Skip to content

Commit 844aa40

Browse files
author
AlexanderPavlenko
committed
stub session in test mode
1 parent cf7fc00 commit 844aa40

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/omniauth/strategies/oauth2.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def authorize_params
5151
options.authorize_params[:state] = 3.times.map{ rand.to_s[2..-1] }.reduce(&:concat)
5252
end
5353
params = options.authorize_params.merge(options.authorize_options.inject({}){|h,k| h[k.to_sym] = options[k] if options[k]; h})
54+
if OmniAuth.config.test_mode
55+
@env ||= {}
56+
@env['rack.session'] ||= {}
57+
end
5458
session['omniauth.state'] = params[:state]
5559
params
5660
end

spec/omniauth/strategies/oauth2_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
def app; lambda{|env| [200, {}, ["Hello."]]} end
55
let(:fresh_strategy){ Class.new(OmniAuth::Strategies::OAuth2) }
66

7+
before do
8+
OmniAuth.config.test_mode = true
9+
end
10+
11+
after do
12+
OmniAuth.config.test_mode = false
13+
end
14+
715
describe '#client' do
816
subject{ fresh_strategy }
917

0 commit comments

Comments
 (0)