Skip to content

Commit 38f8872

Browse files
committed
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 rails#12692
1 parent a021938 commit 38f8872

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

actionpack/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
* Add `session#fetch` method
22

3-
fetch behaves like [Hash#fetch](http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-fetch).
3+
fetch behaves similarly to [Hash#fetch](http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-fetch),
4+
with the exception that the returned value is always saved into the session.
5+
46
It returns a value from the hash for the given key.
57
If the key can’t be found, there are several options:
68

actionpack/test/dispatch/request/session_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ def test_clear
6363

6464
def test_fetch
6565
session = Session.create(store, {}, {})
66-
session['one'] = '1'
6766

67+
session['one'] = '1'
6868
assert_equal '1', session.fetch(:one)
69+
6970
assert_equal '2', session.fetch(:two, '2')
71+
assert_equal '2', session.fetch(:two)
72+
7073
assert_equal 'three', session.fetch(:three) {|el| el.to_s }
74+
assert_equal 'three', session.fetch(:three)
7175

7276
assert_raise KeyError do
7377
session.fetch(:four)

0 commit comments

Comments
 (0)