Skip to content

Commit

Permalink
Fix mock_*_call methods to preserve the omniauth.params hash
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis committed Jun 4, 2012
1 parent c2ceb5f commit fba3c36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/omniauth/strategy.rb
Expand Up @@ -261,6 +261,8 @@ def mock_call!(env)
def mock_request_call
setup_phase

session['omniauth.params'] = request.params

if request.params['origin']
@env['rack.session']['omniauth.origin'] = request.params['origin']
elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
Expand All @@ -276,7 +278,7 @@ def mock_callback_call
fail!(mocked_auth)
else
@env['omniauth.auth'] = mocked_auth
@env['omniauth.params'] = session.delete('query_params') || {}
@env['omniauth.params'] = session.delete('omniauth.params') || {}
@env['omniauth.origin'] = session.delete('omniauth.origin')
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
call_app!
Expand Down
14 changes: 14 additions & 0 deletions spec/omniauth/strategy_spec.rb
Expand Up @@ -564,6 +564,20 @@ def make_env(path = '/auth/test', props = {})
strategy.env['omniauth.origin'].should == 'http://example.com/origin'
end

it 'should set omniauth.params on the request phase' do
OmniAuth.config.mock_auth[:test] = {}

strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'foo=bar'))
strategy.env['rack.session']['omniauth.params'].should == {'foo' => 'bar'}
end

it 'should turn omniauth.params into an env variable on the callback phase' do
OmniAuth.config.mock_auth[:test] = {}

strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.params' => {'foo' => 'bar'}}))
strategy.env['omniauth.params'].should == {'foo' => 'bar'}
end

after do
OmniAuth.config.test_mode = false
end
Expand Down

0 comments on commit fba3c36

Please sign in to comment.