aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-30 07:07:37 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-30 07:07:37 -0700
commitbbb32d205f2391be21d40ad64b693a4c0d9aa534 (patch)
tree20c8ab179657b791808972fdee9181a341a124fa
parenta02193854f995e597d008b309e6948ee97ad2122 (diff)
parent38f8872aa5fd8f0a1d0895e9eb41f73261acd040 (diff)
downloadrails-bbb32d205f2391be21d40ad64b693a4c0d9aa534.tar.gz
rails-bbb32d205f2391be21d40ad64b693a4c0d9aa534.tar.bz2
rails-bbb32d205f2391be21d40ad64b693a4c0d9aa534.zip
Merge pull request #12702 from dmathieu/finetune_session_fetch
session#fetch doesn't behave exactly like Hash#fetch.
-rw-r--r--actionpack/CHANGELOG.md4
-rw-r--r--actionpack/test/dispatch/request/session_test.rb6
2 files changed, 8 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index b8ba48f8f9..dea80abfcd 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,6 +1,8 @@
* Add `session#fetch` method
- fetch behaves like [Hash#fetch](http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-fetch).
+ fetch behaves similarly to [Hash#fetch](http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-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:
diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb
index 2fed480396..a244d1364c 100644
--- a/actionpack/test/dispatch/request/session_test.rb
+++ b/actionpack/test/dispatch/request/session_test.rb
@@ -63,11 +63,15 @@ module ActionDispatch
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
session.fetch(:four)