2005-05-22 03:43:05 -04:00
|
|
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
|
|
|
|
2005-07-04 19:09:58 -04:00
|
|
|
silence_warnings { Customer = Struct.new("Customer", :name) }
|
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
|
|
|
|
|
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
|
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
|
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'
|
|
|
|
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.rhtml')
|
|
|
|
render :file => path
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_file_with_locals
|
|
|
|
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.rhtml')
|
|
|
|
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
|
2006-03-15 21:51:19 -05:00
|
|
|
|
|
|
|
def render_file_not_using_full_path_with_relative_path
|
|
|
|
@secret = 'in the sauce'
|
|
|
|
render :file => 'test/../test/render_file_with_ivar', :use_full_path => true
|
|
|
|
end
|
2005-05-22 03:43:05 -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'
|
|
|
|
render :file => 'test/dot.directory/render_file_with_ivar', :use_full_path => true
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2005-05-22 03:43:05 -04:00
|
|
|
|
2005-05-22 12:59:55 -04:00
|
|
|
def rendering_nothing_on_layout
|
|
|
|
render :nothing => true
|
|
|
|
end
|
|
|
|
|
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
|
2005-07-27 05:11:00 -04:00
|
|
|
|
|
|
|
def partial_with_locals
|
|
|
|
render :partial => "customer", :locals => { :customer => Customer.new("david") }
|
|
|
|
end
|
|
|
|
|
|
|
|
def partial_collection
|
|
|
|
render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ]
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
2005-09-01 17:43:38 -04:00
|
|
|
def empty_partial_collection
|
|
|
|
render :partial => "customer", :collection => []
|
|
|
|
end
|
2005-09-09 03:27:44 -04:00
|
|
|
|
|
|
|
def partial_with_hash_object
|
|
|
|
render :partial => "hash_object", :object => {:first_name => "Sam"}
|
|
|
|
end
|
2005-09-01 17:43:38 -04:00
|
|
|
|
2005-10-10 16:35:13 -04:00
|
|
|
def partial_with_implicit_local_assignment
|
|
|
|
@customer = Customer.new("Marcel")
|
|
|
|
render :partial => "customer"
|
|
|
|
end
|
|
|
|
|
2005-05-22 03:43:05 -04:00
|
|
|
def hello_in_a_string
|
|
|
|
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
2005-05-22 04:58:43 -04:00
|
|
|
render :text => "How's there? #{render_to_string("test/list")}"
|
2005-05-22 03:43:05 -04:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
render "test/hello_world"
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
render :action => "hello_world.rxml"
|
|
|
|
end
|
|
|
|
|
|
|
|
def hello_world_from_rxml_using_template
|
|
|
|
render :template => "test/hello_world.rxml"
|
|
|
|
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
|
|
|
|
|
2006-03-08 00:21:27 -05:00
|
|
|
helper NewRenderTestHelper
|
|
|
|
helper do
|
|
|
|
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
|
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
|
|
|
|
|
2005-05-22 03:43:05 -04:00
|
|
|
def rescue_action(e) raise end
|
|
|
|
|
|
|
|
private
|
|
|
|
def determine_layout
|
|
|
|
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"
|
2005-12-17 01:38:06 -05: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"
|
2005-05-22 03:43:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-05-30 05:00:46 -04:00
|
|
|
NewRenderTestController.template_root = File.dirname(__FILE__) + "/../fixtures/"
|
2005-05-22 03:43:05 -04:00
|
|
|
Fun::GamesController.template_root = File.dirname(__FILE__) + "/../fixtures/"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
get :render_file_not_using_full_path
|
|
|
|
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_relative_path
|
|
|
|
get :render_file_not_using_full_path_with_relative_path
|
|
|
|
assert_equal "The secret is in the sauce\n", @response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
2005-07-23 05:00:05 -04:00
|
|
|
view_internals_old_value = ActionController::Base.view_controller_internals
|
|
|
|
|
2005-05-22 03:43:05 -04:00
|
|
|
ActionController::Base.view_controller_internals = false
|
2005-07-23 05:00:05 -04:00
|
|
|
ActionController::Base.protected_variables_cache = nil
|
2005-05-22 03:43:05 -04:00
|
|
|
|
2005-05-22 13:12:29 -04:00
|
|
|
get :hello_world
|
2006-09-29 03:34:02 -04:00
|
|
|
assert !assigns.include?('request'), 'request should not be in assigns'
|
2005-05-22 03:43:05 -04:00
|
|
|
|
|
|
|
ActionController::Base.view_controller_internals = true
|
2005-07-23 05:00:05 -04:00
|
|
|
ActionController::Base.protected_variables_cache = nil
|
2005-05-22 03:43:05 -04:00
|
|
|
|
2005-05-22 13:12:29 -04:00
|
|
|
get :hello_world
|
2006-09-29 03:34:02 -04:00
|
|
|
assert assigns.include?('request'), 'request should be in assigns'
|
|
|
|
assert_deprecated 'request' do
|
|
|
|
assert_kind_of ActionController::AbstractRequest, assigns['request']
|
|
|
|
end
|
|
|
|
assert_not_deprecated do
|
|
|
|
assert_kind_of ActionController::AbstractRequest, @response.template.request
|
|
|
|
assert_kind_of ActionController::AbstractRequest, assigns['_request']
|
|
|
|
end
|
2005-07-23 05:00:05 -04:00
|
|
|
|
2006-09-29 03:34:02 -04:00
|
|
|
ensure
|
2005-07-23 05:00:05 -04:00
|
|
|
ActionController::Base.view_controller_internals = view_internals_old_value
|
|
|
|
ActionController::Base.protected_variables_cache = nil
|
2005-05-22 03:43:05 -04:00
|
|
|
end
|
2006-09-29 03:34:02 -04:00
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2006-09-04 01:09:18 -04:00
|
|
|
assert_deprecated(/render/) { 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
|
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\nSecond: Stephan\nThird: David\nFourth: David\nFifth: ", @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>\nAction 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
|
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
|
|
|
|
|
|
|
|
def test_partial_collection
|
|
|
|
get :partial_collection
|
|
|
|
assert_equal "Hello: davidHello: mary", @response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2005-07-31 08:16:21 -04:00
|
|
|
|
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
|
|
|
|
assert_equal "Sam", @response.body
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
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
|
2005-09-01 17:51:27 -04:00
|
|
|
|
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
|
2006-09-17 12:20:32 -04:00
|
|
|
assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type']
|
2006-01-20 17:04:07 -05:00
|
|
|
assert_equal 2, @response.body.split($/).length
|
|
|
|
end
|
|
|
|
|
2006-01-29 23:49:17 -05:00
|
|
|
def test_update_page_with_instance_variables
|
|
|
|
get :update_page_with_instance_variables
|
|
|
|
assert_template nil
|
2006-09-17 12:20:32 -04:00
|
|
|
assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type']
|
2006-01-29 23:49:17 -05:00
|
|
|
assert_match /balance/, @response.body
|
|
|
|
assert_match /\$37/, @response.body
|
|
|
|
end
|
|
|
|
|
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\nGreat 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"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_head_with_custom_header
|
|
|
|
get :head_with_custom_header
|
|
|
|
assert @response.body.blank?
|
|
|
|
assert_equal "something", @response.headers["X-Custom-Header"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_head_with_symbolic_status
|
|
|
|
get :head_with_symbolic_status, :status => "ok"
|
|
|
|
assert_equal "200 OK", @response.headers["Status"]
|
|
|
|
|
|
|
|
get :head_with_symbolic_status, :status => "not_found"
|
|
|
|
assert_equal "404 Not Found", @response.headers["Status"]
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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"]
|
|
|
|
end
|
2006-03-15 21:51:19 -05:00
|
|
|
end
|