Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 07c494ae24b897bfa1d46f741b9ac14d3b480bc2 1 parent 0d52abf
David Heinemeier Hansson dhh authored
5 actionpack/CHANGELOG
View
@@ -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]
4 actionpack/lib/action_controller/flash.rb
View
@@ -40,6 +40,10 @@ def []=(k, v)
@flash.discard(k)
v
end
+
+ def [](k)
+ @flash[k]
+ end
end
class FlashHash < Hash
6 actionpack/test/controller/flash_test.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.