1 require 'abstract_unit'
3 class CallerController
< ActionController
::Base
4 def calling_from_controller
5 render_component(:controller => "callee", :action => "being_called")
8 def calling_from_controller_with_params
9 render_component(:controller => "callee", :action => "being_called", :params => { "name" => "David" })
12 def calling_from_controller_with_different_status_code
13 render_component(:controller => "callee", :action => "blowing_up")
16 def calling_from_template
17 render
:inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>"
21 render
:inline => "Are you there? <%= render_component(:action => 'internal_callee') %>"
25 render
:text => "Yes, ma'am"
29 render_component(:controller => "callee", :action => "set_flash")
33 render_component(:controller => "callee", :action => "use_flash")
36 def calling_redirected
37 render_component(:controller => "callee", :action => "redirected")
40 def calling_redirected_as_string
41 render
:inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>"
44 def rescue_action(e
) raise end
47 class CalleeController
< ActionController
::Base
49 render
:text => "#{params[:name] || "Lady
"} of the House, speaking"
53 render
:text => "It's game over, man, just game over, man!", :status => 500
57 flash
[:notice] = 'My stoney baby'
58 render
:text => 'flash is set'
62 render
:text => flash
[:notice] || 'no flash'
66 redirect_to
:controller => "callee", :action => "being_called"
69 def rescue_action(e
) raise end
72 class ComponentsTest
< Test
::Unit::TestCase
74 @controller = CallerController
.new
75 @request = ActionController
::TestRequest.new
76 @response = ActionController
::TestResponse.new
79 def test_calling_from_controller
81 get
:calling_from_controller
82 assert_equal
"Lady of the House, speaking", @response.body
86 def test_calling_from_controller_with_params
88 get
:calling_from_controller_with_params
89 assert_equal
"David of the House, speaking", @response.body
93 def test_calling_from_controller_with_different_status_code
95 get
:calling_from_controller_with_different_status_code
96 assert_equal
500, @response.response_code
100 def test_calling_from_template
102 get
:calling_from_template
103 assert_equal
"Ring, ring: Lady of the House, speaking", @response.body
107 def test_etag_is_set_for_parent_template_when_calling_from_template
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']
115 def test_internal_calling
118 assert_equal
"Are you there? Yes, ma'am", @response.body
125 assert_equal
'My stoney baby', flash
[:notice]
127 assert_equal
'My stoney baby', @response.body
129 assert_equal
'no flash', @response.body
133 def test_component_redirect_redirects
135 get
:calling_redirected
136 assert_redirected_to
:controller=>"callee", :action => "being_called"
140 def test_component_multiple_redirect_redirects
141 test_component_redirect_redirects
142 test_internal_calling
145 def test_component_as_string_redirect_renders_redirected_action
147 get
:calling_redirected_as_string
148 assert_equal
"Lady of the House, speaking", @response.body
154 %("#{Digest::MD5.hexdigest(text)}")