Skip to content

Instantly share code, notes, and snippets.

@lifo
Created August 11, 2009 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifo/166016 to your computer and use it in GitHub Desktop.
Save lifo/166016 to your computer and use it in GitHub Desktop.
commit 3caaafd3518ece4fe62b8aca8382ac70b3235be0
Author: Pratik Naik <pratiknaik@gmail.com>
Date: Tue Aug 11 19:18:39 2009 +0100
Add more tests for rendering partials inside views
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 7f30ae8..09ff70d 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,23 @@ 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"))
+ end
+
+ def test_render_partial_using_collection
+ customers = [ Customer.new("Amazon"), Customer.new("Yahoo") ]
+ assert_equal "Hello: AmazonHello: Yahoo", @controller_view.render(customers)
+ 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" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment