2013-02-25 19:05:37 -05:00
|
|
|
require 'helper'
|
2011-10-16 19:27:26 -04:00
|
|
|
|
|
|
|
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
|
2014-05-30 14:42:00 -04:00
|
|
|
b.run lambda { |_env| [200, {}, ['Not Found']] }
|
2014-01-15 23:00:46 -05:00
|
|
|
end.to_app
|
|
|
|
end
|
2011-10-16 19:27:26 -04:00
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
context 'request phase' do
|
2020-12-02 22:16:51 -05:00
|
|
|
before(:each) { post '/auth/developer' }
|
2011-10-16 19:27:26 -04:00
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'displays a form' do
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(last_response.status).to eq(200)
|
2014-01-15 23:00:46 -05:00
|
|
|
expect(last_response.body).to be_include('<form')
|
2011-10-16 19:27:26 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'has the callback as the action for the form' do
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(last_response.body).to be_include("action='/auth/developer/callback'")
|
2011-10-16 19:27:26 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'has a text field for each of the fields' do
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(last_response.body.scan('<input').size).to eq(2)
|
2011-10-16 19:27:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
context 'callback phase' do
|
|
|
|
let(:auth_hash) { last_request.env['omniauth.auth'] }
|
2011-10-16 19:27:26 -04:00
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
context 'with default options' do
|
2011-10-16 19:27:26 -04:00
|
|
|
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
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(auth_hash.info.name).to eq('Example User')
|
2011-10-16 19:27:26 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'sets the email in the auth hash' do
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(auth_hash.info.email).to eq('user@example.com')
|
2011-10-16 19:27:26 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'sets the uid to the email' do
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(auth_hash.uid).to eq('user@example.com')
|
2011-10-16 19:27:26 -04:00
|
|
|
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'
|
2017-09-28 13:07:45 -04:00
|
|
|
b.use OmniAuth::Strategies::Developer, :fields => %i[first_name last_name], :uid_field => :last_name
|
2014-05-30 14:42:00 -04:00
|
|
|
b.run lambda { |_env| [200, {}, ['Not Found']] }
|
2014-01-15 23:00:46 -05:00
|
|
|
end.to_app
|
|
|
|
end
|
2011-10-16 19:27:26 -04:00
|
|
|
|
|
|
|
before do
|
2017-09-28 13:07:45 -04:00
|
|
|
@options = {:uid_field => :last_name, :fields => %i[first_name last_name]}
|
2011-10-16 19:27:26 -04:00
|
|
|
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
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(auth_hash.info.name).to eq('Example User')
|
2011-10-16 19:27:26 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'sets the uid properly' do
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(auth_hash.uid).to eq('User')
|
2011-10-16 19:27:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|