mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make flash messages cookie compatible with Rails 4
In #18721 we removed the discard key from the session hash used to flash messages and that broke compatibility with Rails 4 applications because they try to map in the discarded flash messages and it returns nil. Fixes #24726.
This commit is contained in:
parent
de8f3cb483
commit
bf876aa0b6
2 changed files with 3 additions and 3 deletions
|
@ -133,7 +133,7 @@ module ActionDispatch
|
|||
def to_session_value #:nodoc:
|
||||
flashes_to_keep = @flashes.except(*@discard)
|
||||
return nil if flashes_to_keep.empty?
|
||||
{'flashes' => flashes_to_keep}
|
||||
{ 'discard' => [], 'flashes' => flashes_to_keep }
|
||||
end
|
||||
|
||||
def initialize(flashes = {}, discard = []) #:nodoc:
|
||||
|
|
|
@ -57,10 +57,10 @@ module ActionDispatch
|
|||
|
||||
def test_to_session_value
|
||||
@hash['foo'] = 'bar'
|
||||
assert_equal({'flashes' => {'foo' => 'bar'}}, @hash.to_session_value)
|
||||
assert_equal({ 'discard' => [], 'flashes' => { 'foo' => 'bar' } }, @hash.to_session_value)
|
||||
|
||||
@hash.now['qux'] = 1
|
||||
assert_equal({'flashes' => {'foo' => 'bar'}}, @hash.to_session_value)
|
||||
assert_equal({ 'flashes' => { 'foo' => 'bar' }, 'discard' => [] }, @hash.to_session_value)
|
||||
|
||||
@hash.discard('foo')
|
||||
assert_equal(nil, @hash.to_session_value)
|
||||
|
|
Loading…
Reference in a new issue