diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-10-26 13:14:10 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-10-26 13:14:10 +0000 |
commit | 07c494ae24b897bfa1d46f741b9ac14d3b480bc2 (patch) | |
tree | 82631d2a8dd051662c3c4fbb523414d48009aee5 /actionpack | |
parent | 0d52abfd0ea42ba8f9bac996378087be42b93917 (diff) | |
download | rails-07c494ae24b897bfa1d46f741b9ac14d3b480bc2.tar.gz rails-07c494ae24b897bfa1d46f741b9ac14d3b480bc2.tar.bz2 rails-07c494ae24b897bfa1d46f741b9ac14d3b480bc2.zip |
Added a reader for flash.now, so it's possible to do stuff like flash.now[:alert] ||= 'New if not set' (closes #2422) [Caio Chassot]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2747 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 5 | ||||
-rw-r--r-- | actionpack/lib/action_controller/flash.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/flash_test.rb | 6 |
3 files changed, 15 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 721ac3ac96..79dc1a5580 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 df2863e0b6..06c8c4b5c6 100644 --- a/actionpack/lib/action_controller/flash.rb +++ b/actionpack/lib/action_controller/flash.rb @@ -40,6 +40,10 @@ module ActionController #:nodoc: @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 54a1444f97..2a14d6d625 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -9,6 +9,9 @@ class FlashTest < Test::Unit::TestCase 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 @@ class FlashTest < Test::Unit::TestCase @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 |