mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ported over render :file tests.
This commit is contained in:
parent
4f291fa528
commit
49a84ff69c
8 changed files with 585 additions and 321 deletions
37
actionpack/test/controller/render_js_test.rb
Normal file
37
actionpack/test/controller/render_js_test.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
require 'abstract_unit'
|
||||||
|
require 'controller/fake_models'
|
||||||
|
require 'pathname'
|
||||||
|
|
||||||
|
class TestController < ActionController::Base
|
||||||
|
protect_from_forgery
|
||||||
|
|
||||||
|
def render_vanilla_js_hello
|
||||||
|
render :js => "alert('hello')"
|
||||||
|
end
|
||||||
|
|
||||||
|
def greeting
|
||||||
|
# let's just rely on the template
|
||||||
|
end
|
||||||
|
|
||||||
|
def partial
|
||||||
|
render :partial => 'partial'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class RenderTest < ActionController::TestCase
|
||||||
|
def test_render_vanilla_js
|
||||||
|
get :render_vanilla_js_hello
|
||||||
|
assert_equal "alert('hello')", @response.body
|
||||||
|
assert_equal "text/javascript", @response.content_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_with_default_from_accept_header
|
||||||
|
xhr :get, :greeting
|
||||||
|
assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_render_js_partial
|
||||||
|
xhr :get, :partial, :format => 'js'
|
||||||
|
assert_equal 'partial js', @response.body
|
||||||
|
end
|
||||||
|
end
|
80
actionpack/test/controller/render_json_test.rb
Normal file
80
actionpack/test/controller/render_json_test.rb
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
require 'abstract_unit'
|
||||||
|
require 'controller/fake_models'
|
||||||
|
require 'pathname'
|
||||||
|
|
||||||
|
class TestController < ActionController::Base
|
||||||
|
protect_from_forgery
|
||||||
|
|
||||||
|
def render_json_nil
|
||||||
|
render :json => nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_json_hello_world
|
||||||
|
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_json_hello_world_with_callback
|
||||||
|
render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert'
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_json_with_custom_content_type
|
||||||
|
render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript'
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_symbol_json
|
||||||
|
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_json_with_render_to_string
|
||||||
|
render :json => {:hello => render_to_string(:partial => 'partial')}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class RenderTest < ActionController::TestCase
|
||||||
|
tests TestController
|
||||||
|
|
||||||
|
def setup
|
||||||
|
# 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".
|
||||||
|
super
|
||||||
|
@controller.logger = Logger.new(nil)
|
||||||
|
|
||||||
|
@request.host = "www.nextangle.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_json_nil
|
||||||
|
get :render_json_nil
|
||||||
|
assert_equal 'null', @response.body
|
||||||
|
assert_equal 'application/json', @response.content_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_json
|
||||||
|
get :render_json_hello_world
|
||||||
|
assert_equal '{"hello":"world"}', @response.body
|
||||||
|
assert_equal 'application/json', @response.content_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_json_with_callback
|
||||||
|
get :render_json_hello_world_with_callback
|
||||||
|
assert_equal 'alert({"hello":"world"})', @response.body
|
||||||
|
assert_equal 'application/json', @response.content_type
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
get :render_symbol_json
|
||||||
|
assert_equal '{"hello":"world"}', @response.body
|
||||||
|
assert_equal 'application/json', @response.content_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_json_with_render_to_string
|
||||||
|
get :render_json_with_render_to_string
|
||||||
|
assert_equal '{"hello":"partial html"}', @response.body
|
||||||
|
assert_equal 'application/json', @response.content_type
|
||||||
|
end
|
||||||
|
end
|
222
actionpack/test/controller/render_other_test.rb
Normal file
222
actionpack/test/controller/render_other_test.rb
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
require 'abstract_unit'
|
||||||
|
require 'controller/fake_models'
|
||||||
|
require 'pathname'
|
||||||
|
|
||||||
|
class TestController < ActionController::Base
|
||||||
|
protect_from_forgery
|
||||||
|
|
||||||
|
module RenderTestHelper
|
||||||
|
def rjs_helper_method_from_module
|
||||||
|
page.visual_effect :highlight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
helper RenderTestHelper
|
||||||
|
helper do
|
||||||
|
def rjs_helper_method(value)
|
||||||
|
page.visual_effect :highlight, value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def enum_rjs_test
|
||||||
|
render :update do |page|
|
||||||
|
page.select('.product').each do |value|
|
||||||
|
page.rjs_helper_method_from_module
|
||||||
|
page.rjs_helper_method(value)
|
||||||
|
page.sortable(value, :url => { :action => "order" })
|
||||||
|
page.draggable(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_explicit_html_template
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_custom_code_rjs
|
||||||
|
render :update, :status => 404 do |page|
|
||||||
|
page.replace :foo, :partial => 'partial'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_implicit_html_template
|
||||||
|
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
|
||||||
|
|
||||||
|
def delete_with_js
|
||||||
|
@project_id = 4
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_page
|
||||||
|
render :update do |page|
|
||||||
|
page.replace_html 'balance', '$37,000,000.00'
|
||||||
|
page.visual_effect :highlight, 'balance'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def update_page_with_view_method
|
||||||
|
render :update do |page|
|
||||||
|
page.replace_html 'person', pluralize(2, 'person')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def partial_as_rjs
|
||||||
|
render :update do |page|
|
||||||
|
page.replace :foo, :partial => 'partial'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def render_alternate_default
|
||||||
|
# For this test, the method "default_render" is overridden:
|
||||||
|
@alternate_default_render = lambda do
|
||||||
|
render :update do |page|
|
||||||
|
page.replace :foo, :partial => 'partial'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def determine_layout
|
||||||
|
case action_name
|
||||||
|
when "render_js_with_explicit_template",
|
||||||
|
"render_js_with_explicit_action_template",
|
||||||
|
"delete_with_js", "update_page", "update_page_with_instance_variables"
|
||||||
|
|
||||||
|
"layouts/standard"
|
||||||
|
when "action_talk_to_layout", "layout_overriding_layout"
|
||||||
|
"layouts/talk_from_action"
|
||||||
|
when "render_implicit_html_template_from_xhr_request"
|
||||||
|
(request.xhr? ? 'layouts/xhr' : 'layouts/standard')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class RenderTest < ActionController::TestCase
|
||||||
|
tests TestController
|
||||||
|
|
||||||
|
def setup
|
||||||
|
# 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".
|
||||||
|
super
|
||||||
|
@controller.logger = Logger.new(nil)
|
||||||
|
|
||||||
|
@request.host = "www.nextangle.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_enum_rjs_test
|
||||||
|
ActiveSupport::SecureRandom.stubs(:base64).returns("asdf")
|
||||||
|
get :enum_rjs_test
|
||||||
|
body = %{
|
||||||
|
$$(".product").each(function(value, index) {
|
||||||
|
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) + '&authenticity_token=' + encodeURIComponent('asdf')})}});
|
||||||
|
new Draggable(value, {});
|
||||||
|
});
|
||||||
|
}.gsub(/^ /, '').strip
|
||||||
|
assert_equal body, @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template
|
||||||
|
[:js, "js"].each do |format|
|
||||||
|
assert_nothing_raised do
|
||||||
|
get :render_explicit_html_template, :format => format
|
||||||
|
assert_equal %(document.write("Hello world\\n");), @response.body
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_custom_code_rjs
|
||||||
|
get :render_custom_code_rjs
|
||||||
|
assert_response 404
|
||||||
|
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_in_an_rjs_template_should_pick_html_templates_when_available
|
||||||
|
[:js, "js"].each do |format|
|
||||||
|
assert_nothing_raised do
|
||||||
|
get :render_implicit_html_template, :format => format
|
||||||
|
assert_equal %(document.write("Hello world\\n");), @response.body
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_rjs_template_explicitly
|
||||||
|
get :render_js_with_explicit_template
|
||||||
|
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rendering_rjs_action_explicitly
|
||||||
|
get :render_js_with_explicit_action_template
|
||||||
|
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_rjs_with_default
|
||||||
|
get :delete_with_js
|
||||||
|
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update_page
|
||||||
|
get :update_page
|
||||||
|
assert_template nil
|
||||||
|
assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type']
|
||||||
|
assert_equal 2, @response.body.split($/).length
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update_page_with_instance_variables
|
||||||
|
get :update_page_with_instance_variables
|
||||||
|
assert_template nil
|
||||||
|
assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
|
||||||
|
assert_match /balance/, @response.body
|
||||||
|
assert_match /\$37/, @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update_page_with_view_method
|
||||||
|
get :update_page_with_view_method
|
||||||
|
assert_template nil
|
||||||
|
assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
|
||||||
|
assert_match /2 people/, @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_render_html_formatted_partial_with_rjs
|
||||||
|
xhr :get, :partial_as_rjs
|
||||||
|
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def test_should_render_with_alternate_default_render
|
||||||
|
xhr :get, :render_alternate_default
|
||||||
|
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
||||||
|
end
|
||||||
|
end
|
|
@ -145,18 +145,21 @@ class TestController < ActionController::Base
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def render_file_with_instance_variables
|
def render_file_with_instance_variables
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
|
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
|
||||||
render :file => path
|
render :file => path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def render_file_as_string_with_instance_variables
|
def render_file_as_string_with_instance_variables
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
|
path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
|
||||||
render path
|
render path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def render_file_not_using_full_path
|
def render_file_not_using_full_path
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
render :file => 'test/render_file_with_ivar'
|
render :file => 'test/render_file_with_ivar'
|
||||||
|
@ -203,41 +206,11 @@ class TestController < ActionController::Base
|
||||||
render :inline => "<%= controller_name %>"
|
render :inline => "<%= controller_name %>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_json_nil
|
|
||||||
render :json => nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_json_hello_world
|
|
||||||
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_json_hello_world_with_callback
|
|
||||||
render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert'
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_json_with_custom_content_type
|
|
||||||
render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript'
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_symbol_json
|
|
||||||
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_json_with_render_to_string
|
|
||||||
render :json => {:hello => render_to_string(:partial => 'partial')}
|
|
||||||
end
|
|
||||||
|
|
||||||
# :ported:
|
# :ported:
|
||||||
def render_custom_code
|
def render_custom_code
|
||||||
render :text => "hello world", :status => 404
|
render :text => "hello world", :status => 404
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_custom_code_rjs
|
|
||||||
render :update, :status => 404 do |page|
|
|
||||||
page.replace :foo, :partial => 'partial'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# :ported:
|
# :ported:
|
||||||
def render_text_with_nil
|
def render_text_with_nil
|
||||||
render :text => nil
|
render :text => nil
|
||||||
|
@ -253,10 +226,6 @@ class TestController < ActionController::Base
|
||||||
render :text => "appended"
|
render :text => "appended"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_vanilla_js_hello
|
|
||||||
render :js => "alert('hello')"
|
|
||||||
end
|
|
||||||
|
|
||||||
# This test is testing 3 things:
|
# This test is testing 3 things:
|
||||||
# render :file in AV :ported:
|
# render :file in AV :ported:
|
||||||
# render :template in AC :ported:
|
# render :template in AC :ported:
|
||||||
|
@ -271,10 +240,6 @@ class TestController < ActionController::Base
|
||||||
render "test/hello"
|
render "test/hello"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_xml_with_custom_content_type
|
|
||||||
render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_line_offset
|
def render_line_offset
|
||||||
render :inline => '<% raise %>', :locals => {:foo => 'bar'}
|
render :inline => '<% raise %>', :locals => {:foo => 'bar'}
|
||||||
end
|
end
|
||||||
|
@ -331,12 +296,6 @@ class TestController < ActionController::Base
|
||||||
:locals => { :local_name => name }
|
:locals => { :local_name => name }
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_implicit_html_template
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_explicit_html_template
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_implicit_html_template_from_xhr_request
|
def render_implicit_html_template_from_xhr_request
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -470,66 +429,6 @@ class TestController < ActionController::Base
|
||||||
render :template => "test/hello_world_from_rxml.builder"
|
render :template => "test/hello_world_from_rxml.builder"
|
||||||
end
|
end
|
||||||
|
|
||||||
module RenderTestHelper
|
|
||||||
def rjs_helper_method_from_module
|
|
||||||
page.visual_effect :highlight
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
helper RenderTestHelper
|
|
||||||
helper do
|
|
||||||
def rjs_helper_method(value)
|
|
||||||
page.visual_effect :highlight, value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def enum_rjs_test
|
|
||||||
render :update do |page|
|
|
||||||
page.select('.product').each do |value|
|
|
||||||
page.rjs_helper_method_from_module
|
|
||||||
page.rjs_helper_method(value)
|
|
||||||
page.sortable(value, :url => { :action => "order" })
|
|
||||||
page.draggable(value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def update_page
|
|
||||||
render :update do |page|
|
|
||||||
page.replace_html 'balance', '$37,000,000.00'
|
|
||||||
page.visual_effect :highlight, 'balance'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def update_page_with_view_method
|
|
||||||
render :update do |page|
|
|
||||||
page.replace_html 'person', pluralize(2, 'person')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def action_talk_to_layout
|
def action_talk_to_layout
|
||||||
# Action template sets variable that's picked up by layout
|
# Action template sets variable that's picked up by layout
|
||||||
end
|
end
|
||||||
|
@ -573,25 +472,6 @@ class TestController < ActionController::Base
|
||||||
head :forbidden, :x_custom_header => "something"
|
head :forbidden, :x_custom_header => "something"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_with_location
|
|
||||||
render :xml => "<hello/>", :location => "http://example.com", :status => 201
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_with_object_location
|
|
||||||
customer = Customer.new("Some guy", 1)
|
|
||||||
render :xml => "<customer/>", :location => customer_url(customer), :status => :created
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_with_to_xml
|
|
||||||
to_xmlable = Class.new do
|
|
||||||
def to_xml
|
|
||||||
"<i-am-xml/>"
|
|
||||||
end
|
|
||||||
end.new
|
|
||||||
|
|
||||||
render :xml => to_xmlable
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_using_layout_around_block
|
def render_using_layout_around_block
|
||||||
render :action => "using_layout_around_block"
|
render :action => "using_layout_around_block"
|
||||||
end
|
end
|
||||||
|
@ -608,22 +488,6 @@ class TestController < ActionController::Base
|
||||||
render :partial => 'partial.html.erb'
|
render :partial => 'partial.html.erb'
|
||||||
end
|
end
|
||||||
|
|
||||||
def partial_as_rjs
|
|
||||||
render :update do |page|
|
|
||||||
page.replace :foo, :partial => 'partial'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def partial
|
def partial
|
||||||
render :partial => 'partial'
|
render :partial => 'partial'
|
||||||
end
|
end
|
||||||
|
@ -880,82 +744,54 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal 'Hello world!', @response.body
|
assert_equal 'Hello world!', @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def test_render_file_with_instance_variables
|
def test_render_file_with_instance_variables
|
||||||
get :render_file_with_instance_variables
|
get :render_file_with_instance_variables
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def test_render_file_as_string_with_instance_variables
|
def test_render_file_as_string_with_instance_variables
|
||||||
get :render_file_as_string_with_instance_variables
|
get :render_file_as_string_with_instance_variables
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def test_render_file_not_using_full_path
|
def test_render_file_not_using_full_path
|
||||||
get :render_file_not_using_full_path
|
get :render_file_not_using_full_path
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def test_render_file_not_using_full_path_with_dot_in_path
|
def test_render_file_not_using_full_path_with_dot_in_path
|
||||||
get :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
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def test_render_file_using_pathname
|
def test_render_file_using_pathname
|
||||||
get :render_file_using_pathname
|
get :render_file_using_pathname
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def test_render_file_with_locals
|
def test_render_file_with_locals
|
||||||
get :render_file_with_locals
|
get :render_file_with_locals
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ported:
|
||||||
def test_render_file_as_string_with_locals
|
def test_render_file_as_string_with_locals
|
||||||
get :render_file_as_string_with_locals
|
get :render_file_as_string_with_locals
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :assessed:
|
||||||
def test_render_file_from_template
|
def test_render_file_from_template
|
||||||
get :render_file_from_template
|
get :render_file_from_template
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_json_nil
|
|
||||||
get :render_json_nil
|
|
||||||
assert_equal 'null', @response.body
|
|
||||||
assert_equal 'application/json', @response.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_render_json
|
|
||||||
get :render_json_hello_world
|
|
||||||
assert_equal '{"hello":"world"}', @response.body
|
|
||||||
assert_equal 'application/json', @response.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_render_json_with_callback
|
|
||||||
get :render_json_hello_world_with_callback
|
|
||||||
assert_equal 'alert({"hello":"world"})', @response.body
|
|
||||||
assert_equal 'application/json', @response.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
get :render_symbol_json
|
|
||||||
assert_equal '{"hello":"world"}', @response.body
|
|
||||||
assert_equal 'application/json', @response.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_render_json_with_render_to_string
|
|
||||||
get :render_json_with_render_to_string
|
|
||||||
assert_equal '{"hello":"partial html"}', @response.body
|
|
||||||
assert_equal 'application/json', @response.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
# :ported:
|
# :ported:
|
||||||
def test_render_custom_code
|
def test_render_custom_code
|
||||||
get :render_custom_code
|
get :render_custom_code
|
||||||
|
@ -964,12 +800,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal 'hello world', @response.body
|
assert_equal 'hello world', @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_custom_code_rjs
|
|
||||||
get :render_custom_code_rjs
|
|
||||||
assert_response 404
|
|
||||||
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
# :ported:
|
# :ported:
|
||||||
def test_render_text_with_nil
|
def test_render_text_with_nil
|
||||||
get :render_text_with_nil
|
get :render_text_with_nil
|
||||||
|
@ -1023,12 +853,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "test", @response.body # name is explicitly set to 'test' inside the controller.
|
assert_equal "test", @response.body # name is explicitly set to 'test' inside the controller.
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_vanilla_js
|
|
||||||
get :render_vanilla_js_hello
|
|
||||||
assert_equal "alert('hello')", @response.body
|
|
||||||
assert_equal "text/javascript", @response.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
# :ported:
|
# :ported:
|
||||||
def test_render_xml
|
def test_render_xml
|
||||||
get :render_xml_hello
|
get :render_xml_hello
|
||||||
|
@ -1053,20 +877,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "<test>\n <hello/>\n</test>\n", @response.body
|
assert_equal "<test>\n <hello/>\n</test>\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enum_rjs_test
|
|
||||||
ActiveSupport::SecureRandom.stubs(:base64).returns("asdf")
|
|
||||||
get :enum_rjs_test
|
|
||||||
body = %{
|
|
||||||
$$(".product").each(function(value, index) {
|
|
||||||
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) + '&authenticity_token=' + encodeURIComponent('asdf')})}});
|
|
||||||
new Draggable(value, {});
|
|
||||||
});
|
|
||||||
}.gsub(/^ /, '').strip
|
|
||||||
assert_equal body, @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_layout_rendering
|
def test_layout_rendering
|
||||||
get :layout_test
|
get :layout_test
|
||||||
assert_equal "<html>Hello world!</html>", @response.body
|
assert_equal "<html>Hello world!</html>", @response.body
|
||||||
|
@ -1114,29 +924,10 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "Goodbye, Local David", @response.body
|
assert_equal "Goodbye, Local David", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_in_an_rjs_template_should_pick_html_templates_when_available
|
|
||||||
[:js, "js"].each do |format|
|
|
||||||
assert_nothing_raised do
|
|
||||||
get :render_implicit_html_template, :format => format
|
|
||||||
assert_equal %(document.write("Hello world\\n");), @response.body
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template
|
|
||||||
[:js, "js"].each do |format|
|
|
||||||
assert_nothing_raised do
|
|
||||||
get :render_explicit_html_template, :format => format
|
|
||||||
assert_equal %(document.write("Hello world\\n");), @response.body
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_should_implicitly_render_html_template_from_xhr_request
|
def test_should_implicitly_render_html_template_from_xhr_request
|
||||||
pending do
|
pending
|
||||||
xhr :get, :render_implicit_html_template_from_xhr_request
|
# xhr :get, :render_implicit_html_template_from_xhr_request
|
||||||
assert_equal "XHR!\nHello HTML!", @response.body
|
# assert_equal "XHR!\nHello HTML!", @response.body
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_implicitly_render_js_template_without_layout
|
def test_should_implicitly_render_js_template_without_layout
|
||||||
|
@ -1151,11 +942,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal 'formatted html erb', @response.body
|
assert_equal 'formatted html erb', @response.body
|
||||||
end
|
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
|
def test_should_render_formatted_html_erb_template
|
||||||
get :formatted_xml_erb
|
get :formatted_xml_erb
|
||||||
assert_equal '<test>passed formatted html erb</test>', @response.body
|
assert_equal '<test>passed formatted html erb</test>', @response.body
|
||||||
|
@ -1167,31 +953,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal '<test>passed formatted html erb</test>', @response.body
|
assert_equal '<test>passed formatted html erb</test>', @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def test_render_with_default_from_accept_header
|
|
||||||
xhr :get, :greeting
|
|
||||||
assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_render_rjs_with_default
|
|
||||||
get :delete_with_js
|
|
||||||
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_render_rjs_template_explicitly
|
|
||||||
get :render_js_with_explicit_template
|
|
||||||
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_rendering_rjs_action_explicitly
|
|
||||||
get :render_js_with_explicit_action_template
|
|
||||||
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_layout_test_with_different_layout
|
def test_layout_test_with_different_layout
|
||||||
get :layout_test_with_different_layout
|
get :layout_test_with_different_layout
|
||||||
assert_equal "<html>Hello world!</html>", @response.body
|
assert_equal "<html>Hello world!</html>", @response.body
|
||||||
|
@ -1299,28 +1060,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "The secret is area51\n", @response.body
|
assert_equal "The secret is area51\n", @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_page
|
|
||||||
get :update_page
|
|
||||||
assert_template nil
|
|
||||||
assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type']
|
|
||||||
assert_equal 2, @response.body.split($/).length
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_update_page_with_instance_variables
|
|
||||||
get :update_page_with_instance_variables
|
|
||||||
assert_template nil
|
|
||||||
assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
|
|
||||||
assert_match /balance/, @response.body
|
|
||||||
assert_match /\$37/, @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_update_page_with_view_method
|
|
||||||
get :update_page_with_view_method
|
|
||||||
assert_template nil
|
|
||||||
assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
|
|
||||||
assert_match /2 people/, @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_yield_content_for
|
def test_yield_content_for
|
||||||
assert_not_deprecated { get :yield_content_for }
|
assert_not_deprecated { get :yield_content_for }
|
||||||
assert_equal "<title>Putting stuff in the title!</title>\n\nGreat stuff!\n", @response.body
|
assert_equal "<title>Putting stuff in the title!</title>\n\nGreat stuff!\n", @response.body
|
||||||
|
@ -1391,31 +1130,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_response :forbidden
|
assert_response :forbidden
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rendering_with_location_should_set_header
|
|
||||||
get :render_with_location
|
|
||||||
assert_equal "http://example.com", @response.headers["Location"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_rendering_xml_should_call_to_xml_if_possible
|
|
||||||
get :render_with_to_xml
|
|
||||||
assert_equal "<i-am-xml/>", @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
get :render_with_object_location
|
|
||||||
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_should_use_implicit_content_type
|
|
||||||
get :implicit_content_type, :format => 'atom'
|
|
||||||
assert_equal Mime::ATOM, @response.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_using_layout_around_block
|
def test_using_layout_around_block
|
||||||
get :render_using_layout_around_block
|
get :render_using_layout_around_block
|
||||||
assert_equal "Before (David)\nInside from block\nAfter", @response.body
|
assert_equal "Before (David)\nInside from block\nAfter", @response.body
|
||||||
|
@ -1446,26 +1160,6 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal 'partial html', @response.body
|
assert_equal 'partial html', @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_render_html_formatted_partial_with_rjs
|
|
||||||
xhr :get, :partial_as_rjs
|
|
||||||
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def test_should_render_js_partial
|
|
||||||
xhr :get, :partial, :format => 'js'
|
|
||||||
assert_equal 'partial js', @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_should_render_with_alternate_default_render
|
|
||||||
xhr :get, :render_alternate_default
|
|
||||||
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_partial_only_with_layout
|
def test_partial_only_with_layout
|
||||||
get :partial_only_with_layout
|
get :partial_only_with_layout
|
||||||
assert_equal "<html>only partial</html>", @response.body
|
assert_equal "<html>only partial</html>", @response.body
|
||||||
|
|
81
actionpack/test/controller/render_xml_test.rb
Normal file
81
actionpack/test/controller/render_xml_test.rb
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
require 'abstract_unit'
|
||||||
|
require 'controller/fake_models'
|
||||||
|
require 'pathname'
|
||||||
|
|
||||||
|
class TestController < ActionController::Base
|
||||||
|
protect_from_forgery
|
||||||
|
|
||||||
|
def render_with_location
|
||||||
|
render :xml => "<hello/>", :location => "http://example.com", :status => 201
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_with_object_location
|
||||||
|
customer = Customer.new("Some guy", 1)
|
||||||
|
render :xml => "<customer/>", :location => customer_url(customer), :status => :created
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_with_to_xml
|
||||||
|
to_xmlable = Class.new do
|
||||||
|
def to_xml
|
||||||
|
"<i-am-xml/>"
|
||||||
|
end
|
||||||
|
end.new
|
||||||
|
|
||||||
|
render :xml => to_xmlable
|
||||||
|
end
|
||||||
|
|
||||||
|
def formatted_xml_erb
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_xml_with_custom_content_type
|
||||||
|
render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class RenderTest < ActionController::TestCase
|
||||||
|
tests TestController
|
||||||
|
|
||||||
|
def setup
|
||||||
|
# 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".
|
||||||
|
super
|
||||||
|
@controller.logger = Logger.new(nil)
|
||||||
|
|
||||||
|
@request.host = "www.nextangle.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rendering_with_location_should_set_header
|
||||||
|
get :render_with_location
|
||||||
|
assert_equal "http://example.com", @response.headers["Location"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rendering_xml_should_call_to_xml_if_possible
|
||||||
|
get :render_with_to_xml
|
||||||
|
assert_equal "<i-am-xml/>", @response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
get :render_with_object_location
|
||||||
|
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
|
||||||
|
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_xml_but_keep_custom_content_type
|
||||||
|
get :render_xml_with_custom_content_type
|
||||||
|
assert_equal "application/atomsvc+xml", @response.content_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_use_implicit_content_type
|
||||||
|
get :implicit_content_type, :format => 'atom'
|
||||||
|
assert_equal Mime::ATOM, @response.content_type
|
||||||
|
end
|
||||||
|
end
|
110
actionpack/test/new_base/render_file_test.rb
Normal file
110
actionpack/test/new_base/render_file_test.rb
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||||
|
|
||||||
|
module RenderFile
|
||||||
|
|
||||||
|
class BasicController < ActionController::Base
|
||||||
|
self.view_paths = "."
|
||||||
|
|
||||||
|
def index
|
||||||
|
render :file => File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world])
|
||||||
|
end
|
||||||
|
|
||||||
|
def with_instance_variables
|
||||||
|
@secret = 'in the sauce'
|
||||||
|
render :file => File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
|
||||||
|
end
|
||||||
|
|
||||||
|
def without_file_key
|
||||||
|
render File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world])
|
||||||
|
end
|
||||||
|
|
||||||
|
def without_file_key_with_instance_variable
|
||||||
|
@secret = 'in the sauce'
|
||||||
|
render File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
|
||||||
|
end
|
||||||
|
|
||||||
|
def relative_path
|
||||||
|
@secret = 'in the sauce'
|
||||||
|
render :file => '../fixtures/test/render_file_with_ivar'
|
||||||
|
end
|
||||||
|
|
||||||
|
def relative_path_with_dot
|
||||||
|
@secret = 'in the sauce'
|
||||||
|
render :file => '../fixtures/test/dot.directory/render_file_with_ivar'
|
||||||
|
end
|
||||||
|
|
||||||
|
def pathname
|
||||||
|
@secret = 'in the sauce'
|
||||||
|
render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. fixtures test dot.directory render_file_with_ivar.erb])
|
||||||
|
end
|
||||||
|
|
||||||
|
def with_locals
|
||||||
|
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
|
||||||
|
render :file => path, :locals => {:secret => 'in the sauce'}
|
||||||
|
end
|
||||||
|
|
||||||
|
def without_file_key_with_locals
|
||||||
|
path = File.expand_path('../fixtures/test/render_file_with_locals.erb')
|
||||||
|
render path, :locals => {:secret => 'in the sauce'}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class TestBasic < SimpleRouteCase
|
||||||
|
testing RenderFile::BasicController
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@old_pwd = Dir.pwd
|
||||||
|
Dir.chdir(File.dirname(__FILE__))
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
Dir.chdir(@old_pwd)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering simple template" do
|
||||||
|
get :index
|
||||||
|
assert_response "Hello world!"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering template with ivar" do
|
||||||
|
get :with_instance_variables
|
||||||
|
assert_response "The secret is in the sauce\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering path without specifying the :file key" do
|
||||||
|
get :without_file_key
|
||||||
|
assert_response "Hello world!"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering path without specifying the :file key with ivar" do
|
||||||
|
get :without_file_key_with_instance_variable
|
||||||
|
assert_response "The secret is in the sauce\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering a relative path" do
|
||||||
|
get :relative_path
|
||||||
|
assert_response "The secret is in the sauce\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering a relative path with dot" do
|
||||||
|
get :relative_path_with_dot
|
||||||
|
assert_response "The secret is in the sauce\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering a Pathname" do
|
||||||
|
get :pathname
|
||||||
|
assert_response "The secret is in the sauce\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering file with locals" do
|
||||||
|
get :with_locals
|
||||||
|
assert_response "The secret is in the sauce\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rendering path without specifying the :file key with locals" do
|
||||||
|
get :without_file_key_with_locals
|
||||||
|
assert_response "The secret is in the sauce\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -6,7 +6,8 @@ module ControllerLayouts
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||||
"layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI",
|
"layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI",
|
||||||
"layouts/override.html.erb" => "Override! <%= yield %>",
|
"layouts/override.html.erb" => "Override! <%= yield %>",
|
||||||
"basic.html.erb" => "Hello world!"
|
"basic.html.erb" => "Hello world!",
|
||||||
|
"controller_layouts/implicit/layout_false.html.erb" => "hai(layout_false.html.erb)"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -17,6 +18,12 @@ module ControllerLayouts
|
||||||
render :template => "basic", :layout => "override"
|
render :template => "basic", :layout => "override"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def layout_false
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def builder_override
|
def builder_override
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -56,4 +63,13 @@ module ControllerLayouts
|
||||||
get "/controller_layouts/implicit/override"
|
get "/controller_layouts/implicit/override"
|
||||||
assert_body "Override! Hello world!"
|
assert_body "Override! Hello world!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class TestLayoutOptions < SimpleRouteCase
|
||||||
|
testing ControllerLayouts::ImplicitController
|
||||||
|
|
||||||
|
test "rendering with :layout => false leaves out the implicit layout" do
|
||||||
|
get :layout_false
|
||||||
|
assert_response "hai(layout_false.html.erb)"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -59,12 +59,28 @@ class Rack::TestCase < ActiveSupport::TestCase
|
||||||
@app ||= ActionController::Dispatcher.new
|
@app ||= ActionController::Dispatcher.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.testing(klass = nil)
|
||||||
|
if klass
|
||||||
|
@testing = "/#{klass.name.underscore}".sub!(/_controller$/, '')
|
||||||
|
else
|
||||||
|
@testing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.get(url)
|
def self.get(url)
|
||||||
setup do |test|
|
setup do |test|
|
||||||
test.get url
|
test.get url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get(thing, *args)
|
||||||
|
if thing.is_a?(Symbol)
|
||||||
|
super("#{self.class.testing}/#{thing}")
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def assert_body(body)
|
def assert_body(body)
|
||||||
assert_equal body, Array.wrap(last_response.body).join
|
assert_equal body, Array.wrap(last_response.body).join
|
||||||
end
|
end
|
||||||
|
@ -85,6 +101,14 @@ class Rack::TestCase < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_response(body, status = 200, headers = {})
|
||||||
|
assert_body body
|
||||||
|
assert_status status
|
||||||
|
headers.each do |header, value|
|
||||||
|
assert_header header, value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def assert_content_type(type)
|
def assert_content_type(type)
|
||||||
assert_equal type, last_response.headers["Content-Type"]
|
assert_equal type, last_response.headers["Content-Type"]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue