Froze rails gems
[depot.git] / vendor / rails / actionpack / test / controller / components_test.rb
1 require 'abstract_unit'
2
3 class CallerController < ActionController::Base
4 def calling_from_controller
5 render_component(:controller => "callee", :action => "being_called")
6 end
7
8 def calling_from_controller_with_params
9 render_component(:controller => "callee", :action => "being_called", :params => { "name" => "David" })
10 end
11
12 def calling_from_controller_with_different_status_code
13 render_component(:controller => "callee", :action => "blowing_up")
14 end
15
16 def calling_from_template
17 render :inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>"
18 end
19
20 def internal_caller
21 render :inline => "Are you there? <%= render_component(:action => 'internal_callee') %>"
22 end
23
24 def internal_callee
25 render :text => "Yes, ma'am"
26 end
27
28 def set_flash
29 render_component(:controller => "callee", :action => "set_flash")
30 end
31
32 def use_flash
33 render_component(:controller => "callee", :action => "use_flash")
34 end
35
36 def calling_redirected
37 render_component(:controller => "callee", :action => "redirected")
38 end
39
40 def calling_redirected_as_string
41 render :inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>"
42 end
43
44 def rescue_action(e) raise end
45 end
46
47 class CalleeController < ActionController::Base
48 def being_called
49 render :text => "#{params[:name] || "Lady"} of the House, speaking"
50 end
51
52 def blowing_up
53 render :text => "It's game over, man, just game over, man!", :status => 500
54 end
55
56 def set_flash
57 flash[:notice] = 'My stoney baby'
58 render :text => 'flash is set'
59 end
60
61 def use_flash
62 render :text => flash[:notice] || 'no flash'
63 end
64
65 def redirected
66 redirect_to :controller => "callee", :action => "being_called"
67 end
68
69 def rescue_action(e) raise end
70 end
71
72 class ComponentsTest < Test::Unit::TestCase
73 def setup
74 @controller = CallerController.new
75 @request = ActionController::TestRequest.new
76 @response = ActionController::TestResponse.new
77 end
78
79 def test_calling_from_controller
80 assert_deprecated do
81 get :calling_from_controller
82 assert_equal "Lady of the House, speaking", @response.body
83 end
84 end
85
86 def test_calling_from_controller_with_params
87 assert_deprecated do
88 get :calling_from_controller_with_params
89 assert_equal "David of the House, speaking", @response.body
90 end
91 end
92
93 def test_calling_from_controller_with_different_status_code
94 assert_deprecated do
95 get :calling_from_controller_with_different_status_code
96 assert_equal 500, @response.response_code
97 end
98 end
99
100 def test_calling_from_template
101 assert_deprecated do
102 get :calling_from_template
103 assert_equal "Ring, ring: Lady of the House, speaking", @response.body
104 end
105 end
106
107 def test_etag_is_set_for_parent_template_when_calling_from_template
108 assert_deprecated do
109 get :calling_from_template
110 expected_etag = etag_for("Ring, ring: Lady of the House, speaking")
111 assert_equal expected_etag, @response.headers['ETag']
112 end
113 end
114
115 def test_internal_calling
116 assert_deprecated do
117 get :internal_caller
118 assert_equal "Are you there? Yes, ma'am", @response.body
119 end
120 end
121
122 def test_flash
123 assert_deprecated do
124 get :set_flash
125 assert_equal 'My stoney baby', flash[:notice]
126 get :use_flash
127 assert_equal 'My stoney baby', @response.body
128 get :use_flash
129 assert_equal 'no flash', @response.body
130 end
131 end
132
133 def test_component_redirect_redirects
134 assert_deprecated do
135 get :calling_redirected
136 assert_redirected_to :controller=>"callee", :action => "being_called"
137 end
138 end
139
140 def test_component_multiple_redirect_redirects
141 test_component_redirect_redirects
142 test_internal_calling
143 end
144
145 def test_component_as_string_redirect_renders_redirected_action
146 assert_deprecated do
147 get :calling_redirected_as_string
148 assert_equal "Lady of the House, speaking", @response.body
149 end
150 end
151
152 protected
153 def etag_for(text)
154 %("#{Digest::MD5.hexdigest(text)}")
155 end
156 end