From 3ef3ef1ca9defb1f00a5c0b66eab8d42315c7eaa Mon Sep 17 00:00:00 2001 From: Mike Breen Date: Mon, 16 Mar 2009 07:11:16 -0400 Subject: [PATCH] allow assert_template to take a symbol --- .../assertions/response_assertions.rb | 9 +++++- .../test/controller/action_pack_assertions_test.rb | 27 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/assertions/response_assertions.rb b/actionpack/lib/action_controller/assertions/response_assertions.rb index 5976090..a0bd260 100644 --- a/actionpack/lib/action_controller/assertions/response_assertions.rb +++ b/actionpack/lib/action_controller/assertions/response_assertions.rb @@ -82,6 +82,9 @@ module ActionController # # 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 # @@ -91,7 +94,7 @@ module ActionController 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 ", @@ -100,7 +103,7 @@ module ActionController if options.nil? @response.rendered[:template].blank? else - rendered.to_s.match(options) + rendered.to_s.match(options.to_s) end end when Hash @@ -123,6 +126,8 @@ module ActionController assert @response.rendered[:partials].empty?, "Expected no partials to be rendered" end + else + raise ArgumentError end end end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index cb7922e..6e92eff 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -11,6 +11,9 @@ class ActionPackAssertionsController < ActionController::Base # 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 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase 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 -- 1.6.1.3