Froze rails gems
[depot.git] / vendor / rails / actionpack / test / controller / flash_test.rb
1 require 'abstract_unit'
2
3 class FlashTest < Test::Unit::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 def setup
77 @request = ActionController::TestRequest.new
78 @response = ActionController::TestResponse.new
79 @controller = TestController.new
80 end
81
82 def test_flash
83 get :set_flash
84
85 get :use_flash
86 assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
87 assert_equal "hello", @response.template.assigns["flashy"]
88
89 get :use_flash
90 assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash"
91 end
92
93 def test_keep_flash
94 get :set_flash
95
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"]
99
100 get :use_flash
101 assert_equal "hello", @response.template.assigns["flash_copy"]["that"], "On second flash"
102
103 get :use_flash
104 assert_nil @response.template.assigns["flash_copy"]["that"], "On third flash"
105 end
106
107 def test_flash_now
108 get :set_flash_now
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"]
112
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"]
117 end
118
119 def test_update_flash
120 get :set_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"]
124 get :use_flash
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"
127 end
128
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"]
134 end
135
136 def test_sweep_after_halted_filter_chain
137 get :std_action
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"]
143 get :std_action
144 assert_nil @response.template.assigns["flash_copy"]["foo"]
145 end
146 end