Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / actionpack / test / controller / flash_test.rb
1 require 'abstract_unit'
2
3 class FlashTest < ActionController::TestCase
4 class TestController < ActionController::Base
5 def set_flash
6 flash["that"] = "hello"
7 render :inline => "hello"
8 end
9
10 def set_flash_now
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"
17 end
18
19 def attempt_to_use_flash_now
20 @flash_copy = {}.update flash
21 @flashy = flash["that"]
22 render :inline => "hello"
23 end
24
25 def use_flash
26 @flash_copy = {}.update flash
27 @flashy = flash["that"]
28 render :inline => "hello"
29 end
30
31 def use_flash_and_keep_it
32 @flash_copy = {}.update flash
33 @flashy = flash["that"]
34 flash.keep
35 render :inline => "hello"
36 end
37
38 def use_flash_and_update_it
39 flash.update("this" => "hello again")
40 @flash_copy = {}.update flash
41 render :inline => "hello"
42 end
43
44 def use_flash_after_reset_session
45 flash["that"] = "hello"
46 @flashy_that = flash["that"]
47 reset_session
48 @flashy_that_reset = flash["that"]
49 flash["this"] = "good-bye"
50 @flashy_this = flash["this"]
51 render :inline => "hello"
52 end
53
54 def rescue_action(e)
55 raise unless ActionView::MissingTemplate === e
56 end
57
58 # methods for test_sweep_after_halted_filter_chain
59 before_filter :halt_and_redir, :only => "filter_halting_action"
60
61 def std_action
62 @flash_copy = {}.update(flash)
63 end
64
65 def filter_halting_action
66 @flash_copy = {}.update(flash)
67 end
68
69 def halt_and_redir
70 flash["foo"] = "bar"
71 redirect_to :action => "std_action"
72 @flash_copy = {}.update(flash)
73 end
74 end
75
76 tests TestController
77
78 def test_flash
79 get :set_flash
80
81 get :use_flash
82 assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
83 assert_equal "hello", @response.template.assigns["flashy"]
84
85 get :use_flash
86 assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash"
87 end
88
89 def test_keep_flash
90 get :set_flash
91
92 get :use_flash_and_keep_it
93 assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
94 assert_equal "hello", @response.template.assigns["flashy"]
95
96 get :use_flash
97 assert_equal "hello", @response.template.assigns["flash_copy"]["that"], "On second flash"
98
99 get :use_flash
100 assert_nil @response.template.assigns["flash_copy"]["that"], "On third flash"
101 end
102
103 def test_flash_now
104 get :set_flash_now
105 assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
106 assert_equal "bar" , @response.template.assigns["flash_copy"]["foo"]
107 assert_equal "hello", @response.template.assigns["flashy"]
108
109 get :attempt_to_use_flash_now
110 assert_nil @response.template.assigns["flash_copy"]["that"]
111 assert_nil @response.template.assigns["flash_copy"]["foo"]
112 assert_nil @response.template.assigns["flashy"]
113 end
114
115 def test_update_flash
116 get :set_flash
117 get :use_flash_and_update_it
118 assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
119 assert_equal "hello again", @response.template.assigns["flash_copy"]["this"]
120 get :use_flash
121 assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash"
122 assert_equal "hello again", @response.template.assigns["flash_copy"]["this"], "On second flash"
123 end
124
125 def test_flash_after_reset_session
126 get :use_flash_after_reset_session
127 assert_equal "hello", @response.template.assigns["flashy_that"]
128 assert_equal "good-bye", @response.template.assigns["flashy_this"]
129 assert_nil @response.template.assigns["flashy_that_reset"]
130 end
131
132 def test_sweep_after_halted_filter_chain
133 get :std_action
134 assert_nil @response.template.assigns["flash_copy"]["foo"]
135 get :filter_halting_action
136 assert_equal "bar", @response.template.assigns["flash_copy"]["foo"]
137 get :std_action # follow redirection
138 assert_equal "bar", @response.template.assigns["flash_copy"]["foo"]
139 get :std_action
140 assert_nil @response.template.assigns["flash_copy"]["foo"]
141 end
142 end