2008-01-05 08:32:06 -05:00
require 'abstract_unit'
require 'controller/fake_models'
2007-05-17 16:48:47 -04:00
class CustomersController < ActionController :: Base
end
2005-05-22 03:43:05 -04:00
module Fun
class GamesController < ActionController :: Base
def hello_world
end
end
end
2006-03-08 00:21:27 -05:00
module NewRenderTestHelper
def rjs_helper_method_from_module
page . visual_effect :highlight
end
end
2008-01-15 21:01:57 -05:00
class LabellingFormBuilder < ActionView :: Helpers :: FormBuilder
end
2005-05-30 05:00:46 -04:00
class NewRenderTestController < ActionController :: Base
2005-05-22 03:43:05 -04:00
layout :determine_layout
2005-05-30 05:00:46 -04:00
def self . controller_name ; " test " ; end
def self . controller_path ; " test " ; end
2005-05-22 03:43:05 -04:00
def hello_world
end
def render_hello_world
2005-05-22 04:58:43 -04:00
render :template = > " test/hello_world "
2005-05-22 03:43:05 -04:00
end
def render_hello_world_from_variable
@person = " david "
2005-05-22 04:58:43 -04:00
render :text = > " hello #{ @person } "
2005-05-22 03:43:05 -04:00
end
def render_action_hello_world
2005-05-22 04:58:43 -04:00
render :action = > " hello_world "
2005-05-22 03:43:05 -04:00
end
2006-02-17 13:32:21 -05:00
def render_action_hello_world_as_symbol
render :action = > :hello_world
end
2008-06-25 16:24:12 -04:00
2005-05-22 03:43:05 -04:00
def render_text_hello_world
2005-05-22 04:58:43 -04:00
render :text = > " hello world "
2005-05-22 03:43:05 -04:00
end
2008-06-25 16:24:12 -04:00
2005-10-28 03:33:54 -04:00
def render_text_hello_world_with_layout
@variable_for_layout = " , I'm here! "
render :text = > " hello world " , :layout = > true
end
2005-05-22 03:43:05 -04:00
2005-12-20 00:32:39 -05:00
def hello_world_with_layout_false
render :layout = > false
end
2005-05-22 03:43:05 -04:00
def render_custom_code
2005-05-22 04:58:43 -04:00
render :text = > " hello world " , :status = > " 404 Moved "
2005-05-22 03:43:05 -04:00
end
2005-11-22 03:37:04 -05:00
def render_file_with_instance_variables
@secret = 'in the sauce'
2007-02-20 17:09:12 -05:00
path = File . join ( File . dirname ( __FILE__ ) , '../fixtures/test/render_file_with_ivar.erb' )
2005-11-22 03:37:04 -05:00
render :file = > path
end
2008-06-25 16:24:12 -04:00
2008-06-05 18:27:27 -04:00
def render_file_from_template
@secret = 'in the sauce'
@path = File . expand_path ( File . join ( File . dirname ( __FILE__ ) , '../fixtures/test/render_file_with_ivar.erb' ) )
end
2005-11-22 03:37:04 -05:00
def render_file_with_locals
2007-02-20 17:09:12 -05:00
path = File . join ( File . dirname ( __FILE__ ) , '../fixtures/test/render_file_with_locals.erb' )
2008-06-25 16:24:12 -04:00
render :file = > path , :locals = > { :secret = > 'in the sauce' }
2005-11-22 03:37:04 -05:00
end
def render_file_not_using_full_path
@secret = 'in the sauce'
2008-07-02 22:38:58 -04:00
render :file = > 'test/render_file_with_ivar'
2005-11-22 03:37:04 -05:00
end
2008-06-25 16:24:12 -04:00
2006-03-15 21:51:19 -05:00
def render_file_not_using_full_path_with_dot_in_path
@secret = 'in the sauce'
2008-07-02 22:38:58 -04:00
render :file = > 'test/dot.directory/render_file_with_ivar'
2006-03-15 21:51:19 -05:00
end
2005-05-22 03:43:05 -04:00
def render_xml_hello
@name = " David "
2005-05-22 04:58:43 -04:00
render :template = > " test/hello "
2005-05-22 03:43:05 -04:00
end
def greeting
# let's just rely on the template
end
def layout_test
2005-05-22 04:58:43 -04:00
render :action = > " hello_world "
2005-05-22 03:43:05 -04:00
end
def layout_test_with_different_layout
2005-05-22 04:58:43 -04:00
render :action = > " hello_world " , :layout = > " standard "
2005-05-22 03:43:05 -04:00
end
2008-06-25 16:24:12 -04:00
2005-05-22 03:43:05 -04:00
def rendering_without_layout
2005-05-22 04:58:43 -04:00
render :action = > " hello_world " , :layout = > false
2005-05-22 03:43:05 -04:00
end
2005-08-05 16:51:03 -04:00
def layout_overriding_layout
render :action = > " hello_world " , :layout = > " standard "
end
2008-06-25 16:24:12 -04:00
2005-05-22 12:59:55 -04:00
def rendering_nothing_on_layout
render :nothing = > true
end
2008-06-25 16:24:12 -04:00
2005-05-22 03:43:05 -04:00
def builder_layout_test
2005-05-22 04:58:43 -04:00
render :action = > " hello "
2005-05-22 03:43:05 -04:00
end
def partials_list
2005-07-05 14:21:26 -04:00
@test_unchanged = 'hello'
2005-05-22 03:43:05 -04:00
@customers = [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
2005-05-22 04:58:43 -04:00
render :action = > " list "
2005-05-22 03:43:05 -04:00
end
def partial_only
2005-05-30 03:20:37 -04:00
render :partial = > true
2005-05-22 03:43:05 -04:00
end
2005-05-30 03:51:02 -04:00
def partial_only_with_layout
2005-06-01 09:39:58 -04:00
render :partial = > " partial_only " , :layout = > true
2005-05-30 03:51:02 -04:00
end
2008-06-25 16:24:12 -04:00
2005-07-27 05:11:00 -04:00
def partial_with_locals
2008-06-25 16:24:12 -04:00
render :partial = > " customer " , :locals = > { :customer = > Customer . new ( " david " ) }
2005-07-27 05:11:00 -04:00
end
2008-01-15 21:01:57 -05:00
def partial_with_form_builder
2008-02-02 01:16:04 -05:00
render :partial = > ActionView :: Helpers :: FormBuilder . new ( :post , nil , @template , { } , Proc . new { } )
2008-01-15 21:01:57 -05:00
end
2008-02-02 01:16:04 -05:00
2008-01-15 21:01:57 -05:00
def partial_with_form_builder_subclass
2008-02-02 01:16:04 -05:00
render :partial = > LabellingFormBuilder . new ( :post , nil , @template , { } , Proc . new { } )
2008-01-15 21:01:57 -05:00
end
2005-07-27 05:11:00 -04:00
def partial_collection
render :partial = > " customer " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
end
2008-06-25 16:24:12 -04:00
2008-07-02 11:38:50 -04:00
def partial_collection_with_as
render :partial = > " customer_with_var " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ] , :as = > :customer
end
2008-03-02 23:01:35 -05:00
def partial_collection_with_spacer
render :partial = > " customer " , :spacer_template = > " partial_only " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
end
2008-06-25 16:24:12 -04:00
2008-03-02 23:01:35 -05:00
def partial_collection_with_counter
render :partial = > " customer_counter " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
end
2005-07-27 05:11:00 -04:00
def partial_collection_with_locals
2005-07-27 08:06:19 -04:00
render :partial = > " customer_greeting " , :collection = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ] , :locals = > { :greeting = > " Bonjour " }
2005-07-27 05:11:00 -04:00
end
2005-05-30 03:51:02 -04:00
2008-02-08 17:04:06 -05:00
def partial_collection_shorthand_with_locals
render :partial = > [ Customer . new ( " david " ) , Customer . new ( " mary " ) ] , :locals = > { :greeting = > " Bonjour " }
end
2008-03-31 20:50:09 -04:00
def partial_collection_shorthand_with_different_types_of_records
render :partial = > [
BadCustomer . new ( " mark " ) ,
GoodCustomer . new ( " craig " ) ,
BadCustomer . new ( " john " ) ,
GoodCustomer . new ( " zach " ) ,
GoodCustomer . new ( " brandon " ) ,
BadCustomer . new ( " dan " ) ] ,
:locals = > { :greeting = > " Bonjour " }
end
def partial_collection_shorthand_with_different_types_of_records_with_counter
partial_collection_shorthand_with_different_types_of_records
end
2005-09-01 17:43:38 -04:00
def empty_partial_collection
render :partial = > " customer " , :collection = > [ ]
end
2008-06-25 16:24:12 -04:00
2005-09-09 03:27:44 -04:00
def partial_with_hash_object
render :partial = > " hash_object " , :object = > { :first_name = > " Sam " }
end
2008-06-25 16:24:12 -04:00
2007-09-02 20:18:30 -04:00
def partial_hash_collection
render :partial = > " hash_object " , :collection = > [ { :first_name = > " Pratik " } , { :first_name = > " Amy " } ]
end
2008-06-25 16:24:12 -04:00
2007-09-02 20:18:30 -04:00
def partial_hash_collection_with_locals
render :partial = > " hash_greeting " , :collection = > [ { :first_name = > " Pratik " } , { :first_name = > " Amy " } ] , :locals = > { :greeting = > " Hola " }
end
2008-06-25 16:24:12 -04:00
2005-10-10 16:35:13 -04:00
def partial_with_implicit_local_assignment
@customer = Customer . new ( " Marcel " )
render :partial = > " customer "
end
2008-06-25 16:24:12 -04:00
2007-05-24 12:42:10 -04:00
def missing_partial
render :partial = > 'thisFileIsntHere'
end
2008-06-25 16:24:12 -04:00
2005-05-22 03:43:05 -04:00
def hello_in_a_string
@customers = [ Customer . new ( " david " ) , Customer . new ( " mary " ) ]
2007-09-02 20:18:30 -04:00
render :text = > " How's there? " << render_to_string ( :template = > " test/list " )
2005-05-22 03:43:05 -04:00
end
2008-06-25 16:24:12 -04:00
2006-11-20 06:03:21 -05: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 01:10:06 -05:00
2008-06-10 18:53:30 -04:00
def render_to_string_with_partial
2007-01-12 01:10:06 -05:00
@partial_only = render_to_string :partial = > " partial_only "
2008-06-25 16:24:12 -04:00
@partial_with_locals = render_to_string :partial = > " customer " , :locals = > { :customer = > Customer . new ( " david " ) }
render :action = > " test/hello_world "
end
2006-11-20 06:03:21 -05:00
def render_to_string_with_exception
2008-07-02 22:38:58 -04:00
render_to_string :file = > " exception that will not be caught - this will certainly not work "
2006-11-20 06:03:21 -05:00
end
2008-06-25 16:24:12 -04:00
2006-11-20 06:03:21 -05:00
def render_to_string_with_caught_exception
@before = " i'm before the render "
begin
2008-07-02 22:38:58 -04:00
render_to_string :file = > " exception that will be caught- hope my future instance vars still work! "
2006-11-20 06:03:21 -05:00
rescue
end
@after = " i'm after the render "
render :action = > " test/hello_world "
end
2006-09-04 01:09:18 -04:00
2005-05-22 03:43:05 -04:00
def accessing_params_in_template
2005-05-22 04:58:43 -04:00
render :inline = > " Hello: <%= params[:name] %> "
2005-05-22 03:43:05 -04:00
end
2008-04-21 06:39:46 -04:00
def accessing_request_in_template
render :inline = > " Hello: <%= request.host %> "
end
def accessing_logger_in_template
render :inline = > " <%= logger.class %> "
end
2008-06-10 18:53:30 -04:00
2008-05-06 07:02:24 -04:00
def accessing_action_name_in_template
render :inline = > " <%= action_name %> "
end
2008-04-21 06:39:46 -04:00
2008-06-10 18:53:30 -04:00
def accessing_controller_name_in_template
render :inline = > " <%= controller_name %> "
end
2005-05-30 05:12:12 -04:00
def accessing_params_in_template_with_layout
2005-07-23 05:00:05 -04:00
render :layout = > nil , :inline = > " Hello: <%= params[:name] %> "
2005-05-30 05:12:12 -04:00
end
2005-06-15 09:20:17 -04:00
def render_with_explicit_template
2007-09-02 20:18:30 -04:00
render :template = > " test/hello_world "
2005-06-15 09:20:17 -04:00
end
2008-07-01 23:26:34 -04:00
def render_with_explicit_template_with_locals
render :template = > " test/render_file_with_locals " , :locals = > { :secret = > 'area51' }
end
2005-07-09 11:31:06 -04: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
2008-06-25 16:24:12 -04:00
2006-11-20 06:03:21 -05: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 11:31:06 -04:00
2005-07-21 03:14:35 -04:00
def rendering_with_conflicting_local_vars
@name = " David "
2005-08-26 18:37:36 -04:00
def @template . name ( ) nil end
2005-07-21 03:14:35 -04:00
render :action = > " potential_conflicts "
end
2006-03-11 22:39:58 -05:00
def hello_world_from_rxml_using_action
2007-12-10 15:41:59 -05:00
render :action = > " hello_world_from_rxml.builder "
2006-03-11 22:39:58 -05:00
end
def hello_world_from_rxml_using_template
2007-12-10 15:41:59 -05:00
render :template = > " test/hello_world_from_rxml.builder "
2006-03-11 22:39:58 -05:00
end
2006-09-28 15:13:55 -04: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 15:32:40 -04:00
def head_with_status_code_first
head :forbidden , :x_custom_header = > " something "
end
2007-04-24 14:29:37 -04:00
def render_with_location
render :xml = > " <hello/> " , :location = > " http://example.com " , :status = > 201
end
2008-06-25 16:24:12 -04:00
2007-05-17 16:48:47 -04: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 14:29:37 -04:00
def render_with_to_xml
to_xmlable = Class . new do
def to_xml
" <i-am-xml/> "
end
end . new
2008-06-25 16:24:12 -04:00
2007-04-24 14:29:37 -04:00
render :xml = > to_xmlable
end
2006-03-08 00:21:27 -05:00
helper NewRenderTestHelper
2008-06-25 16:24:12 -04:00
helper do
2006-03-08 00:21:27 -05:00
def rjs_helper_method ( value )
page . visual_effect :highlight , value
end
end
2006-03-05 11:35:27 -05:00
def enum_rjs_test
render :update do | page |
page . select ( '.product' ) . each do | value |
2006-03-08 00:21:27 -05:00
page . rjs_helper_method_from_module
page . rjs_helper_method ( value )
2006-03-05 11:35:27 -05:00
page . sortable ( value , :url = > { :action = > " order " } )
page . draggable ( value )
end
end
end
2005-11-17 16:28:59 -05: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 17:04:07 -05:00
def update_page
render :update do | page |
page . replace_html 'balance' , '$37,000,000.00'
page . visual_effect :highlight , 'balance'
end
end
2008-06-25 16:24:12 -04:00
2006-01-29 23:49:17 -05: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 17:04:07 -05:00
2005-07-23 04:43:01 -04:00
def action_talk_to_layout
# Action template sets variable that's picked up by layout
end
2005-07-31 08:16:21 -04:00
def render_text_with_assigns
@hello = " world "
render :text = > " foo "
end
2005-09-01 17:51:27 -04:00
def yield_content_for
render :action = > " content_for " , :layout = > " yield "
end
2006-09-17 12:20:32 -04:00
def render_content_type_from_body
response . content_type = Mime :: RSS
render :text = > " hello world! "
end
2007-08-02 16:10:03 -04:00
def render_call_to_partial_with_layout
render :action = > " calling_partial_with_layout "
end
2008-01-03 10:28:36 -05: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 16:10:03 -04:00
def render_using_layout_around_block
render :action = > " using_layout_around_block "
end
2008-01-03 10:28:36 -05:00
def render_using_layout_around_block_in_main_layout_and_within_content_for_layout
render :action = > " using_layout_around_block "
end
2008-06-25 16:24:12 -04:00
2005-05-22 03:43:05 -04:00
def rescue_action ( e ) raise end
2008-06-25 16:24:12 -04:00
2005-05-22 03:43:05 -04:00
private
def determine_layout
2008-06-25 16:24:12 -04:00
case action_name
2005-06-01 09:39:58 -04:00
when " hello_world " , " layout_test " , " rendering_without_layout " ,
2005-05-30 03:51:02 -04:00
" rendering_nothing_on_layout " , " render_text_hello_world " ,
2005-10-28 03:33:54 -04:00
" render_text_hello_world_with_layout " ,
2005-12-20 00:32:39 -05:00
" hello_world_with_layout_false " ,
2005-05-30 05:12:12 -04:00
" partial_only " , " partial_only_with_layout " ,
" accessing_params_in_template " ,
2005-06-15 09:20:17 -04:00
" accessing_params_in_template_with_layout " ,
2005-11-18 03:32:17 -05:00
" render_with_explicit_template " ,
2005-12-17 01:38:06 -05:00
" render_js_with_explicit_template " ,
" render_js_with_explicit_action_template " ,
2006-01-29 23:49:17 -05:00
" delete_with_js " , " update_page " , " update_page_with_instance_variables "
2008-06-25 16:24:12 -04:00
2005-05-22 03:43:05 -04:00
" layouts/standard "
when " builder_layout_test "
" layouts/builder "
2005-08-05 16:51:03 -04:00
when " action_talk_to_layout " , " layout_overriding_layout "
2005-07-23 04:43:01 -04:00
" layouts/talk_from_action "
2008-01-03 10:28:36 -05: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 03:43:05 -04:00
end
end
end
2005-05-30 05:00:46 -04:00
class NewRenderTest < Test :: Unit :: TestCase
def setup
@controller = NewRenderTestController . new
2005-05-22 03:43:05 -04:00
2005-05-30 05:00:46 -04: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 03:43:05 -04:00
@request = ActionController :: TestRequest . new
@response = ActionController :: TestResponse . new
@request . host = " www.nextangle.com "
end
def test_simple_show
2005-05-22 13:12:29 -04:00
get :hello_world
assert_response :success
assert_template " test/hello_world "
2005-06-01 09:39:58 -04:00
assert_equal " <html>Hello world!</html> " , @response . body
2005-05-22 03:43:05 -04:00
end
2008-07-07 14:57:53 -04:00
def test_renders_default_template_for_missing_action
get :'hyphen-ated'
assert_template 'test/hyphen-ated'
end
2005-05-22 03:43:05 -04:00
def test_do_with_render
2005-05-22 13:12:29 -04:00
get :render_hello_world
assert_template " test/hello_world "
2005-05-22 03:43:05 -04:00
end
def test_do_with_render_from_variable
2005-05-22 13:12:29 -04:00
get :render_hello_world_from_variable
assert_equal " hello david " , @response . body
2005-05-22 03:43:05 -04:00
end
def test_do_with_render_action
2005-05-22 13:12:29 -04:00
get :render_action_hello_world
assert_template " test/hello_world "
2005-05-22 03:43:05 -04:00
end
2006-02-17 13:32:21 -05: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 03:43:05 -04:00
def test_do_with_render_text
2005-05-22 13:12:29 -04:00
get :render_text_hello_world
assert_equal " hello world " , @response . body
2005-05-22 03:43:05 -04:00
end
2005-10-28 03:33:54 -04: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 00:32:39 -05: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 03:43:05 -04:00
def test_do_with_render_custom_code
2005-05-22 13:12:29 -04:00
get :render_custom_code
assert_response :missing
2005-05-22 03:43:05 -04:00
end
2005-11-22 03:37:04 -05: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
2008-06-25 16:24:12 -04:00
get :render_file_not_using_full_path
2005-11-22 03:37:04 -05:00
assert_equal " The secret is in the sauce \n " , @response . body
end
2006-03-15 21:51:19 -05: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 03:37:04 -05:00
def test_render_file_with_locals
get :render_file_with_locals
assert_equal " The secret is in the sauce \n " , @response . body
end
2008-06-25 16:24:12 -04:00
2008-06-05 18:27:27 -04:00
def test_render_file_from_template
get :render_file_from_template
assert_equal " The secret is in the sauce \n " , @response . body
end
2005-11-22 03:37:04 -05:00
2005-05-22 03:43:05 -04:00
def test_attempt_to_access_object_method
2005-05-22 13:12:29 -04:00
assert_raises ( ActionController :: UnknownAction , " No action responded to [clone] " ) { get :clone }
2005-05-22 03:43:05 -04:00
end
def test_private_methods
2005-05-22 13:12:29 -04:00
assert_raises ( ActionController :: UnknownAction , " No action responded to [determine_layout] " ) { get :determine_layout }
2005-05-22 03:43:05 -04:00
end
def test_access_to_request_in_view
2008-04-21 06:39:46 -04:00
get :accessing_request_in_template
assert_equal " Hello: www.nextangle.com " , @response . body
end
def test_access_to_logger_in_view
get :accessing_logger_in_template
assert_equal " Logger " , @response . body
2005-05-22 03:43:05 -04:00
end
2008-06-10 18:53:30 -04:00
2008-05-06 07:02:24 -04:00
def test_access_to_action_name_in_view
get :accessing_action_name_in_template
assert_equal " accessing_action_name_in_template " , @response . body
end
2006-09-29 03:34:02 -04:00
2008-06-10 18:53:30 -04:00
def test_access_to_controller_name_in_view
get :accessing_controller_name_in_template
assert_equal " test " , @response . body # name is explicitly set to 'test' inside the controller.
end
2005-05-22 03:43:05 -04:00
def test_render_xml
2005-05-22 13:12:29 -04: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 03:43:05 -04:00
end
2006-03-05 01:42:58 -05:00
def test_enum_rjs_test
get :enum_rjs_test
assert_equal <<-EOS.strip, @response.body
2006-03-12 21:11:59 -05:00
$$ ( " .product " ) . each ( function ( value , index ) {
2006-03-05 01:42:58 -05: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 03:43:05 -04:00
def test_render_xml_with_default
2005-05-22 13:12:29 -04:00
get :greeting
assert_equal " <p>This is grand!</p> \n " , @response . body
2005-05-22 03:43:05 -04:00
end
2008-02-29 13:09:23 -05:00
def test_render_with_default_from_accept_header
2008-06-27 14:24:21 -04:00
xhr :get , :greeting
2008-02-29 13:09:23 -05:00
assert_equal " $( \" body \" ).visualEffect( \" highlight \" ); " , @response . body
end
2005-11-17 16:28:59 -05:00
def test_render_rjs_with_default
get :delete_with_js
2006-09-20 16:14:12 -04:00
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});! , @response . body
2005-11-17 16:28:59 -05:00
end
def test_render_rjs_template_explicitly
get :render_js_with_explicit_template
2006-09-20 16:14:12 -04:00
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});! , @response . body
2005-11-17 16:28:59 -05:00
end
def test_rendering_rjs_action_explicitly
get :render_js_with_explicit_action_template
2006-09-20 16:14:12 -04:00
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});! , @response . body
2005-11-17 16:28:59 -05:00
end
2005-05-22 03:43:05 -04:00
def test_layout_rendering
2005-05-22 13:12:29 -04:00
get :layout_test
assert_equal " <html>Hello world!</html> " , @response . body
2005-05-22 03:43:05 -04:00
end
def test_layout_test_with_different_layout
2005-05-22 13:12:29 -04:00
get :layout_test_with_different_layout
assert_equal " <html>Hello world!</html> " , @response . body
2005-05-22 03:43:05 -04:00
end
def test_rendering_without_layout
2005-05-22 13:12:29 -04:00
get :rendering_without_layout
assert_equal " Hello world! " , @response . body
2005-05-22 03:43:05 -04:00
end
2005-08-05 16:51:03 -04:00
def test_layout_overriding_layout
get :layout_overriding_layout
assert_no_match %r{ <title> } , @response . body
end
2005-05-22 12:59:55 -04:00
def test_rendering_nothing_on_layout
2005-05-22 13:12:29 -04:00
get :rendering_nothing_on_layout
2005-07-14 03:19:26 -04:00
assert_equal " " , @response . body
2005-05-22 12:59:55 -04:00
end
2005-05-22 03:43:05 -04:00
def test_render_xml_with_layouts
2005-05-22 13:12:29 -04: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 03:43:05 -04:00
end
def test_partial_only
2005-05-22 13:12:29 -04:00
get :partial_only
assert_equal " only partial " , @response . body
2005-05-22 03:43:05 -04:00
end
2005-05-30 03:51:02 -04:00
def test_partial_only_with_layout
get :partial_only_with_layout
assert_equal " <html>only partial</html> " , @response . body
end
2005-05-22 03:43:05 -04:00
def test_render_to_string
2006-09-04 01:09:18 -04:00
assert_not_deprecated { get :hello_in_a_string }
2005-07-05 14:21:26 -04:00
assert_equal " How's there? goodbyeHello: davidHello: marygoodbye \n " , @response . body
2005-05-22 03:43:05 -04:00
end
2008-06-25 16:24:12 -04:00
2006-11-20 06:03:21 -05: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 01:10:06 -05: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 )
2008-06-25 16:24:12 -04:00
end
2007-01-12 01:10:06 -05:00
2006-11-20 06:03:21 -05:00
def test_bad_render_to_string_still_throws_exception
2008-04-19 13:52:14 -04:00
assert_raises ( ActionView :: MissingTemplate ) { get :render_to_string_with_exception }
2006-11-20 06:03:21 -05:00
end
2008-06-25 16:24:12 -04:00
2006-11-20 06:03:21 -05:00
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 03:43:05 -04:00
def test_nested_rendering
2005-05-22 13:12:29 -04:00
get :hello_world
2005-05-22 03:43:05 -04:00
assert_equal " Living in a nested world " , Fun :: GamesController . process ( @request , @response ) . body
end
def test_accessing_params_in_template
2005-05-22 13:12:29 -04:00
get :accessing_params_in_template , :name = > " David "
assert_equal " Hello: David " , @response . body
2005-05-22 03:43:05 -04:00
end
2005-05-30 05:12:12 -04: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 09:20:17 -04:00
def test_render_with_explicit_template
2007-09-02 20:18:30 -04:00
get :render_with_explicit_template
2005-06-15 09:20:17 -04:00
assert_response :success
end
2005-07-09 11:31:06 -04: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
2008-06-25 16:24:12 -04:00
2006-11-20 06:03:21 -05: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 03:14:35 -04: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 04:43:01 -04: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 12:45:39 -04:00
def test_partials_list
get :partials_list
assert_equal " goodbyeHello: davidHello: marygoodbye \n " , @response . body
end
2008-06-25 16:24:12 -04:00
2005-07-27 05:11:00 -04:00
def test_partial_with_locals
get :partial_with_locals
2005-07-27 08:24:14 -04:00
assert_equal " Hello: david " , @response . body
2005-07-27 05:11:00 -04:00
end
2008-01-15 21:01:57 -05: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 05:11:00 -04:00
def test_partial_collection
get :partial_collection
assert_equal " Hello: davidHello: mary " , @response . body
end
2008-06-25 16:24:12 -04:00
2008-07-02 11:38:50 -04:00
def test_partial_collection_with_as
get :partial_collection_with_as
assert_equal " david david davidmary mary mary " , @response . body
end
2008-03-02 23:01:35 -05:00
def test_partial_collection_with_counter
get :partial_collection_with_counter
2008-06-05 15:48:42 -04:00
assert_equal " david0mary1 " , @response . body
2008-03-02 23:01:35 -05:00
end
2008-06-25 16:24:12 -04:00
2005-07-27 05:11:00 -04:00
def test_partial_collection_with_locals
get :partial_collection_with_locals
2005-07-27 08:06:19 -04:00
assert_equal " Bonjour: davidBonjour: mary " , @response . body
2005-07-27 05:11:00 -04:00
end
2008-06-25 16:24:12 -04:00
2008-03-02 23:01:35 -05:00
def test_partial_collection_with_spacer
get :partial_collection_with_spacer
assert_equal " Hello: davidonly partialHello: mary " , @response . body
end
2005-07-31 08:16:21 -04:00
2008-02-08 17:04:06 -05:00
def test_partial_collection_shorthand_with_locals
get :partial_collection_shorthand_with_locals
assert_equal " Bonjour: davidBonjour: mary " , @response . body
end
2008-03-31 20:50:09 -04:00
def test_partial_collection_shorthand_with_different_types_of_records
get :partial_collection_shorthand_with_different_types_of_records
2008-06-05 15:48:42 -04:00
assert_equal " Bonjour bad customer: mark0Bonjour good customer: craig1Bonjour bad customer: john2Bonjour good customer: zach3Bonjour good customer: brandon4Bonjour bad customer: dan5 " , @response . body
2008-03-31 20:50:09 -04:00
end
2005-09-01 17:43:38 -04:00
def test_empty_partial_collection
get :empty_partial_collection
assert_equal " " , @response . body
end
2005-09-09 03:27:44 -04:00
def test_partial_with_hash_object
get :partial_with_hash_object
2007-10-25 17:32:01 -04:00
assert_equal " Sam \n maS \n " , @response . body
2005-09-09 03:27:44 -04:00
end
2008-06-25 16:24:12 -04:00
2007-09-02 20:18:30 -04:00
def test_hash_partial_collection
get :partial_hash_collection
2007-10-25 17:32:01 -04:00
assert_equal " Pratik \n kitarP \n Amy \n ymA \n " , @response . body
2007-09-02 20:18:30 -04:00
end
2008-06-25 16:24:12 -04:00
2007-09-02 20:18:30 -04:00
def test_partial_hash_collection_with_locals
get :partial_hash_collection_with_locals
assert_equal " Hola: PratikHola: Amy " , @response . body
end
2005-09-09 03:27:44 -04:00
2005-10-10 16:35:13 -04:00
def test_partial_with_implicit_local_assignment
get :partial_with_implicit_local_assignment
assert_equal " Hello: Marcel " , @response . body
end
2008-06-25 16:24:12 -04:00
2007-05-24 12:42:10 -04:00
def test_render_missing_partial_template
2008-04-19 13:52:14 -04:00
assert_raises ( ActionView :: MissingTemplate ) do
2007-05-24 12:42:10 -04:00
get :missing_partial
end
end
2008-06-25 16:24:12 -04:00
2005-07-31 08:16:21 -04:00
def test_render_text_with_assigns
get :render_text_with_assigns
assert_equal " world " , assigns [ " hello " ]
end
2008-06-25 16:24:12 -04:00
2008-07-01 23:26:34 -04:00
def test_template_with_locals
get :render_with_explicit_template_with_locals
assert_equal " The secret is area51 \n " , @response . body
end
2006-01-20 17:04:07 -05:00
def test_update_page
get :update_page
2006-01-23 11:29:37 -05:00
assert_template nil
2007-02-18 21:25:01 -05:00
assert_equal 'text/javascript; charset=utf-8' , @response . headers [ 'type' ]
2006-01-20 17:04:07 -05:00
assert_equal 2 , @response . body . split ( $/ ) . length
end
2008-06-25 16:24:12 -04:00
2006-01-29 23:49:17 -05:00
def test_update_page_with_instance_variables
get :update_page_with_instance_variables
assert_template nil
2007-02-18 21:25:01 -05:00
assert_equal 'text/javascript; charset=utf-8' , @response . headers [ 'type' ]
2006-01-29 23:49:17 -05:00
assert_match / balance / , @response . body
assert_match / \ $37 / , @response . body
end
2008-06-25 16:24:12 -04:00
2005-09-01 17:51:27 -04:00
def test_yield_content_for
2006-09-04 01:09:18 -04:00
assert_not_deprecated { get :yield_content_for }
2005-09-01 17:51:27 -04:00
assert_equal " <title>Putting stuff in the title!</title> \n \n Great stuff! \n " , @response . body
end
2006-03-11 22:39:58 -05: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 15:13:55 -04: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 16:45:10 -05:00
assert_response :ok
2006-09-28 15:13:55 -04: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 16:45:10 -05:00
assert_response :ok
2006-09-28 15:13:55 -04: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 16:45:10 -05:00
assert_response :ok
2006-09-28 15:13:55 -04:00
get :head_with_symbolic_status , :status = > " not_found "
assert_equal " 404 Not Found " , @response . headers [ " Status " ]
2006-11-07 16:45:10 -05:00
assert_response :not_found
2006-09-28 15:13:55 -04: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 16:45:10 -05:00
assert_response status
2006-09-28 15:13:55 -04: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 15:32:40 -04:00
def test_head_with_string_status
2006-09-28 15:13:55 -04: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 16:45:10 -05:00
assert_response :not_found
2006-09-28 15:13:55 -04:00
end
2006-09-28 15:32:40 -04: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 16:45:10 -05:00
assert_response :forbidden
2006-09-28 15:32:40 -04:00
end
2007-04-24 14:29:37 -04:00
def test_rendering_with_location_should_set_header
get :render_with_location
assert_equal " http://example.com " , @response . headers [ " Location " ]
end
2008-06-25 16:24:12 -04:00
2007-04-24 14:29:37 -04:00
def test_rendering_xml_should_call_to_xml_if_possible
get :render_with_to_xml
assert_equal " <i-am-xml/> " , @response . body
end
2008-06-25 16:24:12 -04:00
2007-05-17 16:48:47 -04: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 01:25:17 -04:00
2007-05-17 16:48:47 -04:00
get :render_with_object_location
2007-05-18 01:25:17 -04:00
assert_equal " http://www.nextangle.com/customers/1 " , @response . headers [ " Location " ]
2007-05-17 16:48:47 -04:00
end
2007-08-02 16:10:03 -04: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 10:28:36 -05: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 16:10:03 -04:00
def test_using_layout_around_block
2008-01-03 10:28:36 -05:00
get :render_using_layout_around_block
2007-08-02 16:10:03 -04:00
assert_equal " Before (David) \n Inside from block \n After " , @response . body
end
2008-01-03 10:28:36 -05: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 17:32:01 -04:00
end