diff options
author | Matthew Gerrior <mgerrior@greanetree.com> | 2014-06-27 17:27:41 -0400 |
---|---|---|
committer | Matthew Gerrior <matthew@challengepost.com> | 2015-08-06 15:29:45 -0400 |
commit | 3004cc817794527fa44c727eea87e20b65c686ce (patch) | |
tree | 1415f6a237f8849edfe44d3d38f2a26eb883469a | |
parent | 3908a6d8675605f570f07d8be2f9224c1c47f0e3 (diff) | |
download | rails-3004cc817794527fa44c727eea87e20b65c686ce.tar.gz rails-3004cc817794527fa44c727eea87e20b65c686ce.tar.bz2 rails-3004cc817794527fa44c727eea87e20b65c686ce.zip |
Adds missing argument handling for ActionController::TestSession to
allow testing controllers that use session#fetch with a default value.
-rw-r--r-- | actionpack/CHANGELOG.md | 9 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 4 | ||||
-rw-r--r-- | actionpack/test/dispatch/session/test_session_test.rb | 10 |
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 |