Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow_direct: Include rack.session.options #233

Merged
merged 4 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 172
Max: 173

# Offense count: 5
Metrics/CyclomaticComplexity:
Expand Down
3 changes: 2 additions & 1 deletion lib/rack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def follow_redirect!
send(
request_method, last_response['Location'], params,
'HTTP_REFERER' => last_request.url,
'rack.session' => last_request.session
'rack.session' => last_request.session,
'rack.session.options' => last_request.session_options
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/fake_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FakeApp < Sinatra::Base

%i[get put post delete].each do |meth|
send(meth, '/redirected') do
additional_info = meth == :get ? ", session #{session}" : " using #{meth} with #{params}"
additional_info = meth == :get ? ", session #{session} with options #{request.session_options}" : " using #{meth} with #{params}"
"You've been redirected" + additional_info
end
end
Expand Down
9 changes: 8 additions & 1 deletion spec/rack/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def close
follow_redirect!

expect(last_response).not_to be_redirect
expect(last_response.body).to eq("You've been redirected, session {}")
expect(last_response.body).to eq("You've been redirected, session {} with options {}")
expect(last_request.env['HTTP_REFERER']).to eql('http://example.org/redirect')
end

Expand All @@ -380,6 +380,13 @@ def close
expect(last_response.body).to include('session {"foo"=>"bar"}')
end

it 'includes session options when following the redirect' do
get '/redirect', {}, 'rack.session.options' => { 'foo' => 'bar' }
follow_redirect!

expect(last_response.body).to include('session {} with options {"foo"=>"bar"}')
end

it 'raises an error if the last_response is not set' do
expect do
follow_redirect!
Expand Down