1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00
omniauth--omniauth/spec/omniauth/strategies/developer_spec.rb

74 lines
2.1 KiB
Ruby
Raw Normal View History

2013-02-25 19:05:37 -05:00
require 'helper'
describe OmniAuth::Strategies::Developer do
2014-01-15 23:00:46 -05:00
let(:app) do
Rack::Builder.new do |b|
b.use Rack::Session::Cookie, :secret => 'abc123'
b.use OmniAuth::Strategies::Developer
b.run lambda { |_env| [200, {}, ['Not Found']] }
2014-01-15 23:00:46 -05:00
end.to_app
end
2014-01-15 23:00:46 -05:00
context 'request phase' do
before(:each) { get '/auth/developer' }
2014-01-15 23:00:46 -05:00
it 'displays a form' do
expect(last_response.status).to eq(200)
2014-01-15 23:00:46 -05:00
expect(last_response.body).to be_include('<form')
end
2014-01-15 23:00:46 -05:00
it 'has the callback as the action for the form' do
expect(last_response.body).to be_include("action='/auth/developer/callback'")
end
2014-01-15 23:00:46 -05:00
it 'has a text field for each of the fields' do
expect(last_response.body.scan('<input').size).to eq(2)
end
end
2014-01-15 23:00:46 -05:00
context 'callback phase' do
let(:auth_hash) { last_request.env['omniauth.auth'] }
2014-01-15 23:00:46 -05:00
context 'with default options' do
before do
post '/auth/developer/callback', :name => 'Example User', :email => 'user@example.com'
end
2014-01-15 23:00:46 -05:00
it 'sets the name in the auth hash' do
expect(auth_hash.info.name).to eq('Example User')
end
2014-01-15 23:00:46 -05:00
it 'sets the email in the auth hash' do
expect(auth_hash.info.email).to eq('user@example.com')
end
2014-01-15 23:00:46 -05:00
it 'sets the uid to the email' do
expect(auth_hash.uid).to eq('user@example.com')
end
end
2014-01-15 23:00:46 -05:00
context 'with custom options' do
let(:app) do
Rack::Builder.new do |b|
b.use Rack::Session::Cookie, :secret => 'abc123'
b.use OmniAuth::Strategies::Developer, :fields => [:first_name, :last_name], :uid_field => :last_name
b.run lambda { |_env| [200, {}, ['Not Found']] }
2014-01-15 23:00:46 -05:00
end.to_app
end
before do
@options = {:uid_field => :last_name, :fields => [:first_name, :last_name]}
post '/auth/developer/callback', :first_name => 'Example', :last_name => 'User'
end
2014-01-15 23:00:46 -05:00
it 'sets info fields properly' do
expect(auth_hash.info.name).to eq('Example User')
end
2014-01-15 23:00:46 -05:00
it 'sets the uid properly' do
expect(auth_hash.uid).to eq('User')
end
end
end
end