1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #21384 from jeremyf/updating-ActionController-TestSession-to-behave-as-a-hash-with-indifferent

Updating TestSession to access with indifference
This commit is contained in:
Yves Senn 2015-08-27 14:16:30 +02:00
commit 6236cc46b9
3 changed files with 17 additions and 2 deletions

View file

@ -1,3 +1,8 @@
* Updating ActionController::TestSession to behave as a hash with indifferent
access:
*Jeremy Friesen*
* Using strings or symbols for middleware class names is deprecated. Convert
things like this:

View file

@ -174,8 +174,8 @@ module ActionController
clear
end
def fetch(*args, &block)
@data.fetch(*args, &block)
def fetch(key, *args, &block)
@data.fetch(key.to_s, *args, &block)
end
private

View file

@ -46,6 +46,16 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase
assert_equal('2', session.fetch(:two, '2'))
end
def test_fetch_on_symbol_returns_value
session = ActionController::TestSession.new(one: '1')
assert_equal('1', session.fetch(:one))
end
def test_fetch_on_string_returns_value
session = ActionController::TestSession.new(one: '1')
assert_equal('1', session.fetch('one'))
end
def test_fetch_returns_block_value
session = ActionController::TestSession.new(one: '1')
assert_equal(2, session.fetch('2') { |key| key.to_i })