Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

session#fetch doesn't behave exactly like Hash#fetch.

Mention it in the changelog and add a test checking for regressions.

Hash#fetch isn't adding the defaultly returned value.
However, in the session, saving it is the behavior we should expect.

See discussion in #12692
  • Loading branch information...
commit 38f8872aa5fd8f0a1d0895e9eb41f73261acd040 1 parent a021938
@dmathieu dmathieu authored
4 actionpack/
@@ -1,6 +1,8 @@
* Add `session#fetch` method
- fetch behaves like [Hash#fetch](
+ fetch behaves similarly to [Hash#fetch](,
+ with the exception that the returned value is always saved into the session.
It returns a value from the hash for the given key.
If the key can’t be found, there are several options:
6 actionpack/test/dispatch/request/session_test.rb
@@ -63,11 +63,15 @@ def test_clear
def test_fetch
session = Session.create(store, {}, {})
- session['one'] = '1'
+ session['one'] = '1'
assert_equal '1', session.fetch(:one)
assert_equal '2', session.fetch(:two, '2')
+ assert_equal '2', session.fetch(:two)
assert_equal 'three', session.fetch(:three) {|el| el.to_s }
+ assert_equal 'three', session.fetch(:three)
assert_raise KeyError do
Please sign in to comment.
Something went wrong with that request. Please try again.