2004-11-24 01:04:44 +00:00
|
|
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
2007-07-17 09:44:03 +00:00
|
|
|
require File.dirname(__FILE__) + '/fake_models'
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
module Fun
|
|
|
|
class GamesController < ActionController::Base
|
2004-11-24 01:04:44 +00:00
|
|
|
def hello_world
|
|
|
|
end
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
|
|
|
end
|
2004-11-24 01:04:44 +00:00
|
|
|
|
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
class TestController < ActionController::Base
|
|
|
|
layout :determine_layout
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def hello_world
|
|
|
|
end
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def render_hello_world
|
2007-09-03 00:18:30 +00:00
|
|
|
render :template => "test/hello_world"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def render_hello_world_from_variable
|
|
|
|
@person = "david"
|
2007-09-03 00:18:30 +00:00
|
|
|
render :text => "hello #{@person}"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def render_action_hello_world
|
2007-09-03 00:18:30 +00:00
|
|
|
render :action => "hello_world"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
2006-02-19 00:46:34 +00:00
|
|
|
|
|
|
|
def render_action_hello_world_with_symbol
|
2007-09-03 00:18:30 +00:00
|
|
|
render :action => :hello_world
|
2006-02-19 00:46:34 +00:00
|
|
|
end
|
2006-09-04 04:05:38 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def render_text_hello_world
|
2007-09-03 00:18:30 +00:00
|
|
|
render :text => "hello world"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
2006-12-06 23:06:38 +00:00
|
|
|
|
2006-12-06 22:27:08 +00:00
|
|
|
def render_json_hello_world
|
2007-09-03 00:18:30 +00:00
|
|
|
render :json => {:hello => 'world'}.to_json
|
2006-12-06 22:27:08 +00:00
|
|
|
end
|
2006-12-06 23:06:38 +00:00
|
|
|
|
2006-12-06 22:27:08 +00:00
|
|
|
def render_json_hello_world_with_callback
|
2007-09-03 00:18:30 +00:00
|
|
|
render :json => {:hello => 'world'}.to_json, :callback => 'alert'
|
2006-12-06 22:27:08 +00:00
|
|
|
end
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def render_json_with_custom_content_type
|
|
|
|
render :json => {:hello => 'world'}.to_json, :content_type => 'text/javascript'
|
|
|
|
end
|
|
|
|
|
2006-12-19 04:41:57 +00:00
|
|
|
def render_symbol_json
|
|
|
|
render :json => {:hello => 'world'}.to_json
|
|
|
|
end
|
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def render_custom_code
|
2007-09-03 00:18:30 +00:00
|
|
|
render :text => "hello world", :status => 404
|
2006-10-09 01:26:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_nothing_with_appendix
|
2007-09-03 00:18:30 +00:00
|
|
|
render :text => "appended"
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_invalid_args
|
|
|
|
render("test/hello")
|
2006-10-09 01:26:35 +00:00
|
|
|
end
|
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def render_xml_hello
|
|
|
|
@name = "David"
|
2007-09-03 00:18:30 +00:00
|
|
|
render :template => "test/hello"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
2005-02-15 00:51:02 +00:00
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def render_xml_with_custom_content_type
|
|
|
|
render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
|
|
|
|
end
|
|
|
|
|
2007-02-17 18:16:44 +00:00
|
|
|
def heading
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def greeting
|
|
|
|
# let's just rely on the template
|
2005-02-15 00:51:02 +00:00
|
|
|
end
|
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def layout_test
|
2007-09-03 00:18:30 +00:00
|
|
|
render :action => "hello_world"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
2006-09-04 04:05:38 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def builder_layout_test
|
2007-09-03 00:18:30 +00:00
|
|
|
render :action => "hello"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
|
|
|
|
2006-09-06 03:51:45 +00:00
|
|
|
def builder_partial_test
|
2007-09-03 00:18:30 +00:00
|
|
|
render :action => "hello_world_container"
|
2006-09-06 03:51:45 +00:00
|
|
|
end
|
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def partials_list
|
2005-07-05 18:31:51 +00:00
|
|
|
@test_unchanged = 'hello'
|
2005-02-15 01:45:35 +00:00
|
|
|
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
2007-09-03 00:18:30 +00:00
|
|
|
render :action => "list"
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
|
|
|
|
2005-04-17 09:25:54 +00:00
|
|
|
def partial_only
|
2007-09-03 00:18:30 +00:00
|
|
|
render :partial => true
|
2005-04-17 09:25:54 +00:00
|
|
|
end
|
|
|
|
|
2005-02-23 14:57:08 +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-02-23 14:57:08 +00:00
|
|
|
end
|
2006-09-04 04:05:38 +00:00
|
|
|
|
2005-05-19 16:00:04 +00:00
|
|
|
def accessing_params_in_template
|
2007-09-03 00:18:30 +00:00
|
|
|
render :inline => "Hello: <%= params[:name] %>"
|
2005-05-19 16:00:04 +00:00
|
|
|
end
|
2005-02-23 14:57:08 +00:00
|
|
|
|
2005-10-13 20:26:39 +00:00
|
|
|
def accessing_local_assigns_in_inline_template
|
|
|
|
name = params[:local_name]
|
2005-10-17 15:51:07 +00:00
|
|
|
render :inline => "<%= 'Goodbye, ' + local_name %>",
|
|
|
|
:locals => { :local_name => name }
|
2005-10-13 20:26:39 +00:00
|
|
|
end
|
2006-09-04 04:05:38 +00:00
|
|
|
|
2005-10-16 00:04:33 +00:00
|
|
|
def accessing_local_assigns_in_inline_template_with_string_keys
|
|
|
|
name = params[:local_name]
|
2005-10-17 15:51:07 +00:00
|
|
|
ActionView::Base.local_assigns_support_string_keys = true
|
|
|
|
render :inline => "<%= 'Goodbye, ' + local_name %>",
|
|
|
|
:locals => { "local_name" => name }
|
|
|
|
ActionView::Base.local_assigns_support_string_keys = false
|
2005-10-16 00:04:33 +00:00
|
|
|
end
|
2005-10-13 20:26:39 +00:00
|
|
|
|
2007-04-02 00:02:11 +00:00
|
|
|
def formatted_html_erb
|
|
|
|
end
|
|
|
|
|
|
|
|
def formatted_xml_erb
|
|
|
|
end
|
|
|
|
|
2005-10-25 02:15:08 +00:00
|
|
|
def render_to_string_test
|
|
|
|
@foo = render_to_string :inline => "this is a test"
|
|
|
|
end
|
|
|
|
|
2007-05-15 03:13:32 +00:00
|
|
|
def partial
|
|
|
|
render :partial => 'partial'
|
|
|
|
end
|
2007-07-01 00:04:03 +00:00
|
|
|
|
|
|
|
def partial_dot_html
|
|
|
|
render :partial => 'partial.html.erb'
|
|
|
|
end
|
2007-05-15 03:13:32 +00:00
|
|
|
|
|
|
|
def partial_as_rjs
|
|
|
|
render :update do |page|
|
|
|
|
page.replace :foo, :partial => 'partial'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-06-05 16:51:49 +00: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 06:38:01 +00: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-15 01:45:35 +00:00
|
|
|
def rescue_action(e) raise end
|
2006-09-04 04:05:38 +00:00
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
private
|
|
|
|
def determine_layout
|
2006-09-04 04:05:38 +00:00
|
|
|
case action_name
|
2007-10-02 05:32:14 +00: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-15 01:45:35 +00:00
|
|
|
end
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
2005-02-15 01:45:35 +00:00
|
|
|
end
|
2005-02-15 00:51:02 +00:00
|
|
|
|
2007-02-04 20:47:05 +00:00
|
|
|
TestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
|
|
|
Fun::GamesController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
2005-02-15 01:45:35 +00:00
|
|
|
|
|
|
|
class RenderTest < Test::Unit::TestCase
|
2004-11-24 01:04:44 +00:00
|
|
|
def setup
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
2006-03-12 01:56:55 +00:00
|
|
|
@controller = TestController.new
|
2004-11-24 01:04:44 +00:00
|
|
|
|
|
|
|
@request.host = "www.nextangle.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_simple_show
|
2006-09-04 05:24:08 +00:00
|
|
|
get :hello_world
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_response 200
|
|
|
|
assert_template "test/hello_world"
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render
|
2007-09-03 00:18:30 +00:00
|
|
|
get :render_hello_world
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_template "test/hello_world"
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_from_variable
|
2006-09-04 05:24:08 +00:00
|
|
|
get :render_hello_world_from_variable
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "hello david", @response.body
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_action
|
2006-09-04 05:24:08 +00:00
|
|
|
get :render_action_hello_world
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_template "test/hello_world"
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_action_with_symbol
|
2006-09-04 05:24:08 +00:00
|
|
|
get :render_action_hello_world_with_symbol
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_template "test/hello_world"
|
2006-02-19 00:46:34 +00:00
|
|
|
end
|
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_text
|
2006-09-04 05:24:08 +00:00
|
|
|
get :render_text_hello_world
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "hello world", @response.body
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
2006-12-06 23:06:38 +00:00
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_json
|
2006-12-06 22:27:08 +00:00
|
|
|
get :render_json_hello_world
|
2007-09-30 20:57:50 +00:00
|
|
|
assert_equal '{"hello": "world"}', @response.body
|
2006-12-06 23:06:38 +00:00
|
|
|
assert_equal 'application/json', @response.content_type
|
2006-12-06 22:27:08 +00:00
|
|
|
end
|
2006-12-06 23:06:38 +00:00
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_json_with_callback
|
2006-12-06 22:27:08 +00:00
|
|
|
get :render_json_hello_world_with_callback
|
2007-09-30 20:57:50 +00:00
|
|
|
assert_equal 'alert({"hello": "world"})', @response.body
|
2006-12-06 23:06:38 +00:00
|
|
|
assert_equal 'application/json', @response.content_type
|
2006-12-06 22:27:08 +00:00
|
|
|
end
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2007-12-09 22:11:37 +00: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-19 04:41:57 +00:00
|
|
|
get :render_symbol_json
|
2007-09-30 20:57:50 +00:00
|
|
|
assert_equal '{"hello": "world"}', @response.body
|
2006-12-19 04:41:57 +00:00
|
|
|
assert_equal 'application/json', @response.content_type
|
|
|
|
end
|
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_custom_code
|
2006-09-04 05:24:08 +00:00
|
|
|
get :render_custom_code
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_response 404
|
2007-09-03 00:18:30 +00:00
|
|
|
assert_equal 'hello world', @response.body
|
2006-10-09 01:26:35 +00:00
|
|
|
end
|
|
|
|
|
2007-12-09 22:11:37 +00:00
|
|
|
def test_render_nothing_with_appendix
|
2006-10-09 01:26:35 +00:00
|
|
|
get :render_nothing_with_appendix
|
|
|
|
assert_response 200
|
|
|
|
assert_equal 'appended', @response.body
|
|
|
|
end
|
2007-09-03 00:18:30 +00:00
|
|
|
|
|
|
|
def test_attempt_to_render_with_invalid_arguments
|
|
|
|
assert_raises(ActionController::RenderError) { get :render_invalid_args }
|
|
|
|
end
|
|
|
|
|
2004-11-24 01:04:44 +00:00
|
|
|
def test_attempt_to_access_object_method
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2005-01-09 15:20:00 +00:00
|
|
|
def test_private_methods
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
|
2005-01-09 15:20:00 +00:00
|
|
|
end
|
|
|
|
|
2004-11-24 01:04:44 +00:00
|
|
|
def test_render_xml
|
2007-09-03 00:18:30 +00:00
|
|
|
get :render_xml_hello
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
|
2007-12-09 22:11:37 +00:00
|
|
|
assert_equal "application/xml", @response.content_type
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_xml_with_default
|
2006-09-04 05:24:08 +00:00
|
|
|
get :greeting
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "<p>This is grand!</p>\n", @response.body
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2006-09-06 03:51:45 +00:00
|
|
|
def test_render_xml_with_partial
|
|
|
|
get :builder_partial_test
|
|
|
|
assert_equal "<test>\n <hello/>\n</test>\n", @response.body
|
|
|
|
end
|
|
|
|
|
2004-11-24 01:04:44 +00:00
|
|
|
def test_layout_rendering
|
2006-09-04 05:24:08 +00:00
|
|
|
get :layout_test
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "<html>Hello world!</html>", @response.body
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_xml_with_layouts
|
2006-09-04 05:24:08 +00:00
|
|
|
get :builder_layout_test
|
2006-03-12 01:56:55 +00: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-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2005-07-06 08:27:11 +00:00
|
|
|
# def test_partials_list
|
2006-03-12 01:56:55 +00:00
|
|
|
# get :partials_list
|
2005-07-06 08:27:11 +00:00
|
|
|
# assert_equal "goodbyeHello: davidHello: marygoodbye\n", process_request.body
|
|
|
|
# end
|
2004-11-24 01:04:44 +00:00
|
|
|
|
2005-04-17 09:25:54 +00:00
|
|
|
def test_partial_only
|
2006-09-04 05:24:08 +00:00
|
|
|
get :partial_only
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "only partial", @response.body
|
2005-04-17 09:25:54 +00:00
|
|
|
end
|
|
|
|
|
2005-02-23 14:57:08 +00:00
|
|
|
def test_render_to_string
|
2006-09-04 05:24:08 +00:00
|
|
|
get :hello_in_a_string
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body
|
2005-10-25 02:15:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_to_string_resets_assigns
|
2006-09-04 05:24:08 +00:00
|
|
|
get :render_to_string_test
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "The value of foo is: ::this is a test::\n", @response.body
|
2005-02-23 14:57:08 +00:00
|
|
|
end
|
|
|
|
|
2005-02-15 01:45:35 +00:00
|
|
|
def test_nested_rendering
|
2006-03-12 01:56:55 +00:00
|
|
|
@controller = Fun::GamesController.new
|
|
|
|
get :hello_world
|
|
|
|
assert_equal "Living in a nested world", @response.body
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
|
|
|
|
2005-05-19 16:00:04 +00:00
|
|
|
def test_accessing_params_in_template
|
2006-09-04 05:24:08 +00:00
|
|
|
get :accessing_params_in_template, :name => "David"
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "Hello: David", @response.body
|
2005-05-19 16:00:04 +00:00
|
|
|
end
|
|
|
|
|
2005-10-13 20:26:39 +00:00
|
|
|
def test_accessing_local_assigns_in_inline_template
|
2006-09-04 05:24:08 +00:00
|
|
|
get :accessing_local_assigns_in_inline_template, :local_name => "Local David"
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "Goodbye, Local David", @response.body
|
2005-10-13 20:26:39 +00:00
|
|
|
end
|
2006-09-04 04:05:38 +00:00
|
|
|
|
2005-10-16 00:04:33 +00:00
|
|
|
def test_accessing_local_assigns_in_inline_template_with_string_keys
|
2006-09-04 05:24:08 +00:00
|
|
|
get :accessing_local_assigns_in_inline_template_with_string_keys, :local_name => "Local David"
|
2006-03-12 01:56:55 +00:00
|
|
|
assert_equal "Goodbye, Local David", @response.body
|
2005-10-16 00:04:33 +00:00
|
|
|
end
|
2006-09-04 05:51:48 +00:00
|
|
|
|
2007-02-17 18:16:44 +00:00
|
|
|
def test_render_200_should_set_etag
|
|
|
|
get :render_hello_world_from_variable
|
2007-02-19 02:10:19 +00:00
|
|
|
assert_equal etag_for("hello david"), @response.headers['ETag']
|
2007-08-12 22:32:19 +00:00
|
|
|
assert_equal "private, max-age=0, must-revalidate", @response.headers['Cache-Control']
|
2007-02-17 18:16:44 +00: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-18 00:47:18 +00:00
|
|
|
expected_etag = etag_for('hello david')
|
2007-02-19 02:10:19 +00:00
|
|
|
assert_equal expected_etag, @response.headers['ETag']
|
2007-02-18 00:47:18 +00:00
|
|
|
|
2007-02-17 18:16:44 +00: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-18 00:47:18 +00:00
|
|
|
|
2007-02-17 18:16:44 +00: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-19 02:10:19 +00:00
|
|
|
assert_nil @response.headers['ETag']
|
2007-02-17 18:16:44 +00:00
|
|
|
end
|
|
|
|
|
2007-02-18 16:32:05 +00:00
|
|
|
def test_etag_should_not_be_changed_when_already_set
|
|
|
|
expected_etag = etag_for("hello somewhere else")
|
2007-02-19 02:10:19 +00:00
|
|
|
@response.headers["ETag"] = expected_etag
|
2007-02-18 16:32:05 +00:00
|
|
|
get :render_hello_world_from_variable
|
2007-02-19 02:10:19 +00:00
|
|
|
assert_equal expected_etag, @response.headers['ETag']
|
2007-02-18 16:32:05 +00:00
|
|
|
end
|
|
|
|
|
2007-02-18 23:54:20 +00:00
|
|
|
def test_etag_should_govern_renders_with_layouts_too
|
|
|
|
get :builder_layout_test
|
2007-02-19 00:27:19 +00: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-19 02:10:19 +00: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 23:54:20 +00:00
|
|
|
end
|
|
|
|
|
2007-04-02 00:02:11 +00:00
|
|
|
def test_should_render_formatted_template
|
|
|
|
get :formatted_html_erb
|
|
|
|
assert_equal 'formatted html erb', @response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def test_should_render_formatted_html_erb_template
|
|
|
|
get :formatted_xml_erb
|
|
|
|
assert_equal '<test>passed formatted html erb</test>', @response.body
|
|
|
|
end
|
2007-04-12 20:25:32 +00: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 23:54:20 +00:00
|
|
|
|
2007-05-15 03:13:32 +00:00
|
|
|
def test_should_render_html_formatted_partial
|
|
|
|
get :partial
|
|
|
|
assert_equal 'partial html', @response.body
|
|
|
|
end
|
|
|
|
|
2007-07-01 00:04:03 +00:00
|
|
|
def test_should_render_html_partial_with_dot
|
|
|
|
get :partial_dot_html
|
|
|
|
assert_equal 'partial html', @response.body
|
|
|
|
end
|
|
|
|
|
2007-05-15 03:13:32 +00: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 17:52:03 +00:00
|
|
|
|
2007-06-05 16:51:49 +00: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-15 03:15:36 +00:00
|
|
|
def test_should_render_js_partial
|
|
|
|
xhr :get, :partial, :format => 'js'
|
|
|
|
assert_equal 'partial js', @response.body
|
|
|
|
end
|
|
|
|
|
2007-10-25 06:38:01 +00: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 22:11:37 +00: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 05:51:48 +00:00
|
|
|
protected
|
2007-09-03 00:18:30 +00:00
|
|
|
|
2007-02-17 18:16:44 +00:00
|
|
|
def etag_for(text)
|
2007-02-18 00:47:18 +00:00
|
|
|
%("#{Digest::MD5.hexdigest(text)}")
|
2007-02-17 18:16:44 +00:00
|
|
|
end
|
2005-05-30 09:00:46 +00:00
|
|
|
end
|