diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 721ac3ac9633550bd674dbf854fa060cdd8b5750..79dc1a5580168a5b2a076de508bfefb61c28cce5 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,3 +1,8 @@ +*SVN* + +* Added a reader for flash.now, so it's possible to do stuff like flash.now[:alert] ||= 'New if not set' #2422 [Caio Chassot] + + *1.10.2* (October 26th, 2005) * Reset template variables after using render_to_string [skaes@web.de] diff --git a/actionpack/lib/action_controller/flash.rb b/actionpack/lib/action_controller/flash.rb index df2863e0b61c7cc32a41c52ec304dc54625185ce..06c8c4b5c6bdfc2bf7c38ff5fc7f2c2a23bd5d3b 100644 --- a/actionpack/lib/action_controller/flash.rb +++ b/actionpack/lib/action_controller/flash.rb @@ -40,6 +40,10 @@ def []=(k, v) @flash.discard(k) v end + + def [](k) + @flash[k] + end end class FlashHash < Hash diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index 54a1444f97f39d85eb2c912c435811d270b541b8..2a14d6d625215f4fba2c264bc99be138f3a32bb4 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -9,6 +9,9 @@ def set_flash def set_flash_now flash.now["that"] = "hello" + flash.now["foo"] ||= "bar" + flash.now["foo"] ||= "err" + @flashy = flash.now["that"] @flash_copy = {}.update flash render :inline => "hello" end @@ -75,10 +78,13 @@ def test_flash_now @request.action = "set_flash_now" response = process_request assert_equal "hello", response.template.assigns["flash_copy"]["that"] + assert_equal "bar" , response.template.assigns["flash_copy"]["foo"] + assert_equal "hello", response.template.assigns["flashy"] @request.action = "attempt_to_use_flash_now" first_response = process_request assert_nil first_response.template.assigns["flash_copy"]["that"] + assert_nil first_response.template.assigns["flash_copy"]["foo"] assert_nil first_response.template.assigns["flashy"] end