2008-01-05 08:32:06 -05:00
|
|
|
require 'abstract_unit'
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
# a controller class to facilitate the tests
|
|
|
|
class ActionPackAssertionsController < ActionController::Base
|
|
|
|
|
|
|
|
# this does absolutely nothing
|
2006-11-28 18:41:04 -05:00
|
|
|
def nothing() head :ok end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
# a standard template
|
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
|
|
|
|
|
|
|
# a standard template
|
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
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# a redirect to an internal location
|
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
|
|
|
|
|
|
|
def redirect_to_named_route() redirect_to route_one_url end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# a redirect to an external location
|
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
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# a 404
|
2006-11-28 18:41:04 -05:00
|
|
|
def response404() head '404 AWOL' end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
# a 500
|
2006-11-28 18:41:04 -05:00
|
|
|
def response500() head '500 Sorry' end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
# a fictional 599
|
2006-11-28 18:41:04 -05:00
|
|
|
def response599() head '599 Whoah!' end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
# putting stuff in the flash
|
|
|
|
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
|
|
|
|
|
|
|
|
# we have a flash, but nothing is in it
|
|
|
|
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
|
|
|
|
|
|
|
|
# assign some template instance variables
|
|
|
|
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
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# puts something in the session
|
|
|
|
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
|
|
|
|
2004-12-07 06:10:46 -05:00
|
|
|
# raises exception on get requests
|
|
|
|
def raise_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
|
|
|
|
|
|
|
|
# raises exception on post requests
|
|
|
|
def raise_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-10-15 22:20:53 -04:00
|
|
|
def get_valid_record
|
2006-09-29 03:34:02 -04:00
|
|
|
@record = Class.new do
|
2005-10-15 22:20:53 -04:00
|
|
|
def valid?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
2006-09-29 03:34:02 -04:00
|
|
|
Class.new do
|
|
|
|
def full_messages; []; end
|
2005-10-15 22:20:53 -04:00
|
|
|
end.new
|
2006-09-29 03:34:02 -04:00
|
|
|
end
|
|
|
|
|
2005-10-15 22:20:53 -04:00
|
|
|
end.new
|
2006-09-29 03:34:02 -04:00
|
|
|
|
|
|
|
render :nothing => true
|
2005-10-15 22:20:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def get_invalid_record
|
2006-09-29 03:34:02 -04:00
|
|
|
@record = Class.new do
|
|
|
|
|
2005-10-15 22:20:53 -04:00
|
|
|
def valid?
|
|
|
|
false
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2005-10-15 22:20:53 -04:00
|
|
|
def errors
|
2006-09-29 03:34:02 -04:00
|
|
|
Class.new do
|
|
|
|
def full_messages; ['...stuff...']; end
|
2005-10-15 22:20:53 -04:00
|
|
|
end.new
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
end.new
|
|
|
|
|
|
|
|
render :nothing => true
|
2004-12-07 06:10:46 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
# 911
|
|
|
|
def rescue_action(e) raise; 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
|
|
|
|
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
|
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
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2006-09-29 03:34:02 -04:00
|
|
|
# tell the controller where to find its templates but start from parent
|
|
|
|
# directory of test_request_response to simulate the behaviour of a
|
2004-11-23 20:04:44 -05:00
|
|
|
# production environment
|
2007-02-04 15:47:05 -05:00
|
|
|
ActionPackAssertionsController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
# a test case to exercise the new capabilities TestRequest & TestResponse
|
2004-12-07 06:10:46 -05:00
|
|
|
class ActionPackAssertionsControllerTest < Test::Unit::TestCase
|
2006-09-29 03:34:02 -04:00
|
|
|
# let's get this party started
|
2004-11-23 20:04:44 -05:00
|
|
|
def setup
|
2006-12-25 04:34:01 -05:00
|
|
|
ActionController::Routing::Routes.reload
|
|
|
|
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module content admin/user))
|
2004-11-23 20:04:44 -05:00
|
|
|
@controller = ActionPackAssertionsController.new
|
|
|
|
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2006-12-25 04:34:01 -05:00
|
|
|
def teardown
|
|
|
|
ActionController::Routing::Routes.reload
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# -- assertion-based testing ------------------------------------------------
|
|
|
|
|
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
|
|
|
|
|
2004-12-07 06:10:46 -05:00
|
|
|
# test the get method, make sure the request really was a get
|
|
|
|
def test_get
|
|
|
|
assert_raise(RuntimeError) { get :raise_on_get }
|
|
|
|
get :raise_on_post
|
|
|
|
assert_equal @response.body, 'request method: GET'
|
|
|
|
end
|
|
|
|
|
|
|
|
# test the get method, make sure the request really was a get
|
|
|
|
def test_post
|
|
|
|
assert_raise(RuntimeError) { post :raise_on_post }
|
|
|
|
post :raise_on_get
|
|
|
|
assert_equal @response.body, 'request method: POST'
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2006-02-09 15:05:11 -05:00
|
|
|
# the following test fails because the request_method is now cached on the request instance
|
|
|
|
# test the get/post switch within one test action
|
|
|
|
# def test_get_post_switch
|
|
|
|
# post :raise_on_get
|
|
|
|
# assert_equal @response.body, 'request method: POST'
|
|
|
|
# get :raise_on_post
|
|
|
|
# assert_equal @response.body, 'request method: GET'
|
|
|
|
# post :raise_on_get
|
|
|
|
# assert_equal @response.body, 'request method: POST'
|
|
|
|
# get :raise_on_post
|
|
|
|
# assert_equal @response.body, 'request method: GET'
|
|
|
|
# end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-08-06 04:37:25 -04:00
|
|
|
# test the redirection to a named route
|
|
|
|
def test_assert_redirect_to_named_route
|
2006-04-22 11:08:25 -04:00
|
|
|
with_routing do |set|
|
2006-06-01 11:42:08 -04:00
|
|
|
set.draw do |map|
|
|
|
|
map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing'
|
|
|
|
map.connect ':controller/:action/:id'
|
2006-04-22 11:08:25 -04:00
|
|
|
end
|
2007-05-12 00:18:46 -04:00
|
|
|
set.install_helpers
|
2006-06-01 11:42:08 -04:00
|
|
|
|
2006-04-22 11:08:25 -04:00
|
|
|
process :redirect_to_named_route
|
|
|
|
assert_redirected_to 'http://test.host/route_one'
|
|
|
|
assert_redirected_to route_one_url
|
2006-04-24 23:54:46 -04:00
|
|
|
assert_redirected_to :route_one_url
|
2005-08-06 04:37:25 -04:00
|
|
|
end
|
|
|
|
end
|
2006-04-22 11:08:25 -04:00
|
|
|
|
|
|
|
def test_assert_redirect_to_named_route_failure
|
|
|
|
with_routing do |set|
|
2006-06-01 11:42:08 -04:00
|
|
|
set.draw do |map|
|
|
|
|
map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'one'
|
|
|
|
map.route_two 'route_two', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
|
|
|
|
map.connect ':controller/:action/:id'
|
2006-04-22 11:08:25 -04:00
|
|
|
end
|
|
|
|
process :redirect_to_named_route
|
|
|
|
assert_raise(Test::Unit::AssertionFailedError) do
|
|
|
|
assert_redirected_to 'http://test.host/route_two'
|
|
|
|
end
|
|
|
|
assert_raise(Test::Unit::AssertionFailedError) do
|
|
|
|
assert_redirected_to :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
|
|
|
|
end
|
|
|
|
assert_raise(Test::Unit::AssertionFailedError) do
|
|
|
|
assert_redirected_to route_two_url
|
|
|
|
end
|
|
|
|
assert_raise(Test::Unit::AssertionFailedError) do
|
2006-04-24 23:54:46 -04:00
|
|
|
assert_redirected_to :route_two_url
|
2006-04-22 11:08:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-08-13 14:31:58 -04:00
|
|
|
def test_assert_redirect_to_nested_named_route
|
|
|
|
with_routing do |set|
|
|
|
|
set.draw do |map|
|
|
|
|
map.admin_inner_module 'admin/inner_module', :controller => 'admin/inner_module', :action => 'index'
|
|
|
|
map.connect ':controller/:action/:id'
|
|
|
|
end
|
|
|
|
@controller = Admin::InnerModuleController.new
|
|
|
|
process :redirect_to_index
|
|
|
|
# redirection is <{"action"=>"index", "controller"=>"admin/admin/inner_module"}>
|
|
|
|
assert_redirected_to admin_inner_module_path
|
|
|
|
end
|
|
|
|
end
|
2006-12-25 04:34:01 -05:00
|
|
|
|
|
|
|
def test_assert_redirected_to_top_level_named_route_from_nested_controller
|
|
|
|
with_routing do |set|
|
|
|
|
set.draw do |map|
|
|
|
|
map.top_level '/action_pack_assertions/:id', :controller => 'action_pack_assertions', :action => 'index'
|
|
|
|
map.connect ':controller/:action/:id'
|
|
|
|
end
|
|
|
|
@controller = Admin::InnerModuleController.new
|
|
|
|
process :redirect_to_top_level_named_route
|
|
|
|
# passes -> assert_redirected_to "http://test.host/action_pack_assertions/foo"
|
|
|
|
assert_redirected_to "/action_pack_assertions/foo"
|
|
|
|
end
|
|
|
|
end
|
2006-08-13 14:31:58 -04:00
|
|
|
|
2005-02-07 09:15:53 -05:00
|
|
|
# -- standard request/response object testing --------------------------------
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# make sure that the template objects exist
|
|
|
|
def test_template_objects_alive
|
|
|
|
process :assign_this
|
|
|
|
assert !@response.has_template_object?('hi')
|
|
|
|
assert @response.has_template_object?('howdy')
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# make sure we don't have template objects when we shouldn't
|
|
|
|
def test_template_object_missing
|
|
|
|
process :nothing
|
|
|
|
assert_nil @response.template_objects['howdy']
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# check the empty flashing
|
|
|
|
def test_flash_me_naked
|
|
|
|
process :flash_me_naked
|
2005-03-20 14:12:53 -05:00
|
|
|
assert !@response.has_flash?
|
2004-11-23 20:04:44 -05:00
|
|
|
assert !@response.has_flash_with_contents?
|
|
|
|
end
|
|
|
|
|
|
|
|
# check if we have flash objects
|
|
|
|
def test_flash_haves
|
|
|
|
process :flash_me
|
|
|
|
assert @response.has_flash?
|
|
|
|
assert @response.has_flash_with_contents?
|
|
|
|
assert @response.has_flash_object?('hello')
|
|
|
|
end
|
|
|
|
|
|
|
|
# ensure we don't have flash objects
|
|
|
|
def test_flash_have_nots
|
|
|
|
process :nothing
|
|
|
|
assert !@response.has_flash?
|
|
|
|
assert !@response.has_flash_with_contents?
|
|
|
|
assert_nil @response.flash['hello']
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
|
|
|
# check if we were rendered by a file-based template?
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_rendered_action
|
|
|
|
process :nothing
|
|
|
|
assert !@response.rendered_with_file?
|
|
|
|
|
2007-09-02 20:18:30 -04:00
|
|
|
process :hello_world
|
2004-11-23 20:04:44 -05:00
|
|
|
assert @response.rendered_with_file?
|
|
|
|
assert 'hello_world', @response.rendered_file
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# check the redirection location
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
# check server errors
|
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
|
|
|
# check a 404 response code
|
|
|
|
def test_missing_response_code
|
|
|
|
process :response404
|
|
|
|
assert @response.missing?
|
|
|
|
end
|
|
|
|
|
|
|
|
# check to see if our redirection matches a pattern
|
|
|
|
def test_redirect_url_match
|
|
|
|
process :redirect_external
|
|
|
|
assert @response.redirect?
|
|
|
|
assert @response.redirect_url_match?("rubyonrails")
|
|
|
|
assert @response.redirect_url_match?(/rubyonrails/)
|
|
|
|
assert !@response.redirect_url_match?("phpoffrails")
|
|
|
|
assert !@response.redirect_url_match?(/perloffrails/)
|
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# check for a redirection
|
|
|
|
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
|
|
|
# check a successful response code
|
|
|
|
def test_successful_response_code
|
|
|
|
process :nothing
|
|
|
|
assert @response.success?
|
2006-09-29 03:34:02 -04:00
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# a basic check to make sure we have a TestResponse object
|
|
|
|
def test_has_response
|
|
|
|
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
|
|
|
|
process :render_based_on_parameters, "name" => "David"
|
|
|
|
assert_equal "Mr. David", @response.body
|
|
|
|
end
|
|
|
|
|
2005-02-12 14:35:30 -05:00
|
|
|
def test_follow_redirect
|
|
|
|
process :redirect_to_action
|
|
|
|
assert_redirected_to :action => "flash_me"
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2005-02-12 14:35:30 -05:00
|
|
|
follow_redirect
|
2005-06-26 10:36:13 -04:00
|
|
|
assert_equal 1, @request.parameters["id"].to_i
|
2005-02-12 16:54:34 -05:00
|
|
|
|
2005-02-12 14:35:30 -05:00
|
|
|
assert "Inconceivable!", @response.body
|
|
|
|
end
|
2006-04-24 23:54:46 -04:00
|
|
|
|
2005-02-12 14:35:30 -05:00
|
|
|
def test_follow_redirect_outside_current_action
|
|
|
|
process :redirect_to_controller
|
|
|
|
assert_redirected_to :controller => "elsewhere", :action => "flash_me"
|
|
|
|
|
|
|
|
assert_raises(RuntimeError, "Can't follow redirects outside of current controller (elsewhere)") { follow_redirect }
|
|
|
|
end
|
2005-05-19 15:19:58 -04:00
|
|
|
|
2006-04-24 23:54:46 -04:00
|
|
|
def test_assert_redirection_fails_with_incorrect_controller
|
|
|
|
process :redirect_to_controller
|
|
|
|
assert_raise(Test::Unit::AssertionFailedError) do
|
|
|
|
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
|
|
|
|
|
2005-05-19 15:19:58 -04:00
|
|
|
def test_redirected_to_url_leadling_slash
|
|
|
|
process :redirect_to_path
|
|
|
|
assert_redirected_to '/some/path'
|
|
|
|
end
|
|
|
|
def test_redirected_to_url_no_leadling_slash
|
|
|
|
process :redirect_to_path
|
|
|
|
assert_redirected_to 'some/path'
|
|
|
|
end
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2005-10-15 22:20:53 -04:00
|
|
|
def test_assert_valid
|
|
|
|
get :get_valid_record
|
2006-09-29 03:34:02 -04:00
|
|
|
assert_valid assigns('record')
|
|
|
|
end
|
|
|
|
|
2005-10-15 22:20:53 -04:00
|
|
|
def test_assert_valid_failing
|
|
|
|
get :get_invalid_record
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2005-10-15 22:20:53 -04:00
|
|
|
begin
|
2006-09-29 03:34:02 -04:00
|
|
|
assert_valid assigns('record')
|
2005-10-15 22:20:53 -04:00
|
|
|
assert false
|
2006-09-29 03:34:02 -04:00
|
|
|
rescue Test::Unit::AssertionFailedError => e
|
2005-10-15 22:20:53 -04:00
|
|
|
end
|
2005-06-27 01:36:03 -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'
|
|
|
|
rescue Test::Unit::AssertionFailedError => e
|
|
|
|
assert e.message.include?('FAIL')
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2006-09-29 03:34:02 -04:00
|
|
|
class ActionPackHeaderTest < Test::Unit::TestCase
|
2004-11-23 20:04:44 -05:00
|
|
|
def setup
|
|
|
|
@controller = ActionPackAssertionsController.new
|
|
|
|
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
|
|
|
end
|
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
|
2007-02-18 21:25:01 -05:00
|
|
|
assert_equal('application/xml; charset=utf-8', @response.headers['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
|
2007-02-18 21:25:01 -05:00
|
|
|
@response.headers['type'] = 'application/pdf'
|
2007-09-02 20:18:30 -04:00
|
|
|
process :hello_xml_world
|
2007-02-18 21:25:01 -05:00
|
|
|
assert_equal('application/pdf; charset=utf-8', @response.headers['type'])
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-06-01 23:39:56 -04:00
|
|
|
|
2006-09-29 03:34:02 -04:00
|
|
|
|
2006-06-01 23:39:56 -04:00
|
|
|
def test_render_text_with_custom_content_type
|
|
|
|
get :render_text_with_custom_content_type
|
2007-02-18 21:25:01 -05:00
|
|
|
assert_equal 'application/rss+xml; charset=utf-8', @response.headers['type']
|
2006-06-01 23:39:56 -04:00
|
|
|
end
|
2006-02-09 15:05:11 -05:00
|
|
|
end
|