aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/render_test.rb
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-08-11 15:02:05 -0700
committerYehuda Katz <wycats@gmail.com>2009-08-15 12:32:01 -0700
commit27adcd1c1a5cc566cfa8c5f8268b65ef01a7e865 (patch)
tree2e732c3909ec5a6a72e3dbcace8d0fdd2d57cc3d /actionpack/test/template/render_test.rb
parenta363dba790d9d9f6284f7f857d872eca124805ee (diff)
downloadrails-27adcd1c1a5cc566cfa8c5f8268b65ef01a7e865.tar.gz
rails-27adcd1c1a5cc566cfa8c5f8268b65ef01a7e865.tar.bz2
rails-27adcd1c1a5cc566cfa8c5f8268b65ef01a7e865.zip
Clean up ActionView some:
* Call _evaluate_assigns_and_ivars at the two entry points so we don't have to do a check at every render. * Make template.render viable without having to go through a wrapper method * Remove old TemplateHandler#render(template, local_assigns) path so we don't have to set self.template every time we render a template. * Move Template rescuing code to Template#render so it gets caught every time. * Pull in some tests from Pratik that test render @object in ActionView
Diffstat (limited to 'actionpack/test/template/render_test.rb')
-rw-r--r--actionpack/test/template/render_test.rb34
1 files changed, 23 insertions, 11 deletions
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 7f30ae88a1..50074b3b9d 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -2,10 +2,14 @@
require 'abstract_unit'
require 'controller/fake_models'
+class TestController < ActionController::Base
+end
+
module RenderTestCases
def setup_view(paths)
@assigns = { :secret => 'in the sauce' }
@view = ActionView::Base.new(paths, @assigns)
+ @controller_view = ActionView::Base.for_controller(TestController.new)
# Reload and register danish language for testing
I18n.reload!
@@ -158,6 +162,25 @@ module RenderTestCases
assert_nil @view.render(:partial => [])
end
+ def test_render_partial_using_string
+ assert_equal "Hello: Anonymous", @controller_view.render('customer')
+ end
+
+ def test_render_partial_with_locals_using_string
+ assert_equal "Hola: david", @controller_view.render('customer_greeting', :greeting => 'Hola', :customer_greeting => Customer.new("david"))
+ end
+
+ def test_render_partial_using_object
+ assert_equal "Hello: lifo",
+ @controller_view.render(Customer.new("lifo"), :greeting => "Hello")
+ end
+
+ def test_render_partial_using_collection
+ customers = [ Customer.new("Amazon"), Customer.new("Yahoo") ]
+ assert_equal "Hello: AmazonHello: Yahoo",
+ @controller_view.render(customers, :greeting => "Hello")
+ end
+
# TODO: The reason for this test is unclear, improve documentation
def test_render_partial_and_fallback_to_layout
assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
@@ -196,17 +219,6 @@ module RenderTestCases
assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
end
- class LegacyHandler < ActionView::TemplateHandler
- def render(template, local_assigns)
- "source: #{template.source}; locals: #{local_assigns.inspect}"
- end
- end
-
- def test_render_legacy_handler_with_custom_type
- ActionView::Template.register_template_handler :foo, LegacyHandler
- assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
- end
-
def test_render_ignores_templates_with_malformed_template_handlers
%w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
assert_raise(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") }