1 require 'abstract_unit'
3 class FlashTest
< Test
::Unit::TestCase
4 class TestController
< ActionController
::Base
6 flash
["that"] = "hello"
7 render
:inline => "hello"
11 flash
.now
["that"] = "hello"
12 flash
.now
["foo"] ||= "bar"
13 flash
.now
["foo"] ||= "err"
14 @flashy = flash
.now
["that"]
15 @flash_copy = {}.update flash
16 render
:inline => "hello"
19 def attempt_to_use_flash_now
20 @flash_copy = {}.update flash
21 @flashy = flash
["that"]
22 render
:inline => "hello"
26 @flash_copy = {}.update flash
27 @flashy = flash
["that"]
28 render
:inline => "hello"
31 def use_flash_and_keep_it
32 @flash_copy = {}.update flash
33 @flashy = flash
["that"]
35 render
:inline => "hello"
38 def use_flash_and_update_it
39 flash
.update("this" => "hello again")
40 @flash_copy = {}.update flash
41 render
:inline => "hello"
44 def use_flash_after_reset_session
45 flash
["that"] = "hello"
46 @flashy_that = flash
["that"]
48 @flashy_that_reset = flash
["that"]
49 flash
["this"] = "good-bye"
50 @flashy_this = flash
["this"]
51 render
:inline => "hello"
55 raise unless ActionView
::MissingTemplate === e
58 # methods for test_sweep_after_halted_filter_chain
59 before_filter
:halt_and_redir, :only => "filter_halting_action"
62 @flash_copy = {}.update(flash
)
65 def filter_halting_action
66 @flash_copy = {}.update(flash
)
71 redirect_to
:action => "std_action"
72 @flash_copy = {}.update(flash
)
77 @request = ActionController
::TestRequest.new
78 @response = ActionController
::TestResponse.new
79 @controller = TestController
.new
86 assert_equal
"hello", @response.template
.assigns
["flash_copy"]["that"]
87 assert_equal
"hello", @response.template
.assigns
["flashy"]
90 assert_nil
@response.template
.assigns
["flash_copy"]["that"], "On second flash"
96 get
:use_flash_and_keep_it
97 assert_equal
"hello", @response.template
.assigns
["flash_copy"]["that"]
98 assert_equal
"hello", @response.template
.assigns
["flashy"]
101 assert_equal
"hello", @response.template
.assigns
["flash_copy"]["that"], "On second flash"
104 assert_nil
@response.template
.assigns
["flash_copy"]["that"], "On third flash"
109 assert_equal
"hello", @response.template
.assigns
["flash_copy"]["that"]
110 assert_equal
"bar" , @response.template
.assigns
["flash_copy"]["foo"]
111 assert_equal
"hello", @response.template
.assigns
["flashy"]
113 get
:attempt_to_use_flash_now
114 assert_nil
@response.template
.assigns
["flash_copy"]["that"]
115 assert_nil
@response.template
.assigns
["flash_copy"]["foo"]
116 assert_nil
@response.template
.assigns
["flashy"]
119 def test_update_flash
121 get
:use_flash_and_update_it
122 assert_equal
"hello", @response.template
.assigns
["flash_copy"]["that"]
123 assert_equal
"hello again", @response.template
.assigns
["flash_copy"]["this"]
125 assert_nil
@response.template
.assigns
["flash_copy"]["that"], "On second flash"
126 assert_equal
"hello again", @response.template
.assigns
["flash_copy"]["this"], "On second flash"
129 def test_flash_after_reset_session
130 get
:use_flash_after_reset_session
131 assert_equal
"hello", @response.template
.assigns
["flashy_that"]
132 assert_equal
"good-bye", @response.template
.assigns
["flashy_this"]
133 assert_nil
@response.template
.assigns
["flashy_that_reset"]
136 def test_sweep_after_halted_filter_chain
138 assert_nil
@response.template
.assigns
["flash_copy"]["foo"]
139 get
:filter_halting_action
140 assert_equal
"bar", @response.template
.assigns
["flash_copy"]["foo"]
141 get
:std_action # follow redirection
142 assert_equal
"bar", @response.template
.assigns
["flash_copy"]["foo"]
144 assert_nil
@response.template
.assigns
["flash_copy"]["foo"]