Skip to content
This repository
Browse code

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 authored
5  actionpack/CHANGELOG
... ...
@@ -1,3 +1,8 @@
  1
+*SVN*
  2
+
  3
+* Added a reader for flash.now, so it's possible to do stuff like flash.now[:alert] ||= 'New if not set' #2422 [Caio Chassot]
  4
+
  5
+
1 6
 *1.10.2* (October 26th, 2005)
2 7
 
3 8
 * Reset template variables after using render_to_string [skaes@web.de]
4  actionpack/lib/action_controller/flash.rb
@@ -40,6 +40,10 @@ def []=(k, v)
40 40
         @flash.discard(k)
41 41
         v
42 42
       end
  43
+      
  44
+      def [](k)
  45
+        @flash[k]
  46
+      end
43 47
     end
44 48
     
45 49
     class FlashHash < Hash
6  actionpack/test/controller/flash_test.rb
@@ -9,6 +9,9 @@ def set_flash
9 9
 
10 10
     def set_flash_now
11 11
       flash.now["that"] = "hello"
  12
+      flash.now["foo"] ||= "bar"
  13
+      flash.now["foo"] ||= "err"
  14
+      @flashy = flash.now["that"]
12 15
       @flash_copy = {}.update flash
13 16
       render :inline => "hello"
14 17
     end
@@ -75,10 +78,13 @@ def test_flash_now
75 78
     @request.action = "set_flash_now"
76 79
     response = process_request
77 80
     assert_equal "hello", response.template.assigns["flash_copy"]["that"]
  81
+    assert_equal "bar"  , response.template.assigns["flash_copy"]["foo"]
  82
+    assert_equal "hello", response.template.assigns["flashy"]
78 83
 
79 84
     @request.action = "attempt_to_use_flash_now"
80 85
     first_response = process_request
81 86
     assert_nil first_response.template.assigns["flash_copy"]["that"]
  87
+    assert_nil first_response.template.assigns["flash_copy"]["foo"]
82 88
     assert_nil first_response.template.assigns["flashy"]
83 89
   end 
84 90
   

0 notes on commit 07c494a

Please sign in to comment.
Something went wrong with that request. Please try again.