2008-01-05 13:32:06 +00:00
require 'abstract_unit'
require 'controller/fake_models'
2007-05-17 20:48:47 +00:00
class CustomersController < ActionController :: Base
end
2005-05-22 07:43:05 +00:00
module Fun
class GamesController < ActionController :: Base
def hello_world
end
end
end
2006-03-08 05:21:27 +00:00
module NewRenderTestHelper
def rjs_helper_method_from_module
page . visual_effect :highlight
end
end
2008-01-16 02:01:57 +00:00
class LabellingFormBuilder < ActionView :: Helpers :: FormBuilder
end
2005-05-30 09:00:46 +00:00
class NewRenderTestController < ActionController :: Base
2005-05-22 07:43:05 +00:00
layout :determine_layout
2005-05-30 09:00:46 +00:00
def self . controller_name ; " test " ; end
def self . controller_path ; " test " ; end
2005-05-22 07:43:05 +00:00
def hello_world
end
def render_hello_world
2005-05-22 08:58:43 +00:00
render :template = > " test/hello_world "
2005-05-22 07:43:05 +00:00
end
def render_hello_world_from_variable
@person = " david "
2005-05-22 08:58:43 +00:00
render :text = > " hello #{ @person } "
2005-05-22 07:43:05 +00:00
end
def render_action_hello_world
2005-05-22 08:58:43 +00:00
render :action = > " hello_world "
2005-05-22 07:43:05 +00:00
end
2006-02-17 18:32:21 +00:00
def render_action_hello_world_as_symbol
render :action = > :hello_world
end
2005-05-22 07:43:05 +00:00
def render_text_hello_world
2005-05-22 08:58:43 +00:00
render :text = > " hello world "
2005-05-22 07:43:05 +00:00
end
2005-10-28 07:33:54 +00:00
def render_text_hello_world_with_layout
@variable_for_layout = " , I'm here! "
render :text = > " hello world " , :layout = > true
end
2005-05-22 07:43:05 +00:00
2005-12-20 05:32:39 +00:00
def hello_world_with_layout_false
render :layout = > false
end
2005-05-22 07:43:05 +00:00
def render_custom_code
2005-05-22 08:58:43 +00:00
render :text = > " hello world " , :status = > " 404 Moved "
2005-05-22 07:43:05 +00:00
end
2005-11-22 08:37:04 +00:00
def render_file_with_instance_variables
@secret = 'in the sauce'
2007-02-20 22:09:12 +00:00
path = File . join ( File . dirname ( __FILE__ ) , '../fixtures/test/render_file_with_ivar.erb' )
2005-11-22 08:37:04 +00:00
render :file = > path
end
def render_file_with_locals
2007-02-20 22:09:12 +00:00
path = File . join ( File . dirname ( __FILE__ ) , '../fixtures/test/render_file_with_locals.erb' )
2005-11-22 08:37:04 +00:00
render :file = > path , :locals = > { :secret = > 'in the sauce' }
end
def render_file_not_using_full_path
@secret = 'in the sauce'
render :file = > 'test/render_file_with_ivar' , :use_full_path = > true
end
2005-05-22 07:43:05 +00:00
2006-03-16 02:51:19 +00:00
def render_file_not_using_full_path_with_dot_in_path
@secret = 'in the sauce'
render :file = > 'test/dot.directory/render_file_with_ivar' , :use_full_path = > true
end
2005-05-22 07:43:05 +00:00
def render_xml_hello
@name = " David "
2005-05-22 08:58:43 +00:00
render :template = > " test/hello "
2005-05-22 07:43:05 +00:00
end
def greeting
# let's just rely on the template
end
def layout_test
2005-05-22 08:58:43 +00:00
render :action = > " hello_world "
2005-05-22 07:43:05 +00:00
end
def layout_test_with_different_layout
2005-05-22 08:58:43 +00:00
render :action = > " hello_world " , :layout = > " standard "
2005-05-22 07:43:05 +00:00
end
def rendering_without_layout
2005-05-22 08:58:43 +00:00
render :action = > " hello_world " , :layout = > false
2005-05-22 07:43:05 +00:00
end
2005-08-05 20:51:03 +00:00
def layout_overriding_layout
render :action = > " hello_world " , :layout = > " standard "
end
2005-05-22 07:43:05 +00:00
2005-05-22 16:59:55 +00:00
def rendering_nothing_on_layout
render :nothing = > true
end
2005-05-22 07:43:05 +00:00
def builder_layout_test
2005-05-22 08:58:43 +00:00
render :action = > " hello "
2005-05-22 07:43:05 +00:00
end
def partials_list
2005-07-05 18:21:26 +00:00
@test_unchanged = 'hello'
2005-05-22 07:43:05 +00:00
@customers = [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
2005-05-22 08:58:43 +00:00
render :action = > " list "
2005-05-22 07:43:05 +00:00
end
def partial_only
2005-05-30 07:20:37 +00:00
render :partial = > true
2005-05-22 07:43:05 +00:00
end
2005-05-30 07:51:02 +00:00
def partial_only_with_layout
2005-06-01 13:39:58 +00:00
render :partial = > " partial_only " , :layout = > true
2005-05-30 07:51:02 +00:00
end
2005-07-27 09:11:00 +00:00
def partial_with_locals
render :partial = > " customer " , :locals = > { :customer = > Customer . new ( " david " ) }
end
2008-01-16 02:01:57 +00:00
def partial_with_form_builder
2008-02-02 06:16:04 +00:00
render :partial = > ActionView :: Helpers :: FormBuilder . new ( :post , nil , @template , { } , Proc . new { } )
2008-01-16 02:01:57 +00:00
end
2008-02-02 06:16:04 +00:00
2008-01-16 02:01:57 +00:00
def partial_with_form_builder_subclass
2008-02-02 06:16:04 +00:00
render :partial = > LabellingFormBuilder . new ( :post , nil , @template , { } , Proc . new { } )
2008-01-16 02:01:57 +00:00
end
2005-07-27 09:11:00 +00:00
def partial_collection
render :partial = > " customer " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
end
2008-03-03 04:01:35 +00:00
def partial_collection_with_spacer
render :partial = > " customer " , :spacer_template = > " partial_only " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
end
def partial_collection_with_counter
render :partial = > " customer_counter " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
end
2005-07-27 09:11:00 +00:00
def partial_collection_with_locals
2005-07-27 12:06:19 +00:00
render :partial = > " customer_greeting " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ] , :locals = > { :greeting = > " Bonjour " }
2005-07-27 09:11:00 +00:00
end
2005-05-30 07:51:02 +00:00
2008-02-08 22:04:06 +00:00
def partial_collection_shorthand_with_locals
render :partial = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ] , :locals = > { :greeting = > " Bonjour " }
end
2005-09-01 21:43:38 +00:00
def empty_partial_collection
render :partial = > " customer " , :collection = > [ ]
end
2005-09-09 07:27:44 +00:00
def partial_with_hash_object
render :partial = > " hash_object " , :object = > { :first_name = > " Sam " }
end
2007-09-03 00:18:30 +00:00
def partial_hash_collection
render :partial = > " hash_object " , :collection = > [ { :first_name = > " Pratik " } , { :first_name = > " Amy " } ]
end
def partial_hash_collection_with_locals
render :partial = > " hash_greeting " , :collection = > [ { :first_name = > " Pratik " } , { :first_name = > " Amy " } ] , :locals = > { :greeting = > " Hola " }
end
2005-10-10 20:35:13 +00:00
def partial_with_implicit_local_assignment
@customer = Customer . new ( " Marcel " )
render :partial = > " customer "
end
2007-05-24 16:42:10 +00:00
def missing_partial
render :partial = > 'thisFileIsntHere'
end
2005-05-22 07:43:05 +00:00
def hello_in_a_string
@customers = [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
2007-09-03 00:18:30 +00:00
render :text = > " How's there? " << render_to_string ( :template = > " test/list " )
2005-05-22 07:43:05 +00:00
end
2006-11-20 11:03:21 +00:00
def render_to_string_with_assigns
@before = " i'm before the render "
render_to_string :text = > " foo "
@after = " i'm after the render "
render :action = > " test/hello_world "
end
2007-01-12 06:10:06 +00:00
def render_to_string_with_partial
@partial_only = render_to_string :partial = > " partial_only "
@partial_with_locals = render_to_string :partial = > " customer " , :locals = > { :customer = > Customer . new ( " david " ) }
render :action = > " test/hello_world "
end
2006-11-20 11:03:21 +00:00
def render_to_string_with_exception
render_to_string :file = > " exception that will not be caught - this will certainly not work " , :use_full_path = > true
end
def render_to_string_with_caught_exception
@before = " i'm before the render "
begin
render_to_string :file = > " exception that will be caught- hope my future instance vars still work! " , :use_full_path = > true
rescue
end
@after = " i'm after the render "
render :action = > " test/hello_world "
end
2006-09-04 05:09:18 +00:00
2005-05-22 07:43:05 +00:00
def accessing_params_in_template
2005-05-22 08:58:43 +00:00
render :inline = > " Hello: <%= params[:name] %> "
2005-05-22 07:43:05 +00:00
end
2005-05-30 09:12:12 +00:00
def accessing_params_in_template_with_layout
2005-07-23 09:00:05 +00:00
render :layout = > nil , :inline = > " Hello: <%= params[:name] %> "
2005-05-30 09:12:12 +00:00
end
2005-06-15 13:20:17 +00:00
def render_with_explicit_template
2007-09-03 00:18:30 +00:00
render :template = > " test/hello_world "
2005-06-15 13:20:17 +00:00
end
2005-07-09 15:31:06 +00:00
def double_render
render :text = > " hello "
render :text = > " world "
end
def double_redirect
redirect_to :action = > " double_render "
redirect_to :action = > " double_render "
end
def render_and_redirect
render :text = > " hello "
redirect_to :action = > " double_render "
end
2006-11-20 11:03:21 +00:00
def render_to_string_and_render
@stuff = render_to_string :text = > " here is some cached stuff "
render :text = > " Hi web users! #{ @stuff } "
end
2005-07-09 15:31:06 +00:00
2005-07-21 07:14:35 +00:00
def rendering_with_conflicting_local_vars
@name = " David "
2005-08-26 22:37:36 +00:00
def @template . name ( ) nil end
2005-07-21 07:14:35 +00:00
render :action = > " potential_conflicts "
end
2006-03-12 03:39:58 +00:00
def hello_world_from_rxml_using_action
2007-12-10 20:41:59 +00:00
render :action = > " hello_world_from_rxml.builder "
2006-03-12 03:39:58 +00:00
end
def hello_world_from_rxml_using_template
2007-12-10 20:41:59 +00:00
render :template = > " test/hello_world_from_rxml.builder "
2006-03-12 03:39:58 +00:00
end
2006-09-28 19:13:55 +00:00
def head_with_location_header
head :location = > " /foo "
end
def head_with_symbolic_status
head :status = > params [ :status ] . intern
end
def head_with_integer_status
head :status = > params [ :status ] . to_i
end
def head_with_string_status
head :status = > params [ :status ]
end
def head_with_custom_header
head :x_custom_header = > " something "
end
2006-09-28 19:32:40 +00:00
def head_with_status_code_first
head :forbidden , :x_custom_header = > " something "
end
2007-04-24 18:29:37 +00:00
def render_with_location
render :xml = > " <hello/> " , :location = > " http://example.com " , :status = > 201
end
2007-05-17 20:48:47 +00:00
def render_with_object_location
customer = Customer . new ( " Some guy " , 1 )
render :xml = > " <customer/> " , :location = > customer_url ( customer ) , :status = > :created
end
2007-04-24 18:29:37 +00:00
def render_with_to_xml
to_xmlable = Class . new do
def to_xml
" <i-am-xml/> "
end
end . new
render :xml = > to_xmlable
end
2006-03-08 05:21:27 +00:00
helper NewRenderTestHelper
helper do
def rjs_helper_method ( value )
page . visual_effect :highlight , value
end
end
2006-03-05 16:35:27 +00:00
def enum_rjs_test
render :update do | page |
page . select ( '.product' ) . each do | value |
2006-03-08 05:21:27 +00:00
page . rjs_helper_method_from_module
page . rjs_helper_method ( value )
2006-03-05 16:35:27 +00:00
page . sortable ( value , :url = > { :action = > " order " } )
page . draggable ( value )
end
end
end
2005-11-17 21:28:59 +00:00
def delete_with_js
@project_id = 4
end
def render_js_with_explicit_template
@project_id = 4
render :template = > 'test/delete_with_js'
end
def render_js_with_explicit_action_template
@project_id = 4
render :action = > 'delete_with_js'
end
2006-01-20 22:04:07 +00:00
def update_page
render :update do | page |
page . replace_html 'balance' , '$37,000,000.00'
page . visual_effect :highlight , 'balance'
end
end
2006-01-30 04:49:17 +00:00
def update_page_with_instance_variables
@money = '$37,000,000.00'
@div_id = 'balance'
render :update do | page |
page . replace_html @div_id , @money
page . visual_effect :highlight , @div_id
end
end
2006-01-20 22:04:07 +00:00
2005-07-23 08:43:01 +00:00
def action_talk_to_layout
# Action template sets variable that's picked up by layout
end
2005-07-31 12:16:21 +00:00
def render_text_with_assigns
@hello = " world "
render :text = > " foo "
end
2005-09-01 21:51:27 +00:00
def yield_content_for
render :action = > " content_for " , :layout = > " yield "
end
2006-09-17 16:20:32 +00:00
def render_content_type_from_body
response . content_type = Mime :: RSS
render :text = > " hello world! "
end
2007-08-02 20:10:03 +00:00
def render_call_to_partial_with_layout
render :action = > " calling_partial_with_layout "
end
2008-01-03 15:28:36 +00:00
def render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
render :action = > " calling_partial_with_layout "
end
2007-08-02 20:10:03 +00:00
def render_using_layout_around_block
render :action = > " using_layout_around_block "
end
2008-01-03 15:28:36 +00:00
def render_using_layout_around_block_in_main_layout_and_within_content_for_layout
render :action = > " using_layout_around_block "
end
2005-05-22 07:43:05 +00:00
def rescue_action ( e ) raise end
private
def determine_layout
case action_name
2005-06-01 13:39:58 +00:00
when " hello_world " , " layout_test " , " rendering_without_layout " ,
2005-05-30 07:51:02 +00:00
" rendering_nothing_on_layout " , " render_text_hello_world " ,
2005-10-28 07:33:54 +00:00
" render_text_hello_world_with_layout " ,
2005-12-20 05:32:39 +00:00
" hello_world_with_layout_false " ,
2005-05-30 09:12:12 +00:00
" partial_only " , " partial_only_with_layout " ,
" accessing_params_in_template " ,
2005-06-15 13:20:17 +00:00
" accessing_params_in_template_with_layout " ,
2005-11-18 08:32:17 +00:00
" render_with_explicit_template " ,
2005-12-17 06:38:06 +00:00
" render_js_with_explicit_template " ,
" render_js_with_explicit_action_template " ,
2006-01-30 04:49:17 +00:00
" delete_with_js " , " update_page " , " update_page_with_instance_variables "
2005-12-17 06:38:06 +00:00
2005-05-22 07:43:05 +00:00
" layouts/standard "
when " builder_layout_test "
" layouts/builder "
2005-08-05 20:51:03 +00:00
when " action_talk_to_layout " , " layout_overriding_layout "
2005-07-23 08:43:01 +00:00
" layouts/talk_from_action "
2008-01-03 15:28:36 +00:00
when " render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout "
" layouts/partial_with_layout "
when " render_using_layout_around_block_in_main_layout_and_within_content_for_layout "
" layouts/block_with_layout "
2005-05-22 07:43:05 +00:00
end
end
end
2007-02-04 20:47:05 +00:00
NewRenderTestController . view_paths = [ File . dirname ( __FILE__ ) + " /../fixtures/ " ]
Fun :: GamesController . view_paths = [ File . dirname ( __FILE__ ) + " /../fixtures/ " ]
2005-05-22 07:43:05 +00:00
2005-05-30 09:00:46 +00:00
class NewRenderTest < Test :: Unit :: TestCase
def setup
@controller = NewRenderTestController . new
2005-05-22 07:43:05 +00:00
2005-05-30 09:00:46 +00:00
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
# a more accurate simulation of what happens in "real life".
@controller . logger = Logger . new ( nil )
2005-05-22 07:43:05 +00:00
@request = ActionController :: TestRequest . new
@response = ActionController :: TestResponse . new
@request . host = " www.nextangle.com "
end
def test_simple_show
2005-05-22 17:12:29 +00:00
get :hello_world
assert_response :success
assert_template " test/hello_world "
2005-06-01 13:39:58 +00:00
assert_equal " <html>Hello world!</html> " , @response . body
2005-05-22 07:43:05 +00:00
end
def test_do_with_render
2005-05-22 17:12:29 +00:00
get :render_hello_world
assert_template " test/hello_world "
2005-05-22 07:43:05 +00:00
end
def test_do_with_render_from_variable
2005-05-22 17:12:29 +00:00
get :render_hello_world_from_variable
assert_equal " hello david " , @response . body
2005-05-22 07:43:05 +00:00
end
def test_do_with_render_action
2005-05-22 17:12:29 +00:00
get :render_action_hello_world
assert_template " test/hello_world "
2005-05-22 07:43:05 +00:00
end
2006-02-17 18:32:21 +00:00
def test_do_with_render_action_as_symbol
get :render_action_hello_world_as_symbol
assert_template " test/hello_world "
end
2005-05-22 07:43:05 +00:00
def test_do_with_render_text
2005-05-22 17:12:29 +00:00
get :render_text_hello_world
assert_equal " hello world " , @response . body
2005-05-22 07:43:05 +00:00
end
2005-10-28 07:33:54 +00:00
def test_do_with_render_text_and_layout
get :render_text_hello_world_with_layout
assert_equal " <html>hello world, I'm here!</html> " , @response . body
end
2005-12-20 05:32:39 +00:00
def test_do_with_render_action_and_layout_false
get :hello_world_with_layout_false
assert_equal 'Hello world!' , @response . body
end
2005-05-22 07:43:05 +00:00
def test_do_with_render_custom_code
2005-05-22 17:12:29 +00:00
get :render_custom_code
assert_response :missing
2005-05-22 07:43:05 +00:00
end
2005-11-22 08:37:04 +00:00
def test_render_file_with_instance_variables
get :render_file_with_instance_variables
assert_equal " The secret is in the sauce \n " , @response . body
end
def test_render_file_not_using_full_path
get :render_file_not_using_full_path
assert_equal " The secret is in the sauce \n " , @response . body
end
2006-03-16 02:51:19 +00:00
def test_render_file_not_using_full_path_with_dot_in_path
get :render_file_not_using_full_path_with_dot_in_path
assert_equal " The secret is in the sauce \n " , @response . body
end
2005-11-22 08:37:04 +00:00
def test_render_file_with_locals
get :render_file_with_locals
assert_equal " The secret is in the sauce \n " , @response . body
end
2005-05-22 07:43:05 +00:00
def test_attempt_to_access_object_method
2005-05-22 17:12:29 +00:00
assert_raises ( ActionController :: UnknownAction , " No action responded to [clone] " ) { get :clone }
2005-05-22 07:43:05 +00:00
end
def test_private_methods
2005-05-22 17:12:29 +00:00
assert_raises ( ActionController :: UnknownAction , " No action responded to [determine_layout] " ) { get :determine_layout }
2005-05-22 07:43:05 +00:00
end
def test_access_to_request_in_view
2005-07-23 09:00:05 +00:00
view_internals_old_value = ActionController :: Base . view_controller_internals
2005-05-22 07:43:05 +00:00
ActionController :: Base . view_controller_internals = false
2005-07-23 09:00:05 +00:00
ActionController :: Base . protected_variables_cache = nil
2005-05-22 07:43:05 +00:00
2005-05-22 17:12:29 +00:00
get :hello_world
2007-12-28 05:42:12 +00:00
assert ! assigns . include? ( '_request' ) , '_request should not be in assigns'
2006-09-29 07:34:02 +00:00
assert ! assigns . include? ( 'request' ) , 'request should not be in assigns'
2005-05-22 07:43:05 +00:00
ActionController :: Base . view_controller_internals = true
2005-07-23 09:00:05 +00:00
ActionController :: Base . protected_variables_cache = nil
2005-05-22 07:43:05 +00:00
2005-05-22 17:12:29 +00:00
get :hello_world
2007-03-13 03:49:52 +00:00
assert ! assigns . include? ( 'request' ) , 'request should not be in assigns'
assert_kind_of ActionController :: AbstractRequest , assigns [ '_request' ]
assert_kind_of ActionController :: AbstractRequest , @response . template . request
2005-07-23 09:00:05 +00:00
2006-09-29 07:34:02 +00:00
ensure
2005-07-23 09:00:05 +00:00
ActionController :: Base . view_controller_internals = view_internals_old_value
ActionController :: Base . protected_variables_cache = nil
2005-05-22 07:43:05 +00:00
end
2006-09-29 07:34:02 +00:00
2005-05-22 07:43:05 +00:00
def test_render_xml
2005-05-22 17:12:29 +00:00
get :render_xml_hello
assert_equal " <html> \n <p>Hello David</p> \n <p>This is grand!</p> \n </html> \n " , @response . body
2005-05-22 07:43:05 +00:00
end
2006-03-05 06:42:58 +00:00
def test_enum_rjs_test
get :enum_rjs_test
assert_equal <<-EOS.strip, @response.body
2006-03-13 02:11:59 +00:00
$$ ( " .product " ) . each ( function ( value , index ) {
2006-03-05 06:42:58 +00:00
new Effect . Highlight ( element , { } ) ;
new Effect . Highlight ( value , { } ) ;
Sortable . create ( value , { onUpdate : function ( ) { new Ajax . Request ( '/test/order' , { asynchronous : true , evalScripts : true , parameters : Sortable . serialize ( value ) } ) } } ) ;
new Draggable ( value , { } ) ;
} ) ;
EOS
end
2005-05-22 07:43:05 +00:00
def test_render_xml_with_default
2005-05-22 17:12:29 +00:00
get :greeting
assert_equal " <p>This is grand!</p> \n " , @response . body
2005-05-22 07:43:05 +00:00
end
2008-02-29 18:09:23 +00:00
def test_render_with_default_from_accept_header
@request . env [ " HTTP_ACCEPT " ] = " text/javascript "
get :greeting
assert_equal " $( \" body \" ).visualEffect( \" highlight \" ); " , @response . body
end
2005-11-17 21:28:59 +00:00
def test_render_rjs_with_default
get :delete_with_js
2006-09-20 20:14:12 +00:00
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});! , @response . body
2005-11-17 21:28:59 +00:00
end
def test_render_rjs_template_explicitly
get :render_js_with_explicit_template
2006-09-20 20:14:12 +00:00
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});! , @response . body
2005-11-17 21:28:59 +00:00
end
def test_rendering_rjs_action_explicitly
get :render_js_with_explicit_action_template
2006-09-20 20:14:12 +00:00
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});! , @response . body
2005-11-17 21:28:59 +00:00
end
2005-05-22 07:43:05 +00:00
def test_layout_rendering
2005-05-22 17:12:29 +00:00
get :layout_test
assert_equal " <html>Hello world!</html> " , @response . body
2005-05-22 07:43:05 +00:00
end
def test_layout_test_with_different_layout
2005-05-22 17:12:29 +00:00
get :layout_test_with_different_layout
assert_equal " <html>Hello world!</html> " , @response . body
2005-05-22 07:43:05 +00:00
end
def test_rendering_without_layout
2005-05-22 17:12:29 +00:00
get :rendering_without_layout
assert_equal " Hello world! " , @response . body
2005-05-22 07:43:05 +00:00
end
2005-08-05 20:51:03 +00:00
def test_layout_overriding_layout
get :layout_overriding_layout
assert_no_match %r{ <title> } , @response . body
end
2005-05-22 16:59:55 +00:00
def test_rendering_nothing_on_layout
2005-05-22 17:12:29 +00:00
get :rendering_nothing_on_layout
2005-07-14 07:19:26 +00:00
assert_equal " " , @response . body
2005-05-22 16:59:55 +00:00
end
2005-05-22 07:43:05 +00:00
def test_render_xml_with_layouts
2005-05-22 17:12:29 +00:00
get :builder_layout_test
assert_equal " <wrapper> \n <html> \n <p>Hello </p> \n <p>This is grand!</p> \n </html> \n </wrapper> \n " , @response . body
2005-05-22 07:43:05 +00:00
end
def test_partial_only
2005-05-22 17:12:29 +00:00
get :partial_only
assert_equal " only partial " , @response . body
2005-05-22 07:43:05 +00:00
end
2005-05-30 07:51:02 +00:00
def test_partial_only_with_layout
get :partial_only_with_layout
assert_equal " <html>only partial</html> " , @response . body
end
2005-05-22 07:43:05 +00:00
def test_render_to_string
2006-09-04 05:09:18 +00:00
assert_not_deprecated { get :hello_in_a_string }
2005-07-05 18:21:26 +00:00
assert_equal " How's there? goodbyeHello: davidHello: marygoodbye \n " , @response . body
2005-05-22 07:43:05 +00:00
end
2006-11-20 11:03:21 +00:00
def test_render_to_string_doesnt_break_assigns
get :render_to_string_with_assigns
assert_equal " i'm before the render " , assigns ( :before )
assert_equal " i'm after the render " , assigns ( :after )
end
2007-01-12 06:10:06 +00:00
def test_render_to_string_partial
get :render_to_string_with_partial
assert_equal " only partial " , assigns ( :partial_only )
assert_equal " Hello: david " , assigns ( :partial_with_locals )
end
2006-11-20 11:03:21 +00:00
def test_bad_render_to_string_still_throws_exception
assert_raises ( ActionController :: MissingTemplate ) { get :render_to_string_with_exception }
end
def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
assert_nothing_raised { get :render_to_string_with_caught_exception }
assert_equal " i'm before the render " , assigns ( :before )
assert_equal " i'm after the render " , assigns ( :after )
end
2005-05-22 07:43:05 +00:00
def test_nested_rendering
2005-05-22 17:12:29 +00:00
get :hello_world
2005-05-22 07:43:05 +00:00
assert_equal " Living in a nested world " , Fun :: GamesController . process ( @request , @response ) . body
end
def test_accessing_params_in_template
2005-05-22 17:12:29 +00:00
get :accessing_params_in_template , :name = > " David "
assert_equal " Hello: David " , @response . body
2005-05-22 07:43:05 +00:00
end
2005-05-30 09:12:12 +00:00
def test_accessing_params_in_template_with_layout
get :accessing_params_in_template_with_layout , :name = > " David "
assert_equal " <html>Hello: David</html> " , @response . body
end
2005-06-15 13:20:17 +00:00
def test_render_with_explicit_template
2007-09-03 00:18:30 +00:00
get :render_with_explicit_template
2005-06-15 13:20:17 +00:00
assert_response :success
end
2005-07-09 15:31:06 +00:00
def test_double_render
assert_raises ( ActionController :: DoubleRenderError ) { get :double_render }
end
def test_double_redirect
assert_raises ( ActionController :: DoubleRenderError ) { get :double_redirect }
end
def test_render_and_redirect
assert_raises ( ActionController :: DoubleRenderError ) { get :render_and_redirect }
end
2006-11-20 11:03:21 +00:00
# specify the one exception to double render rule - render_to_string followed by render
def test_render_to_string_and_render
get :render_to_string_and_render
assert_equal ( " Hi web users! here is some cached stuff " , @response . body )
end
2005-07-21 07:14:35 +00:00
def test_rendering_with_conflicting_local_vars
get :rendering_with_conflicting_local_vars
assert_equal ( " First: David \n Second: Stephan \n Third: David \n Fourth: David \n Fifth: " , @response . body )
end
2005-07-23 08:43:01 +00:00
def test_action_talk_to_layout
get :action_talk_to_layout
assert_equal " <title>Talking to the layout</title> \n Action was here! " , @response . body
end
2005-07-24 16:45:39 +00:00
def test_partials_list
get :partials_list
assert_equal " goodbyeHello: davidHello: marygoodbye \n " , @response . body
end
2005-07-27 09:11:00 +00:00
def test_partial_with_locals
get :partial_with_locals
2005-07-27 12:24:14 +00:00
assert_equal " Hello: david " , @response . body
2005-07-27 09:11:00 +00:00
end
2008-01-16 02:01:57 +00:00
def test_partial_with_form_builder
get :partial_with_form_builder
assert_match ( / <label / , @response . body )
assert_template ( 'test/_form' )
end
def test_partial_with_form_builder_subclass
get :partial_with_form_builder_subclass
assert_match ( / <label / , @response . body )
assert_template ( 'test/_labelling_form' )
end
2005-07-27 09:11:00 +00:00
def test_partial_collection
get :partial_collection
assert_equal " Hello: davidHello: mary " , @response . body
end
2008-03-03 04:01:35 +00:00
def test_partial_collection_with_counter
get :partial_collection_with_counter
assert_equal " david1mary2 " , @response . body
end
2005-07-27 09:11:00 +00:00
def test_partial_collection_with_locals
get :partial_collection_with_locals
2005-07-27 12:06:19 +00:00
assert_equal " Bonjour: davidBonjour: mary " , @response . body
2005-07-27 09:11:00 +00:00
end
2008-03-03 04:01:35 +00:00
def test_partial_collection_with_spacer
get :partial_collection_with_spacer
assert_equal " Hello: davidonly partialHello: mary " , @response . body
end
2005-07-31 12:16:21 +00:00
2008-02-08 22:04:06 +00:00
def test_partial_collection_shorthand_with_locals
get :partial_collection_shorthand_with_locals
assert_equal " Bonjour: davidBonjour: mary " , @response . body
end
2005-09-01 21:43:38 +00:00
def test_empty_partial_collection
get :empty_partial_collection
assert_equal " " , @response . body
end
2005-09-09 07:27:44 +00:00
def test_partial_with_hash_object
get :partial_with_hash_object
2007-10-25 21:32:01 +00:00
assert_equal " Sam \n maS \n " , @response . body
2005-09-09 07:27:44 +00:00
end
2007-09-03 00:18:30 +00:00
def test_hash_partial_collection
get :partial_hash_collection
2007-10-25 21:32:01 +00:00
assert_equal " Pratik \n kitarP \n Amy \n ymA \n " , @response . body
2007-09-03 00:18:30 +00:00
end
def test_partial_hash_collection_with_locals
get :partial_hash_collection_with_locals
assert_equal " Hola: PratikHola: Amy " , @response . body
end
2005-09-09 07:27:44 +00:00
2005-10-10 20:35:13 +00:00
def test_partial_with_implicit_local_assignment
get :partial_with_implicit_local_assignment
assert_equal " Hello: Marcel " , @response . body
end
2007-05-24 16:42:10 +00:00
def test_render_missing_partial_template
assert_raises ( ActionView :: ActionViewError ) do
get :missing_partial
end
end
2005-07-31 12:16:21 +00:00
def test_render_text_with_assigns
get :render_text_with_assigns
assert_equal " world " , assigns [ " hello " ]
end
2005-09-01 21:51:27 +00:00
2006-01-20 22:04:07 +00:00
def test_update_page
get :update_page
2006-01-23 16:29:37 +00:00
assert_template nil
2007-02-19 02:25:01 +00:00
assert_equal 'text/javascript; charset=utf-8' , @response . headers [ 'type' ]
2006-01-20 22:04:07 +00:00
assert_equal 2 , @response . body . split ( $/ ) . length
end
2006-01-30 04:49:17 +00:00
def test_update_page_with_instance_variables
get :update_page_with_instance_variables
assert_template nil
2007-02-19 02:25:01 +00:00
assert_equal 'text/javascript; charset=utf-8' , @response . headers [ 'type' ]
2006-01-30 04:49:17 +00:00
assert_match / balance / , @response . body
assert_match / \ $37 / , @response . body
end
2005-09-01 21:51:27 +00:00
def test_yield_content_for
2006-09-04 05:09:18 +00:00
assert_not_deprecated { get :yield_content_for }
2005-09-01 21:51:27 +00:00
assert_equal " <title>Putting stuff in the title!</title> \n \n Great stuff! \n " , @response . body
end
2006-03-12 03:39:58 +00:00
def test_overwritting_rendering_relative_file_with_extension
get :hello_world_from_rxml_using_template
assert_equal " <html> \n <p>Hello</p> \n </html> \n " , @response . body
get :hello_world_from_rxml_using_action
assert_equal " <html> \n <p>Hello</p> \n </html> \n " , @response . body
end
2006-09-28 19:13:55 +00:00
def test_head_with_location_header
get :head_with_location_header
assert @response . body . blank?
assert_equal " /foo " , @response . headers [ " Location " ]
2006-11-07 21:45:10 +00:00
assert_response :ok
2006-09-28 19:13:55 +00:00
end
def test_head_with_custom_header
get :head_with_custom_header
assert @response . body . blank?
assert_equal " something " , @response . headers [ " X-Custom-Header " ]
2006-11-07 21:45:10 +00:00
assert_response :ok
2006-09-28 19:13:55 +00:00
end
def test_head_with_symbolic_status
get :head_with_symbolic_status , :status = > " ok "
assert_equal " 200 OK " , @response . headers [ " Status " ]
2006-11-07 21:45:10 +00:00
assert_response :ok
2006-09-28 19:13:55 +00:00
get :head_with_symbolic_status , :status = > " not_found "
assert_equal " 404 Not Found " , @response . headers [ " Status " ]
2006-11-07 21:45:10 +00:00
assert_response :not_found
2006-09-28 19:13:55 +00:00
ActionController :: StatusCodes :: SYMBOL_TO_STATUS_CODE . each do | status , code |
get :head_with_symbolic_status , :status = > status . to_s
assert_equal code , @response . response_code
2006-11-07 21:45:10 +00:00
assert_response status
2006-09-28 19:13:55 +00:00
end
end
def test_head_with_integer_status
ActionController :: StatusCodes :: STATUS_CODES . each do | code , message |
get :head_with_integer_status , :status = > code . to_s
assert_equal message , @response . message
end
end
2006-09-28 19:32:40 +00:00
def test_head_with_string_status
2006-09-28 19:13:55 +00:00
get :head_with_string_status , :status = > " 404 Eat Dirt "
assert_equal 404 , @response . response_code
assert_equal " Eat Dirt " , @response . message
2006-11-07 21:45:10 +00:00
assert_response :not_found
2006-09-28 19:13:55 +00:00
end
2006-09-28 19:32:40 +00:00
def test_head_with_status_code_first
get :head_with_status_code_first
assert_equal 403 , @response . response_code
assert_equal " Forbidden " , @response . message
assert_equal " something " , @response . headers [ " X-Custom-Header " ]
2006-11-07 21:45:10 +00:00
assert_response :forbidden
2006-09-28 19:32:40 +00:00
end
2007-04-24 18:29:37 +00:00
def test_rendering_with_location_should_set_header
get :render_with_location
assert_equal " http://example.com " , @response . headers [ " Location " ]
end
def test_rendering_xml_should_call_to_xml_if_possible
get :render_with_to_xml
assert_equal " <i-am-xml/> " , @response . body
end
2007-05-17 20:48:47 +00:00
def test_rendering_with_object_location_should_set_header_with_url_for
ActionController :: Routing :: Routes . draw do | map |
map . resources :customers
map . connect ':controller/:action/:id'
end
2007-05-18 05:25:17 +00:00
2007-05-17 20:48:47 +00:00
get :render_with_object_location
2007-05-18 05:25:17 +00:00
assert_equal " http://www.nextangle.com/customers/1 " , @response . headers [ " Location " ]
2007-05-17 20:48:47 +00:00
end
2007-08-02 20:10:03 +00:00
def test_render_call_to_partial_with_layout
get :render_call_to_partial_with_layout
assert_equal " Before (David) \n Inside from partial (David) \n After " , @response . body
end
2008-01-03 15:28:36 +00:00
def test_render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
assert_equal " Before (Anthony) \n Inside from partial (Anthony) \n After \n Before (David) \n Inside from partial (David) \n After \n Before (Ramm) \n Inside from partial (Ramm) \n After " , @response . body
end
2007-08-02 20:10:03 +00:00
def test_using_layout_around_block
2008-01-03 15:28:36 +00:00
get :render_using_layout_around_block
2007-08-02 20:10:03 +00:00
assert_equal " Before (David) \n Inside from block \n After " , @response . body
end
2008-01-03 15:28:36 +00:00
def test_using_layout_around_block_in_main_layout_and_within_content_for_layout
get :render_using_layout_around_block_in_main_layout_and_within_content_for_layout
assert_equal " Before (Anthony) \n Inside from first block in layout \n After \n Before (David) \n Inside from block \n After \n Before (Ramm) \n Inside from second block in layout \n After \n " , @response . body
end
2007-10-25 21:32:01 +00:00
end