Skip to content

Commit

Permalink
follow_direct: Include rack.session.options (#233)
Browse files Browse the repository at this point in the history
* Include session options in request

* Use consistent testing pattern

* Increase allowed ClassLength

* Add more description to the body output
  • Loading branch information
markedmondson authored and perlun committed May 17, 2018
1 parent 1e9277a commit 03eb717
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
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
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
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
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

0 comments on commit 03eb717

Please sign in to comment.