aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-08-06 17:16:24 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-08-06 17:16:24 -0300
commit8585a10d5eee661f9047d131c225469d8351dbc0 (patch)
tree8019ed11344bc09056ce72925661b242be004b7d /actionpack
parentf605825c0e5ae1c633103b4f4ff7699051df434a (diff)
parent3004cc817794527fa44c727eea87e20b65c686ce (diff)
downloadrails-8585a10d5eee661f9047d131c225469d8351dbc0.tar.gz
rails-8585a10d5eee661f9047d131c225469d8351dbc0.tar.bz2
rails-8585a10d5eee661f9047d131c225469d8351dbc0.zip
Merge pull request #15948 from MGerrior/fix_test_session_fetch
Fix test session fetch
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_controller/test_case.rb4
-rw-r--r--actionpack/test/dispatch/session/test_session_test.rb10
3 files changed, 23 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 6a68c057ac..0e478abc97 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,12 @@
+* ActionController::TestSession now accepts a default value as well as
+ a block for generating a default value based off the key provided.
+
+ This fixes calls to session#fetch in ApplicationController instances that
+ take more two arguments or a block from raising `ArgumentError: wrong
+ number of arguments (2 for 1)` when performing controller tests.
+
+ *Matthew Gerrior*
+
* Fix `ActionController::Parameters#fetch` overwriting `KeyError` returned by
default block.
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index f922e134f7..9dab72c5f0 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -171,6 +171,10 @@ module ActionController
clear
end
+ def fetch(*args, &block)
+ @data.fetch(*args, &block)
+ end
+
private
def load!
diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb
index d30461a623..59c030176b 100644
--- a/actionpack/test/dispatch/session/test_session_test.rb
+++ b/actionpack/test/dispatch/session/test_session_test.rb
@@ -40,4 +40,14 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase
assert_equal %w(one two), session.keys
assert_equal %w(1 2), session.values
end
+
+ def test_fetch_returns_default
+ session = ActionController::TestSession.new(one: '1')
+ assert_equal('2', session.fetch(:two, '2'))
+ end
+
+ def test_fetch_returns_block_value
+ session = ActionController::TestSession.new(one: '1')
+ assert_equal(2, session.fetch('2') { |key| key.to_i })
+ end
end