2008-01-05 08:32:06 -05:00
|
|
|
require 'abstract_unit'
|
2009-05-22 12:40:26 -04:00
|
|
|
require 'action_controller/vendor/html-scanner'
|
2009-09-06 22:19:29 -04:00
|
|
|
require 'controller/fake_controllers'
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
class ActionPackAssertionsController < ActionController::Base
|
|
|
|
|
2006-11-28 18:41:04 -05:00
|
|
|
def nothing() head :ok end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2007-09-02 20:18:30 -04:00
|
|
|
def hello_world() render :template => "test/hello_world"; end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2007-09-02 20:18:30 -04:00
|
|
|
def hello_xml_world() render :template => "test/hello_xml_world"; end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2009-06-16 19:46:56 -04:00
|
|
|
def hello_xml_world_pdf
|
|
|
|
self.content_type = "application/pdf"
|
|
|
|
render :template => "test/hello_xml_world"
|
|
|
|
end
|
|
|
|
|
|
|
|
def hello_xml_world_pdf_header
|
|
|
|
response.headers["Content-Type"] = "application/pdf; charset=utf-8"
|
|
|
|
render :template => "test/hello_xml_world"
|
|
|
|
end
|
|
|
|
|
2009-05-17 13:48:15 -04:00
|
|
|
def partial() render :partial => 'test/partial'; end
|
|
|
|
|
2005-05-22 03:43:05 -04:00
|
|
|
def redirect_internal() redirect_to "/nothing"; end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-02-12 16:54:34 -05:00
|
|
|
def redirect_to_action() redirect_to :action => "flash_me", :id => 1, :params => { "panda" => "fun" }; end
|
2005-02-12 14:35:30 -05:00
|
|
|
|
|
|
|
def redirect_to_controller() redirect_to :controller => "elsewhere", :action => "flash_me"; end
|
|
|
|
|
2007-10-07 15:12:02 -04:00
|
|
|
def redirect_to_controller_with_symbol() redirect_to :controller => :elsewhere, :action => :flash_me; end
|
|
|
|
|
2005-05-19 15:19:58 -04:00
|
|
|
def redirect_to_path() redirect_to '/some/path' end
|
2005-08-06 04:37:25 -04:00
|
|
|
|
2010-09-29 11:55:43 -04:00
|
|
|
def redirect_invalid_external_route() redirect_to 'ht_tp://www.rubyonrails.org' end
|
|
|
|
|
2005-08-06 04:37:25 -04:00
|
|
|
def redirect_to_named_route() redirect_to route_one_url end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2007-03-12 23:58:22 -04:00
|
|
|
def redirect_external() redirect_to "http://www.rubyonrails.org"; end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2006-11-28 18:41:04 -05:00
|
|
|
def response404() head '404 AWOL' end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-11-28 18:41:04 -05:00
|
|
|
def response500() head '500 Sorry' end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-11-28 18:41:04 -05:00
|
|
|
def response599() head '599 Whoah!' end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
def flash_me
|
|
|
|
flash['hello'] = 'my name is inigo montoya...'
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "Inconceivable!"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def flash_me_naked
|
|
|
|
flash.clear
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "wow!"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def assign_this
|
|
|
|
@howdy = "ho"
|
2005-07-24 12:45:39 -04:00
|
|
|
render :inline => "Mr. Henke"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_based_on_parameters
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "Mr. #{params[:name]}"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2005-06-26 10:36:13 -04:00
|
|
|
def render_url
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "<div>#{url_for(:action => 'flash_me', :only_path => true)}</div>"
|
2005-06-26 10:36:13 -04:00
|
|
|
end
|
|
|
|
|
2006-06-01 23:39:56 -04:00
|
|
|
def render_text_with_custom_content_type
|
|
|
|
render :text => "Hello!", :content_type => Mime::RSS
|
|
|
|
end
|
|
|
|
|
2011-12-02 13:13:36 -05:00
|
|
|
def render_with_layout
|
2011-12-17 01:30:28 -05:00
|
|
|
@variable_for_layout = nil
|
2011-12-02 13:13:36 -05:00
|
|
|
render "test/hello_world", :layout => "layouts/standard"
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def session_stuffing
|
|
|
|
session['xmas'] = 'turkey'
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "ho ho ho"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def raise_exception_on_get
|
2006-09-29 03:34:02 -04:00
|
|
|
raise "get" if request.get?
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "request method: #{request.env['REQUEST_METHOD']}"
|
2004-12-07 06:10:46 -05:00
|
|
|
end
|
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def raise_exception_on_post
|
2006-09-29 03:34:02 -04:00
|
|
|
raise "post" if request.post?
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "request method: #{request.env['REQUEST_METHOD']}"
|
2006-09-29 03:34:02 -04:00
|
|
|
end
|
2005-06-27 01:36:03 -04:00
|
|
|
end
|
|
|
|
|
2008-01-04 21:19:48 -05:00
|
|
|
# Used to test that assert_response includes the exception message
|
|
|
|
# in the failure message when an action raises and assert_response
|
|
|
|
# is expecting something other than an error.
|
|
|
|
class AssertResponseWithUnexpectedErrorController < ActionController::Base
|
|
|
|
def index
|
|
|
|
raise 'FAIL'
|
|
|
|
end
|
2008-05-16 11:27:09 -04:00
|
|
|
|
|
|
|
def show
|
|
|
|
render :text => "Boom", :status => 500
|
|
|
|
end
|
2008-01-04 21:19:48 -05:00
|
|
|
end
|
|
|
|
|
2005-06-27 01:36:03 -04:00
|
|
|
module Admin
|
|
|
|
class InnerModuleController < ActionController::Base
|
2006-08-13 14:31:58 -04:00
|
|
|
def index
|
|
|
|
render :nothing => true
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_to_index
|
|
|
|
redirect_to admin_inner_module_path
|
|
|
|
end
|
|
|
|
|
2005-06-27 01:36:03 -04:00
|
|
|
def redirect_to_absolute_controller
|
|
|
|
redirect_to :controller => '/content'
|
|
|
|
end
|
2006-08-13 14:31:58 -04:00
|
|
|
|
2005-06-27 01:36:03 -04:00
|
|
|
def redirect_to_fellow_controller
|
|
|
|
redirect_to :controller => 'user'
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2006-12-25 04:34:01 -05:00
|
|
|
def redirect_to_top_level_named_route
|
|
|
|
redirect_to top_level_url(:id => "foo")
|
|
|
|
end
|
2005-06-27 01:36:03 -04:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2008-11-07 15:42:34 -05:00
|
|
|
class ActionPackAssertionsControllerTest < ActionController::TestCase
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-06-26 10:36:13 -04:00
|
|
|
def test_assert_tag_and_url_for
|
|
|
|
get :render_url
|
|
|
|
assert_tag :content => "/action_pack_assertions/flash_me"
|
|
|
|
end
|
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_get_request
|
|
|
|
assert_raise(RuntimeError) { get :raise_exception_on_get }
|
|
|
|
get :raise_exception_on_post
|
2004-12-07 06:10:46 -05:00
|
|
|
assert_equal @response.body, 'request method: GET'
|
|
|
|
end
|
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_post_request
|
|
|
|
assert_raise(RuntimeError) { post :raise_exception_on_post }
|
|
|
|
post :raise_exception_on_get
|
|
|
|
assert_equal @response.body, 'request method: POST'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_post_request_switch
|
|
|
|
post :raise_exception_on_get
|
|
|
|
assert_equal @response.body, 'request method: POST'
|
|
|
|
get :raise_exception_on_post
|
|
|
|
assert_equal @response.body, 'request method: GET'
|
|
|
|
post :raise_exception_on_get
|
2004-12-07 06:10:46 -05:00
|
|
|
assert_equal @response.body, 'request method: POST'
|
2010-09-05 22:24:10 -04:00
|
|
|
get :raise_exception_on_post
|
|
|
|
assert_equal @response.body, 'request method: GET'
|
2004-12-07 06:10:46 -05:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2010-11-15 16:37:05 -05:00
|
|
|
def test_string_constraint
|
|
|
|
with_routing do |set|
|
2010-11-17 16:36:51 -05:00
|
|
|
set.draw do
|
2010-11-15 16:37:05 -05:00
|
|
|
match "photos", :to => 'action_pack_assertions#nothing', :constraints => {:subdomain => "admin"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-04-22 11:08:25 -04:00
|
|
|
def test_assert_redirect_to_named_route_failure
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2009-12-08 17:52:26 -05:00
|
|
|
match 'route_one', :to => 'action_pack_assertions#nothing', :as => :route_one
|
|
|
|
match 'route_two', :to => 'action_pack_assertions#nothing', :id => 'two', :as => :route_two
|
|
|
|
match ':controller/:action'
|
2006-04-22 11:08:25 -04:00
|
|
|
end
|
|
|
|
process :redirect_to_named_route
|
2008-11-07 15:42:34 -05:00
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
2006-04-22 11:08:25 -04:00
|
|
|
assert_redirected_to 'http://test.host/route_two'
|
|
|
|
end
|
2008-11-07 15:42:34 -05:00
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
2006-04-22 11:08:25 -04:00
|
|
|
assert_redirected_to :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
|
|
|
|
end
|
2008-11-07 15:42:34 -05:00
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
2006-04-22 11:08:25 -04:00
|
|
|
assert_redirected_to route_two_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-08-13 14:31:58 -04:00
|
|
|
def test_assert_redirect_to_nested_named_route
|
2010-02-24 19:01:03 -05:00
|
|
|
@controller = Admin::InnerModuleController.new
|
|
|
|
|
2006-08-13 14:31:58 -04:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2009-12-08 17:52:26 -05:00
|
|
|
match 'admin/inner_module', :to => 'admin/inner_module#index', :as => :admin_inner_module
|
2010-08-05 09:44:23 -04:00
|
|
|
match ':controller/:action'
|
2006-08-13 14:31:58 -04:00
|
|
|
end
|
|
|
|
process :redirect_to_index
|
|
|
|
# redirection is <{"action"=>"index", "controller"=>"admin/admin/inner_module"}>
|
|
|
|
assert_redirected_to admin_inner_module_path
|
|
|
|
end
|
|
|
|
end
|
2008-06-02 18:57:35 -04:00
|
|
|
|
2006-12-25 04:34:01 -05:00
|
|
|
def test_assert_redirected_to_top_level_named_route_from_nested_controller
|
2010-02-24 19:01:03 -05:00
|
|
|
@controller = Admin::InnerModuleController.new
|
|
|
|
|
2006-12-25 04:34:01 -05:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2009-12-08 17:52:26 -05:00
|
|
|
match '/action_pack_assertions/:id', :to => 'action_pack_assertions#index', :as => :top_level
|
2010-08-05 09:44:23 -04:00
|
|
|
match ':controller/:action'
|
2006-12-25 04:34:01 -05:00
|
|
|
end
|
|
|
|
process :redirect_to_top_level_named_route
|
2008-06-02 18:57:35 -04:00
|
|
|
# assert_redirected_to "http://test.host/action_pack_assertions/foo" would pass because of exact match early return
|
2006-12-25 04:34:01 -05:00
|
|
|
assert_redirected_to "/action_pack_assertions/foo"
|
|
|
|
end
|
|
|
|
end
|
2006-08-13 14:31:58 -04:00
|
|
|
|
2008-06-02 18:57:35 -04:00
|
|
|
def test_assert_redirected_to_top_level_named_route_with_same_controller_name_in_both_namespaces
|
2010-02-24 19:01:03 -05:00
|
|
|
@controller = Admin::InnerModuleController.new
|
|
|
|
|
2008-06-02 18:57:35 -04:00
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2008-06-02 18:57:35 -04:00
|
|
|
# this controller exists in the admin namespace as well which is the only difference from previous test
|
2009-12-08 17:52:26 -05:00
|
|
|
match '/user/:id', :to => 'user#index', :as => :top_level
|
2010-08-05 09:44:23 -04:00
|
|
|
match ':controller/:action'
|
2008-06-02 18:57:35 -04:00
|
|
|
end
|
|
|
|
process :redirect_to_top_level_named_route
|
|
|
|
# assert_redirected_to top_level_url('foo') would pass because of exact match early return
|
|
|
|
assert_redirected_to top_level_path('foo')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_template_objects_exist
|
2004-11-23 20:04:44 -05:00
|
|
|
process :assign_this
|
2010-09-28 16:35:17 -04:00
|
|
|
assert !@controller.instance_variable_defined?(:"@hi")
|
2010-03-17 19:28:05 -04:00
|
|
|
assert @controller.instance_variable_get(:"@howdy")
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_template_objects_missing
|
2004-11-23 20:04:44 -05:00
|
|
|
process :nothing
|
2010-09-28 16:35:17 -04:00
|
|
|
assert !@controller.instance_variable_defined?(:@howdy)
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_empty_flash
|
2004-11-23 20:04:44 -05:00
|
|
|
process :flash_me_naked
|
2010-09-05 21:59:41 -04:00
|
|
|
assert flash.empty?
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_flash_exist
|
2004-11-23 20:04:44 -05:00
|
|
|
process :flash_me
|
2010-09-05 21:59:41 -04:00
|
|
|
assert flash.any?
|
|
|
|
assert_present flash['hello']
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_flash_does_not_exist
|
2004-11-23 20:04:44 -05:00
|
|
|
process :nothing
|
2010-09-05 21:59:41 -04:00
|
|
|
assert flash.empty?
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_session_exist
|
|
|
|
process :session_stuffing
|
|
|
|
assert_equal session['xmas'], 'turkey'
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_does_not_exist
|
|
|
|
process :nothing
|
|
|
|
assert session.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_template_action
|
2004-11-23 20:04:44 -05:00
|
|
|
process :nothing
|
2010-03-17 17:23:00 -04:00
|
|
|
assert_template nil
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2007-09-02 20:18:30 -04:00
|
|
|
process :hello_world
|
2010-03-17 17:23:00 -04:00
|
|
|
assert_template 'hello_world'
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_redirection_location
|
|
|
|
process :redirect_internal
|
2005-05-22 03:43:05 -04:00
|
|
|
assert_equal 'http://test.host/nothing', @response.redirect_url
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
process :redirect_external
|
|
|
|
assert_equal 'http://www.rubyonrails.org', @response.redirect_url
|
2006-11-28 18:41:04 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2006-11-28 18:41:04 -05:00
|
|
|
def test_no_redirect_url
|
2004-11-23 20:04:44 -05:00
|
|
|
process :nothing
|
|
|
|
assert_nil @response.redirect_url
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_server_error_response_code
|
|
|
|
process :response500
|
|
|
|
assert @response.server_error?
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
process :response599
|
|
|
|
assert @response.server_error?
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
process :response404
|
|
|
|
assert !@response.server_error?
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_missing_response_code
|
|
|
|
process :response404
|
|
|
|
assert @response.missing?
|
|
|
|
end
|
|
|
|
|
2008-11-22 14:10:12 -05:00
|
|
|
def test_client_error_response_code
|
|
|
|
process :response404
|
|
|
|
assert @response.client_error?
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_redirect_url_match
|
|
|
|
process :redirect_external
|
|
|
|
assert @response.redirect?
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/rubyonrails/, @response.redirect_url)
|
2010-09-05 21:59:41 -04:00
|
|
|
assert !/perloffrails/.match(@response.redirect_url)
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_redirection
|
|
|
|
process :redirect_internal
|
|
|
|
assert @response.redirect?
|
|
|
|
|
|
|
|
process :redirect_external
|
|
|
|
assert @response.redirect?
|
|
|
|
|
|
|
|
process :nothing
|
|
|
|
assert !@response.redirect?
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_successful_response_code
|
|
|
|
process :nothing
|
|
|
|
assert @response.success?
|
2006-09-29 03:34:02 -04:00
|
|
|
end
|
|
|
|
|
2010-09-05 22:24:10 -04:00
|
|
|
def test_response_object
|
2004-11-23 20:04:44 -05:00
|
|
|
process :nothing
|
|
|
|
assert_kind_of ActionController::TestResponse, @response
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_render_based_on_parameters
|
2012-01-05 17:52:49 -05:00
|
|
|
process :render_based_on_parameters, "name" => "David"
|
2004-11-23 20:04:44 -05:00
|
|
|
assert_equal "Mr. David", @response.body
|
|
|
|
end
|
|
|
|
|
2006-04-24 23:54:46 -04:00
|
|
|
def test_assert_redirection_fails_with_incorrect_controller
|
|
|
|
process :redirect_to_controller
|
2008-11-07 15:42:34 -05:00
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
2006-04-24 23:54:46 -04:00
|
|
|
assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_redirection_with_extra_controller_option
|
|
|
|
get :redirect_to_action
|
|
|
|
assert_redirected_to :controller => 'action_pack_assertions', :action => "flash_me", :id => 1, :params => { :panda => 'fun' }
|
|
|
|
end
|
|
|
|
|
2008-06-23 12:46:15 -04:00
|
|
|
def test_redirected_to_url_leading_slash
|
2005-05-19 15:19:58 -04:00
|
|
|
process :redirect_to_path
|
|
|
|
assert_redirected_to '/some/path'
|
|
|
|
end
|
2008-06-23 12:46:15 -04:00
|
|
|
|
2010-03-02 17:07:42 -05:00
|
|
|
def test_redirected_to_url_no_leading_slash_fails
|
2005-05-19 15:19:58 -04:00
|
|
|
process :redirect_to_path
|
2010-03-02 17:07:42 -05:00
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_redirected_to 'some/path'
|
|
|
|
end
|
2005-05-19 15:19:58 -04:00
|
|
|
end
|
2008-06-23 12:46:15 -04:00
|
|
|
|
2010-09-29 11:55:43 -04:00
|
|
|
def test_redirect_invalid_external_route
|
|
|
|
process :redirect_invalid_external_route
|
|
|
|
assert_redirected_to "http://test.hostht_tp://www.rubyonrails.org"
|
|
|
|
end
|
|
|
|
|
2005-05-19 15:19:58 -04:00
|
|
|
def test_redirected_to_url_full_url
|
|
|
|
process :redirect_to_path
|
|
|
|
assert_redirected_to 'http://test.host/some/path'
|
|
|
|
end
|
2005-06-27 01:36:03 -04:00
|
|
|
|
2007-10-07 15:12:02 -04:00
|
|
|
def test_assert_redirection_with_symbol
|
|
|
|
process :redirect_to_controller_with_symbol
|
|
|
|
assert_nothing_raised {
|
|
|
|
assert_redirected_to :controller => "elsewhere", :action => "flash_me"
|
|
|
|
}
|
|
|
|
process :redirect_to_controller_with_symbol
|
|
|
|
assert_nothing_raised {
|
|
|
|
assert_redirected_to :controller => :elsewhere, :action => :flash_me
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2005-06-27 01:36:03 -04:00
|
|
|
def test_redirected_to_with_nested_controller
|
|
|
|
@controller = Admin::InnerModuleController.new
|
|
|
|
get :redirect_to_absolute_controller
|
2008-06-23 12:46:15 -04:00
|
|
|
assert_redirected_to :controller => '/content'
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2005-06-27 01:36:03 -04:00
|
|
|
get :redirect_to_fellow_controller
|
|
|
|
assert_redirected_to :controller => 'admin/user'
|
2006-09-29 03:34:02 -04:00
|
|
|
end
|
|
|
|
|
2008-01-04 21:19:48 -05:00
|
|
|
def test_assert_response_uses_exception_message
|
|
|
|
@controller = AssertResponseWithUnexpectedErrorController.new
|
|
|
|
get :index
|
|
|
|
assert_response :success
|
|
|
|
flunk 'Expected non-success response'
|
2009-05-03 00:02:22 -04:00
|
|
|
rescue RuntimeError => e
|
2008-01-04 21:19:48 -05:00
|
|
|
assert e.message.include?('FAIL')
|
|
|
|
end
|
2008-05-16 11:27:09 -04:00
|
|
|
|
|
|
|
def test_assert_response_failure_response_with_no_exception
|
|
|
|
@controller = AssertResponseWithUnexpectedErrorController.new
|
|
|
|
get :show
|
|
|
|
assert_response :success
|
|
|
|
flunk 'Expected non-success response'
|
2008-11-07 15:42:34 -05:00
|
|
|
rescue ActiveSupport::TestCase::Assertion
|
|
|
|
# success
|
2008-05-16 11:27:09 -04:00
|
|
|
rescue
|
|
|
|
flunk "assert_response failed to handle failure response with missing, but optional, exception."
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2010-04-29 10:29:35 -04:00
|
|
|
class AssertTemplateTest < ActionController::TestCase
|
|
|
|
tests ActionPackAssertionsController
|
|
|
|
|
|
|
|
def test_with_partial
|
|
|
|
get :partial
|
|
|
|
assert_template :partial => '_partial'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_with_nil_passes_when_no_template_rendered
|
|
|
|
get :nothing
|
|
|
|
assert_template nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_with_nil_fails_when_template_rendered
|
|
|
|
get :hello_world
|
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
|
|
|
assert_template nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_passes_with_correct_string
|
|
|
|
get :hello_world
|
|
|
|
assert_template 'hello_world'
|
|
|
|
assert_template 'test/hello_world'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_passes_with_correct_symbol
|
|
|
|
get :hello_world
|
|
|
|
assert_template :hello_world
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fails_with_incorrect_string
|
|
|
|
get :hello_world
|
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
|
|
|
assert_template 'hello_planet'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fails_with_incorrect_symbol
|
|
|
|
get :hello_world
|
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
|
|
|
assert_template :hello_planet
|
|
|
|
end
|
|
|
|
end
|
2010-10-18 04:57:51 -04:00
|
|
|
|
2011-12-02 13:13:36 -05:00
|
|
|
def test_fails_with_wrong_layout
|
|
|
|
get :render_with_layout
|
|
|
|
assert_raise(ActiveSupport::TestCase::Assertion) do
|
|
|
|
assert_template :layout => "application"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_passes_with_correct_layout
|
|
|
|
get :render_with_layout
|
|
|
|
assert_template :layout => "layouts/standard"
|
|
|
|
end
|
|
|
|
|
2010-10-18 04:57:51 -04:00
|
|
|
def test_assert_template_reset_between_requests
|
|
|
|
get :hello_world
|
|
|
|
assert_template 'test/hello_world'
|
|
|
|
|
|
|
|
get :nothing
|
|
|
|
assert_template nil
|
|
|
|
end
|
2010-04-29 10:29:35 -04:00
|
|
|
end
|
|
|
|
|
2008-11-07 15:42:34 -05:00
|
|
|
class ActionPackHeaderTest < ActionController::TestCase
|
|
|
|
tests ActionPackAssertionsController
|
2006-03-12 20:33:57 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_rendering_xml_sets_content_type
|
2007-09-02 20:18:30 -04:00
|
|
|
process :hello_xml_world
|
2008-12-19 18:15:22 -05:00
|
|
|
assert_equal('application/xml; charset=utf-8', @response.headers['Content-Type'])
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-03-12 20:33:57 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_rendering_xml_respects_content_type
|
2009-06-16 19:46:56 -04:00
|
|
|
process :hello_xml_world_pdf
|
|
|
|
assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rendering_xml_respects_content_type_when_set_in_the_header
|
|
|
|
process :hello_xml_world_pdf_header
|
|
|
|
assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type'])
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-06-01 23:39:56 -04:00
|
|
|
|
|
|
|
def test_render_text_with_custom_content_type
|
|
|
|
get :render_text_with_custom_content_type
|
2008-12-19 18:15:22 -05:00
|
|
|
assert_equal 'application/rss+xml; charset=utf-8', @response.headers['Content-Type']
|
2006-06-01 23:39:56 -04:00
|
|
|
end
|
2006-02-09 15:05:11 -05:00
|
|
|
end
|