diff options
author | Samuel Cochran <sj26@sj26.com> | 2015-01-30 09:47:03 +1100 |
---|---|---|
committer | Samuel Cochran <sj26@sj26.com> | 2015-01-30 09:47:03 +1100 |
commit | 3f528e371c9ac2cf8e240a29d500a18ab8f5439d (patch) | |
tree | 84516b46c2bc3717e76992eba10f8b7eac102657 /actionpack | |
parent | f7adb34999eb4df7916102b60f5aa3f0ddc8210c (diff) | |
download | rails-3f528e371c9ac2cf8e240a29d500a18ab8f5439d.tar.gz rails-3f528e371c9ac2cf8e240a29d500a18ab8f5439d.tar.bz2 rails-3f528e371c9ac2cf8e240a29d500a18ab8f5439d.zip |
Migrate old flash behaviour
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/flash.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/flash_hash_test.rb | 13 |
2 files changed, 13 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb index b1d402cd30..59639a010e 100644 --- a/actionpack/lib/action_dispatch/middleware/flash.rb +++ b/actionpack/lib/action_dispatch/middleware/flash.rb @@ -83,9 +83,15 @@ module ActionDispatch case value when FlashHash # Rails 3.1, 3.2 flashes = value.instance_variable_get(:@flashes) + if discard = value.instance_variable_get(:@used) + flashes.except!(*discard) + end new(flashes, flashes.keys) when Hash # Rails 4.0 flashes = value['flashes'] + if discard = value['discard'] + flashes.except!(*discard) + end new(flashes, flashes.keys) else new diff --git a/actionpack/test/controller/flash_hash_test.rb b/actionpack/test/controller/flash_hash_test.rb index 93ed5a037e..081288ef21 100644 --- a/actionpack/test/controller/flash_hash_test.rb +++ b/actionpack/test/controller/flash_hash_test.rb @@ -70,22 +70,23 @@ module ActionDispatch end def test_from_session_value - rails_3_2_cookie = 'BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWY4ZTFiODE1MmJhNzYwOWMyOGJiYjE3ZWM5MjYzYmE3BjsAVEkiCmZsYXNoBjsARm86JUFjdGlvbkRpc3BhdGNoOjpGbGFzaDo6Rmxhc2hIYXNoCToKQHVzZWRvOghTZXQGOgpAaGFzaHsAOgxAY2xvc2VkRjoNQGZsYXNoZXN7BkkiDG1lc3NhZ2UGOwBGSSIKSGVsbG8GOwBGOglAbm93MA==' + # {"session_id"=>"f8e1b8152ba7609c28bbb17ec9263ba7", "flash"=>#<ActionDispatch::Flash::FlashHash:0x00000000000000 @used=#<Set: {"farewell"}>, @closed=false, @flashes={"greeting"=>"Hello", "farewell"=>"Goodbye"}, @now=nil>} + rails_3_2_cookie = 'BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWY4ZTFiODE1MmJhNzYwOWMyOGJiYjE3ZWM5MjYzYmE3BjsAVEkiCmZsYXNoBjsARm86JUFjdGlvbkRpc3BhdGNoOjpGbGFzaDo6Rmxhc2hIYXNoCToKQHVzZWRvOghTZXQGOgpAaGFzaHsGSSINZmFyZXdlbGwGOwBUVDoMQGNsb3NlZEY6DUBmbGFzaGVzewdJIg1ncmVldGluZwY7AFRJIgpIZWxsbwY7AFRJIg1mYXJld2VsbAY7AFRJIgxHb29kYnllBjsAVDoJQG5vdzA=' session = Marshal.load(Base64.decode64(rails_3_2_cookie)) hash = Flash::FlashHash.from_session_value(session['flash']) - assert_equal({'message' => 'Hello'}, hash.to_hash) + assert_equal({'greeting' => 'Hello'}, hash.to_hash) assert_equal(nil, hash.to_session_value) end def test_from_session_value_on_json_serializer - decrypted_data = "{ \"session_id\":\"d98bdf6d129618fc2548c354c161cfb5\", \"flash\":{\"discard\":[], \"flashes\":{\"message\":\"hey you\"}} }" + decrypted_data = "{ \"session_id\":\"d98bdf6d129618fc2548c354c161cfb5\", \"flash\":{\"discard\":[\"farewell\"], \"flashes\":{\"greeting\":\"Hello\",\"farewell\":\"Goodbye\"}} }" session = ActionDispatch::Cookies::JsonSerializer.load(decrypted_data) hash = Flash::FlashHash.from_session_value(session['flash']) - assert_equal({'message' => 'hey you'}, hash.to_hash) + assert_equal({'greeting' => 'Hello'}, hash.to_hash) assert_equal(nil, hash.to_session_value) - assert_equal "hey you", hash[:message] - assert_equal "hey you", hash["message"] + assert_equal "Hello", hash[:greeting] + assert_equal "Hello", hash["greeting"] end def test_empty? |