2008-05-18 06:22:34 +02:00
|
|
|
require 'abstract_unit'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
class CallerController < ActionController::Base
|
|
|
|
def calling_from_controller
|
|
|
|
render_component(:controller => "callee", :action => "being_called")
|
|
|
|
end
|
|
|
|
|
|
|
|
def calling_from_controller_with_params
|
|
|
|
render_component(:controller => "callee", :action => "being_called", :params => { "name" => "David" })
|
|
|
|
end
|
|
|
|
|
|
|
|
def calling_from_controller_with_different_status_code
|
|
|
|
render_component(:controller => "callee", :action => "blowing_up")
|
|
|
|
end
|
|
|
|
|
|
|
|
def calling_from_template
|
2007-12-21 08:48:59 +01:00
|
|
|
render :inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>"
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def internal_caller
|
2007-12-21 08:48:59 +01:00
|
|
|
render :inline => "Are you there? <%= render_component(:action => 'internal_callee') %>"
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def internal_callee
|
2007-12-21 08:48:59 +01:00
|
|
|
render :text => "Yes, ma'am"
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_flash
|
|
|
|
render_component(:controller => "callee", :action => "set_flash")
|
|
|
|
end
|
|
|
|
|
|
|
|
def use_flash
|
|
|
|
render_component(:controller => "callee", :action => "use_flash")
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def calling_redirected
|
|
|
|
render_component(:controller => "callee", :action => "redirected")
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def calling_redirected_as_string
|
2007-12-21 08:48:59 +01:00
|
|
|
render :inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>"
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def rescue_action(e) raise end
|
|
|
|
end
|
|
|
|
|
|
|
|
class CalleeController < ActionController::Base
|
|
|
|
def being_called
|
2007-12-21 08:48:59 +01:00
|
|
|
render :text => "#{params[:name] || "Lady"} of the House, speaking"
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def blowing_up
|
2007-12-21 08:48:59 +01:00
|
|
|
render :text => "It's game over, man, just game over, man!", :status => 500
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def set_flash
|
|
|
|
flash[:notice] = 'My stoney baby'
|
|
|
|
render :text => 'flash is set'
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def use_flash
|
|
|
|
render :text => flash[:notice] || 'no flash'
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def redirected
|
|
|
|
redirect_to :controller => "callee", :action => "being_called"
|
|
|
|
end
|
|
|
|
|
|
|
|
def rescue_action(e) raise end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ComponentsTest < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@controller = CallerController.new
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_calling_from_controller
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :calling_from_controller
|
|
|
|
assert_equal "Lady of the House, speaking", @response.body
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_calling_from_controller_with_params
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :calling_from_controller_with_params
|
|
|
|
assert_equal "David of the House, speaking", @response.body
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_calling_from_controller_with_different_status_code
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :calling_from_controller_with_different_status_code
|
|
|
|
assert_equal 500, @response.response_code
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_calling_from_template
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :calling_from_template
|
|
|
|
assert_equal "Ring, ring: Lady of the House, speaking", @response.body
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
|
|
|
def test_etag_is_set_for_parent_template_when_calling_from_template
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :calling_from_template
|
|
|
|
expected_etag = etag_for("Ring, ring: Lady of the House, speaking")
|
|
|
|
assert_equal expected_etag, @response.headers['ETag']
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_internal_calling
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :internal_caller
|
|
|
|
assert_equal "Are you there? Yes, ma'am", @response.body
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_flash
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :set_flash
|
|
|
|
assert_equal 'My stoney baby', flash[:notice]
|
|
|
|
get :use_flash
|
|
|
|
assert_equal 'My stoney baby', @response.body
|
|
|
|
get :use_flash
|
|
|
|
assert_equal 'no flash', @response.body
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_component_redirect_redirects
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :calling_redirected
|
|
|
|
assert_redirected_to :controller=>"callee", :action => "being_called"
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_component_multiple_redirect_redirects
|
|
|
|
test_component_redirect_redirects
|
|
|
|
test_internal_calling
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
|
|
|
def test_component_as_string_redirect_renders_redirected_action
|
2008-10-27 07:47:01 +01:00
|
|
|
assert_deprecated do
|
|
|
|
get :calling_redirected_as_string
|
|
|
|
assert_equal "Lady of the House, speaking", @response.body
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
end
|
|
|
|
|
2007-12-21 08:48:59 +01:00
|
|
|
protected
|
|
|
|
def etag_for(text)
|
|
|
|
%("#{Digest::MD5.hexdigest(text)}")
|
2007-02-09 09:04:31 +01:00
|
|
|
end
|
|
|
|
end
|