Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow assert_template to take a symbol [#2011 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit f383a4aa333cd8a99003eb1bdbb27b6fdea1056c 1 parent 14b7698
Mike Breen hardbap authored lifo committed
9 actionpack/lib/action_controller/assertions/response_assertions.rb
View
@@ -85,6 +85,9 @@ def assert_redirected_to(options = {}, message=nil)
# # assert that the "new" view template was rendered
# assert_template "new"
#
+ # # assert that the "new" view template was rendered with Symbol
+ # assert_template :new
+ #
# # assert that the "_customer" partial was rendered twice
# assert_template :partial => '_customer', :count => 2
#
@@ -94,7 +97,7 @@ def assert_redirected_to(options = {}, message=nil)
def assert_template(options = {}, message = nil)
clean_backtrace do
case options
- when NilClass, String
+ when NilClass, String, Symbol
rendered = @response.rendered[:template].to_s
msg = build_message(message,
"expecting <?> but rendering with <?>",
@@ -103,7 +106,7 @@ def assert_template(options = {}, message = nil)
if options.nil?
@response.rendered[:template].blank?
else
- rendered.to_s.match(options)
+ rendered.to_s.match(options.to_s)
end
end
when Hash
@@ -126,6 +129,8 @@ def assert_template(options = {}, message = nil)
assert @response.rendered[:partials].empty?,
"Expected no partials to be rendered"
end
+ else
+ raise ArgumentError
end
end
end
27 actionpack/test/controller/action_pack_assertions_test.rb
View
@@ -11,6 +11,9 @@ def hello_world() render :template => "test/hello_world"; end
# a standard template
def hello_xml_world() render :template => "test/hello_xml_world"; end
+
+ # a standard partial
+ def partial() render :partial => 'test/partial'; end
# a redirect to an internal location
def redirect_internal() redirect_to "/nothing"; end
@@ -332,6 +335,30 @@ def test_rendered_action
assert @response.rendered[:template]
assert 'hello_world', @response.rendered[:template].to_s
end
+
+ def test_assert_template_with_partial
+ get :partial
+ assert_template :partial => '_partial'
+ end
+
+ def test_assert_template_with_nil
+ get :nothing
+ assert_template nil
+ end
+
+ def test_assert_template_with_string
+ get :hello_world
+ assert_template 'hello_world'
+ end
+
+ def test_assert_template_with_symbol
+ get :hello_world
+ assert_template :hello_world
+ end
+
+ def test_assert_template_with_bad_argument
+ assert_raise(ArgumentError) { assert_template 1 }
+ end
# check the redirection location
def test_redirection_location
Please sign in to comment.
Something went wrong with that request. Please try again.