accept two optional args in Rack::Session::Abstract::SessionHash#fetch #1024
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I got bitten by a bug in rails that lead me to this class. They inherit from
Rack::Session::Abstract::SessionHash
for some session hash classes relating to forgery protection (https://github.com/rails/rails/blob/e7feaff70f13b56a0507e9f4dfaf3ebc361cb8e6/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L135). Whilst in the normal session hash they have implementedfetch
with two optional arguments (https://github.com/rails/rails/blob/e7feaff70f13b56a0507e9f4dfaf3ebc361cb8e6/actionpack/lib/action_dispatch/request/session.rb#L133-L140). They also have a separate session hash class for testing which implements the two optional args forfetch
.I had some shared code between controllers called
session.fetch
with the default argument, this caused exceptions for controllers that used forgery protection it also didn't exception in the tests for these controllers.Whilst this is a bug in rails it seems like this class in
rack
was the right place to fix it and properly mimic the behaviour of Ruby'sHash
.I would have added another spec but it outputs the warning
rack/lib/rack/session/abstract/id.rb:66: warning: block supersedes default value argument
in the middle of the test suite. Given the current tests for this class it seemed better to just not include it than to hide the warning.