2008-01-05 08:32:06 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'controller/fake_models'
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
module Fun
|
|
|
|
class GamesController < ActionController::Base
|
2004-11-23 20:04:44 -05:00
|
|
|
def hello_world
|
|
|
|
end
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
|
2007-12-14 21:29:45 -05:00
|
|
|
# FIXME: crashes Ruby 1.9
|
2005-02-14 20:45:35 -05:00
|
|
|
class TestController < ActionController::Base
|
|
|
|
layout :determine_layout
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def hello_world
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def render_hello_world
|
2007-09-02 20:18:30 -04:00
|
|
|
render :template => "test/hello_world"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2008-01-21 15:45:04 -05:00
|
|
|
def render_hello_world_with_forward_slash
|
|
|
|
render :template => "/test/hello_world"
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2008-05-01 05:21:46 -04:00
|
|
|
def render_template_in_top_directory
|
|
|
|
render :template => 'shared'
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2008-05-01 05:21:46 -04:00
|
|
|
def render_template_in_top_directory_with_slash
|
|
|
|
render :template => '/shared'
|
|
|
|
end
|
2008-01-21 15:45:04 -05:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def render_hello_world_from_variable
|
|
|
|
@person = "david"
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "hello #{@person}"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def render_action_hello_world
|
2007-09-02 20:18:30 -04:00
|
|
|
render :action => "hello_world"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2006-02-18 19:46:34 -05:00
|
|
|
|
|
|
|
def render_action_hello_world_with_symbol
|
2007-09-02 20:18:30 -04:00
|
|
|
render :action => :hello_world
|
2006-02-18 19:46:34 -05:00
|
|
|
end
|
2006-09-04 00:05:38 -04:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def render_text_hello_world
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "hello world"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2006-12-06 18:06:38 -05:00
|
|
|
|
2006-12-06 17:27:08 -05:00
|
|
|
def render_json_hello_world
|
2007-09-02 20:18:30 -04:00
|
|
|
render :json => {:hello => 'world'}.to_json
|
2006-12-06 17:27:08 -05:00
|
|
|
end
|
2006-12-06 18:06:38 -05:00
|
|
|
|
2006-12-06 17:27:08 -05:00
|
|
|
def render_json_hello_world_with_callback
|
2007-09-02 20:18:30 -04:00
|
|
|
render :json => {:hello => 'world'}.to_json, :callback => 'alert'
|
2006-12-06 17:27:08 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def render_json_with_custom_content_type
|
|
|
|
render :json => {:hello => 'world'}.to_json, :content_type => 'text/javascript'
|
|
|
|
end
|
|
|
|
|
2006-12-18 23:41:57 -05:00
|
|
|
def render_symbol_json
|
|
|
|
render :json => {:hello => 'world'}.to_json
|
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def render_custom_code
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "hello world", :status => 404
|
2006-10-08 21:26:35 -04:00
|
|
|
end
|
|
|
|
|
2008-02-12 17:42:36 -05:00
|
|
|
def render_custom_code_rjs
|
|
|
|
render :update, :status => 404 do |page|
|
|
|
|
page.replace :foo, :partial => 'partial'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-06 15:52:57 -05:00
|
|
|
def render_text_with_nil
|
|
|
|
render :text => nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_text_with_false
|
|
|
|
render :text => false
|
|
|
|
end
|
|
|
|
|
2006-10-08 21:26:35 -04:00
|
|
|
def render_nothing_with_appendix
|
2007-09-02 20:18:30 -04:00
|
|
|
render :text => "appended"
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2007-09-02 20:18:30 -04:00
|
|
|
def render_invalid_args
|
|
|
|
render("test/hello")
|
2006-10-08 21:26:35 -04:00
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def render_xml_hello
|
|
|
|
@name = "David"
|
2007-09-02 20:18:30 -04:00
|
|
|
render :template => "test/hello"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2005-02-14 19:51:02 -05:00
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def render_xml_with_custom_content_type
|
|
|
|
render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
|
|
|
|
end
|
|
|
|
|
2008-01-27 15:48:13 -05:00
|
|
|
def render_line_offset
|
|
|
|
begin
|
|
|
|
render :inline => '<% raise %>', :locals => {:foo => 'bar'}
|
2008-06-30 12:10:48 -04:00
|
|
|
rescue RuntimeError => exc
|
2008-01-27 15:48:13 -05:00
|
|
|
end
|
|
|
|
line = exc.backtrace.first
|
|
|
|
render :text => line
|
|
|
|
end
|
|
|
|
|
2007-02-17 13:16:44 -05:00
|
|
|
def heading
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def greeting
|
|
|
|
# let's just rely on the template
|
2005-02-14 19:51:02 -05:00
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def layout_test
|
2007-09-02 20:18:30 -04:00
|
|
|
render :action => "hello_world"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2006-09-04 00:05:38 -04:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def builder_layout_test
|
2007-09-02 20:18:30 -04:00
|
|
|
render :action => "hello"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
|
|
|
|
2006-09-05 23:51:45 -04:00
|
|
|
def builder_partial_test
|
2007-09-02 20:18:30 -04:00
|
|
|
render :action => "hello_world_container"
|
2006-09-05 23:51:45 -04:00
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def partials_list
|
2005-07-05 14:31:51 -04:00
|
|
|
@test_unchanged = 'hello'
|
2005-02-14 20:45:35 -05:00
|
|
|
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
2007-09-02 20:18:30 -04:00
|
|
|
render :action => "list"
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
|
|
|
|
2005-04-17 05:25:54 -04:00
|
|
|
def partial_only
|
2007-09-02 20:18:30 -04:00
|
|
|
render :partial => true
|
2005-04-17 05:25:54 -04:00
|
|
|
end
|
|
|
|
|
2005-02-23 09:57:08 -05: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-02-23 09:57:08 -05:00
|
|
|
end
|
2006-09-04 00:05:38 -04:00
|
|
|
|
2005-05-19 12:00:04 -04:00
|
|
|
def accessing_params_in_template
|
2007-09-02 20:18:30 -04:00
|
|
|
render :inline => "Hello: <%= params[:name] %>"
|
2005-05-19 12:00:04 -04:00
|
|
|
end
|
2005-02-23 09:57:08 -05:00
|
|
|
|
2005-10-13 16:26:39 -04:00
|
|
|
def accessing_local_assigns_in_inline_template
|
|
|
|
name = params[:local_name]
|
2005-10-17 11:51:07 -04:00
|
|
|
render :inline => "<%= 'Goodbye, ' + local_name %>",
|
|
|
|
:locals => { :local_name => name }
|
2005-10-13 16:26:39 -04:00
|
|
|
end
|
2006-09-04 00:05:38 -04:00
|
|
|
|
2007-04-01 20:02:11 -04:00
|
|
|
def formatted_html_erb
|
|
|
|
end
|
|
|
|
|
|
|
|
def formatted_xml_erb
|
|
|
|
end
|
|
|
|
|
2005-10-24 22:15:08 -04:00
|
|
|
def render_to_string_test
|
|
|
|
@foo = render_to_string :inline => "this is a test"
|
|
|
|
end
|
|
|
|
|
2007-05-14 23:13:32 -04:00
|
|
|
def partial
|
|
|
|
render :partial => 'partial'
|
|
|
|
end
|
2007-06-30 20:04:03 -04:00
|
|
|
|
|
|
|
def partial_dot_html
|
|
|
|
render :partial => 'partial.html.erb'
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2007-05-14 23:13:32 -04:00
|
|
|
def partial_as_rjs
|
|
|
|
render :update do |page|
|
|
|
|
page.replace :foo, :partial => 'partial'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-06-05 12:51:49 -04:00
|
|
|
def respond_to_partial_as_rjs
|
|
|
|
respond_to do |format|
|
|
|
|
format.js do
|
|
|
|
render :update do |page|
|
|
|
|
page.replace :foo, :partial => 'partial'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-10-25 02:38:01 -04:00
|
|
|
def default_render
|
|
|
|
if @alternate_default_render
|
|
|
|
@alternate_default_render.call
|
|
|
|
else
|
|
|
|
render
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_alternate_default
|
|
|
|
# For this test, the method "default_render" is overridden:
|
|
|
|
@alternate_default_render = lambda {
|
|
|
|
render :update do |page|
|
|
|
|
page.replace :foo, :partial => 'partial'
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def rescue_action(e) raise end
|
2006-09-04 00:05:38 -04:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
private
|
|
|
|
def determine_layout
|
2006-09-04 00:05:38 -04:00
|
|
|
case action_name
|
2007-10-02 01:32:14 -04:00
|
|
|
when "layout_test"; "layouts/standard"
|
|
|
|
when "builder_layout_test"; "layouts/builder"
|
|
|
|
when "render_symbol_json"; "layouts/standard" # to make sure layouts don't interfere
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2005-02-14 20:45:35 -05:00
|
|
|
end
|
2005-02-14 19:51:02 -05:00
|
|
|
|
2008-06-25 16:24:12 -04:00
|
|
|
TestController.view_paths = [FIXTURE_LOAD_PATH]
|
|
|
|
Fun::GamesController.view_paths = [FIXTURE_LOAD_PATH]
|
2005-02-14 20:45:35 -05:00
|
|
|
|
|
|
|
class RenderTest < Test::Unit::TestCase
|
2004-11-23 20:04:44 -05:00
|
|
|
def setup
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
2006-03-11 20:56:55 -05:00
|
|
|
@controller = TestController.new
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
@request.host = "www.nextangle.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_simple_show
|
2006-09-04 01:24:08 -04:00
|
|
|
get :hello_world
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_response 200
|
|
|
|
assert_template "test/hello_world"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render
|
2007-09-02 20:18:30 -04:00
|
|
|
get :render_hello_world
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_template "test/hello_world"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2008-01-27 15:48:13 -05:00
|
|
|
def test_line_offset
|
|
|
|
get :render_line_offset
|
|
|
|
line = @response.body
|
|
|
|
assert(line =~ %r{:(\d+):})
|
|
|
|
assert_equal "1", $1
|
|
|
|
end
|
|
|
|
|
2008-01-21 15:45:04 -05:00
|
|
|
def test_render_with_forward_slash
|
|
|
|
get :render_hello_world_with_forward_slash
|
|
|
|
assert_template "test/hello_world"
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2008-05-01 05:21:46 -04:00
|
|
|
def test_render_in_top_directory
|
|
|
|
get :render_template_in_top_directory
|
|
|
|
assert_template "shared"
|
|
|
|
assert_equal "Elastica", @response.body
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2008-05-01 05:21:46 -04:00
|
|
|
def test_render_in_top_directory_with_slash
|
|
|
|
get :render_template_in_top_directory_with_slash
|
|
|
|
assert_template "shared"
|
|
|
|
assert_equal "Elastica", @response.body
|
|
|
|
end
|
2008-01-21 15:45:04 -05:00
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_from_variable
|
2006-09-04 01:24:08 -04:00
|
|
|
get :render_hello_world_from_variable
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "hello david", @response.body
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_action
|
2006-09-04 01:24:08 -04:00
|
|
|
get :render_action_hello_world
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_template "test/hello_world"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_action_with_symbol
|
2006-09-04 01:24:08 -04:00
|
|
|
get :render_action_hello_world_with_symbol
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_template "test/hello_world"
|
2006-02-18 19:46:34 -05:00
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_text
|
2006-09-04 01:24:08 -04:00
|
|
|
get :render_text_hello_world
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "hello world", @response.body
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-12-06 18:06:38 -05:00
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_json
|
2006-12-06 17:27:08 -05:00
|
|
|
get :render_json_hello_world
|
2007-09-30 16:57:50 -04:00
|
|
|
assert_equal '{"hello": "world"}', @response.body
|
2006-12-06 18:06:38 -05:00
|
|
|
assert_equal 'application/json', @response.content_type
|
2006-12-06 17:27:08 -05:00
|
|
|
end
|
2006-12-06 18:06:38 -05:00
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_json_with_callback
|
2006-12-06 17:27:08 -05:00
|
|
|
get :render_json_hello_world_with_callback
|
2007-09-30 16:57:50 -04:00
|
|
|
assert_equal 'alert({"hello": "world"})', @response.body
|
2006-12-06 18:06:38 -05:00
|
|
|
assert_equal 'application/json', @response.content_type
|
2006-12-06 17:27:08 -05:00
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_json_with_custom_content_type
|
|
|
|
get :render_json_with_custom_content_type
|
|
|
|
assert_equal '{"hello": "world"}', @response.body
|
|
|
|
assert_equal 'text/javascript', @response.content_type
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_symbol_json
|
2006-12-18 23:41:57 -05:00
|
|
|
get :render_symbol_json
|
2007-09-30 16:57:50 -04:00
|
|
|
assert_equal '{"hello": "world"}', @response.body
|
2006-12-18 23:41:57 -05:00
|
|
|
assert_equal 'application/json', @response.content_type
|
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_custom_code
|
2006-09-04 01:24:08 -04:00
|
|
|
get :render_custom_code
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_response 404
|
2007-09-02 20:18:30 -04:00
|
|
|
assert_equal 'hello world', @response.body
|
2006-10-08 21:26:35 -04:00
|
|
|
end
|
|
|
|
|
2008-02-12 17:42:36 -05:00
|
|
|
def test_render_custom_code_rjs
|
|
|
|
get :render_custom_code_rjs
|
|
|
|
assert_response 404
|
|
|
|
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
|
|
|
end
|
|
|
|
|
2008-01-06 15:52:57 -05:00
|
|
|
def test_render_text_with_nil
|
|
|
|
get :render_text_with_nil
|
|
|
|
assert_response 200
|
|
|
|
assert_equal '', @response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_text_with_false
|
|
|
|
get :render_text_with_false
|
|
|
|
assert_equal 'false', @response.body
|
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_render_nothing_with_appendix
|
2006-10-08 21:26:35 -04:00
|
|
|
get :render_nothing_with_appendix
|
|
|
|
assert_response 200
|
|
|
|
assert_equal 'appended', @response.body
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2007-09-02 20:18:30 -04:00
|
|
|
def test_attempt_to_render_with_invalid_arguments
|
|
|
|
assert_raises(ActionController::RenderError) { get :render_invalid_args }
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_attempt_to_access_object_method
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2005-01-09 10:20:00 -05:00
|
|
|
def test_private_methods
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
|
2005-01-09 10:20:00 -05:00
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_render_xml
|
2007-09-02 20:18:30 -04:00
|
|
|
get :render_xml_hello
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
|
2007-12-09 17:11:37 -05:00
|
|
|
assert_equal "application/xml", @response.content_type
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_xml_with_default
|
2006-09-04 01:24:08 -04:00
|
|
|
get :greeting
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "<p>This is grand!</p>\n", @response.body
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2006-09-05 23:51:45 -04:00
|
|
|
def test_render_xml_with_partial
|
|
|
|
get :builder_partial_test
|
|
|
|
assert_equal "<test>\n <hello/>\n</test>\n", @response.body
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def test_layout_rendering
|
2006-09-04 01:24:08 -04:00
|
|
|
get :layout_test
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "<html>Hello world!</html>", @response.body
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_xml_with_layouts
|
2006-09-04 01:24:08 -04:00
|
|
|
get :builder_layout_test
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2005-07-06 04:27:11 -04:00
|
|
|
# def test_partials_list
|
2006-03-11 20:56:55 -05:00
|
|
|
# get :partials_list
|
2005-07-06 04:27:11 -04:00
|
|
|
# assert_equal "goodbyeHello: davidHello: marygoodbye\n", process_request.body
|
|
|
|
# end
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-04-17 05:25:54 -04:00
|
|
|
def test_partial_only
|
2006-09-04 01:24:08 -04:00
|
|
|
get :partial_only
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "only partial", @response.body
|
2005-04-17 05:25:54 -04:00
|
|
|
end
|
|
|
|
|
2005-02-23 09:57:08 -05:00
|
|
|
def test_render_to_string
|
2006-09-04 01:24:08 -04:00
|
|
|
get :hello_in_a_string
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body
|
2005-10-24 22:15:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_to_string_resets_assigns
|
2006-09-04 01:24:08 -04:00
|
|
|
get :render_to_string_test
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "The value of foo is: ::this is a test::\n", @response.body
|
2005-02-23 09:57:08 -05:00
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def test_nested_rendering
|
2006-03-11 20:56:55 -05:00
|
|
|
@controller = Fun::GamesController.new
|
|
|
|
get :hello_world
|
|
|
|
assert_equal "Living in a nested world", @response.body
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2005-05-19 12:00:04 -04:00
|
|
|
def test_accessing_params_in_template
|
2006-09-04 01:24:08 -04:00
|
|
|
get :accessing_params_in_template, :name => "David"
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "Hello: David", @response.body
|
2005-05-19 12:00:04 -04:00
|
|
|
end
|
|
|
|
|
2005-10-13 16:26:39 -04:00
|
|
|
def test_accessing_local_assigns_in_inline_template
|
2006-09-04 01:24:08 -04:00
|
|
|
get :accessing_local_assigns_in_inline_template, :local_name => "Local David"
|
2006-03-11 20:56:55 -05:00
|
|
|
assert_equal "Goodbye, Local David", @response.body
|
2005-10-15 20:04:33 -04:00
|
|
|
end
|
2006-09-04 01:51:48 -04:00
|
|
|
|
2007-02-17 13:16:44 -05:00
|
|
|
def test_render_200_should_set_etag
|
|
|
|
get :render_hello_world_from_variable
|
2007-02-18 21:10:19 -05:00
|
|
|
assert_equal etag_for("hello david"), @response.headers['ETag']
|
2007-08-12 18:32:19 -04:00
|
|
|
assert_equal "private, max-age=0, must-revalidate", @response.headers['Cache-Control']
|
2007-02-17 13:16:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_against_etag_request_should_304_when_match
|
|
|
|
@request.headers["HTTP_IF_NONE_MATCH"] = etag_for("hello david")
|
|
|
|
get :render_hello_world_from_variable
|
|
|
|
assert_equal "304 Not Modified", @response.headers['Status']
|
|
|
|
assert @response.body.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_against_etag_request_should_200_when_no_match
|
|
|
|
@request.headers["HTTP_IF_NONE_MATCH"] = etag_for("hello somewhere else")
|
|
|
|
get :render_hello_world_from_variable
|
|
|
|
assert_equal "200 OK", @response.headers['Status']
|
|
|
|
assert !@response.body.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_with_etag
|
|
|
|
get :render_hello_world_from_variable
|
2007-02-17 19:47:18 -05:00
|
|
|
expected_etag = etag_for('hello david')
|
2007-02-18 21:10:19 -05:00
|
|
|
assert_equal expected_etag, @response.headers['ETag']
|
2007-02-17 19:47:18 -05:00
|
|
|
|
2007-02-17 13:16:44 -05:00
|
|
|
@request.headers["HTTP_IF_NONE_MATCH"] = expected_etag
|
|
|
|
get :render_hello_world_from_variable
|
|
|
|
assert_equal "304 Not Modified", @response.headers['Status']
|
2007-02-17 19:47:18 -05:00
|
|
|
|
2007-02-17 13:16:44 -05:00
|
|
|
@request.headers["HTTP_IF_NONE_MATCH"] = "\"diftag\""
|
|
|
|
get :render_hello_world_from_variable
|
|
|
|
assert_equal "200 OK", @response.headers['Status']
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_with_404_shouldnt_have_etag
|
|
|
|
get :render_custom_code
|
2007-02-18 21:10:19 -05:00
|
|
|
assert_nil @response.headers['ETag']
|
2007-02-17 13:16:44 -05:00
|
|
|
end
|
|
|
|
|
2007-02-18 11:32:05 -05:00
|
|
|
def test_etag_should_not_be_changed_when_already_set
|
|
|
|
expected_etag = etag_for("hello somewhere else")
|
2007-02-18 21:10:19 -05:00
|
|
|
@response.headers["ETag"] = expected_etag
|
2007-02-18 11:32:05 -05:00
|
|
|
get :render_hello_world_from_variable
|
2007-02-18 21:10:19 -05:00
|
|
|
assert_equal expected_etag, @response.headers['ETag']
|
2007-02-18 11:32:05 -05:00
|
|
|
end
|
|
|
|
|
2007-02-18 18:54:20 -05:00
|
|
|
def test_etag_should_govern_renders_with_layouts_too
|
|
|
|
get :builder_layout_test
|
2007-02-18 19:27:19 -05:00
|
|
|
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
|
2007-02-18 21:10:19 -05:00
|
|
|
assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag']
|
2007-02-18 18:54:20 -05:00
|
|
|
end
|
|
|
|
|
2007-04-01 20:02:11 -04:00
|
|
|
def test_should_render_formatted_template
|
|
|
|
get :formatted_html_erb
|
|
|
|
assert_equal 'formatted html erb', @response.body
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2007-04-01 20:02:11 -04:00
|
|
|
def test_should_render_formatted_xml_erb_template
|
|
|
|
get :formatted_xml_erb, :format => :xml
|
|
|
|
assert_equal '<test>passed formatted xml erb</test>', @response.body
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2007-04-01 20:02:11 -04:00
|
|
|
def test_should_render_formatted_html_erb_template
|
|
|
|
get :formatted_xml_erb
|
|
|
|
assert_equal '<test>passed formatted html erb</test>', @response.body
|
|
|
|
end
|
2008-06-25 16:24:12 -04:00
|
|
|
|
2007-04-12 16:25:32 -04:00
|
|
|
def test_should_render_formatted_html_erb_template_with_faulty_accepts_header
|
|
|
|
@request.env["HTTP_ACCEPT"] = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*"
|
|
|
|
get :formatted_xml_erb
|
|
|
|
assert_equal '<test>passed formatted html erb</test>', @response.body
|
|
|
|
end
|
2007-02-18 18:54:20 -05:00
|
|
|
|
2007-05-14 23:13:32 -04:00
|
|
|
def test_should_render_html_formatted_partial
|
|
|
|
get :partial
|
|
|
|
assert_equal 'partial html', @response.body
|
|
|
|
end
|
|
|
|
|
2007-06-30 20:04:03 -04:00
|
|
|
def test_should_render_html_partial_with_dot
|
|
|
|
get :partial_dot_html
|
|
|
|
assert_equal 'partial html', @response.body
|
|
|
|
end
|
|
|
|
|
2007-05-14 23:13:32 -04:00
|
|
|
def test_should_render_html_formatted_partial_with_rjs
|
|
|
|
xhr :get, :partial_as_rjs
|
|
|
|
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
|
|
|
end
|
2007-04-24 13:52:03 -04:00
|
|
|
|
2007-06-05 12:51:49 -04:00
|
|
|
def test_should_render_html_formatted_partial_with_rjs_and_js_format
|
|
|
|
xhr :get, :respond_to_partial_as_rjs
|
|
|
|
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
|
|
|
end
|
|
|
|
|
2007-05-14 23:15:36 -04:00
|
|
|
def test_should_render_js_partial
|
|
|
|
xhr :get, :partial, :format => 'js'
|
|
|
|
assert_equal 'partial js', @response.body
|
|
|
|
end
|
|
|
|
|
2007-10-25 02:38:01 -04:00
|
|
|
def test_should_render_with_alternate_default_render
|
|
|
|
xhr :get, :render_alternate_default
|
|
|
|
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:37 -05:00
|
|
|
def test_should_render_xml_but_keep_custom_content_type
|
|
|
|
get :render_xml_with_custom_content_type
|
|
|
|
assert_equal "application/atomsvc+xml", @response.content_type
|
|
|
|
end
|
|
|
|
|
2006-09-04 01:51:48 -04:00
|
|
|
protected
|
2007-02-17 13:16:44 -05:00
|
|
|
def etag_for(text)
|
2007-02-17 19:47:18 -05:00
|
|
|
%("#{Digest::MD5.hexdigest(text)}")
|
2007-02-17 13:16:44 -05:00
|
|
|
end
|
2005-05-30 05:00:46 -04:00
|
|
|
end
|