Skip to content
This repository
Browse code

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 authored March 16, 2009 lifo committed May 17, 2009
9  actionpack/lib/action_controller/assertions/response_assertions.rb
@@ -85,6 +85,9 @@ def assert_redirected_to(options = {}, message=nil)
85 85
       #   # assert that the "new" view template was rendered
86 86
       #   assert_template "new"
87 87
       #
  88
+      #   # assert that the "new" view template was rendered with Symbol
  89
+      #   assert_template :new
  90
+      #
88 91
       #   # assert that the "_customer" partial was rendered twice
89 92
       #   assert_template :partial => '_customer', :count => 2
90 93
       #
@@ -94,7 +97,7 @@ def assert_redirected_to(options = {}, message=nil)
94 97
       def assert_template(options = {}, message = nil)
95 98
         clean_backtrace do
96 99
           case options
97  
-           when NilClass, String
  100
+           when NilClass, String, Symbol
98 101
             rendered = @response.rendered[:template].to_s
99 102
             msg = build_message(message,
100 103
                     "expecting <?> but rendering with <?>",
@@ -103,7 +106,7 @@ def assert_template(options = {}, message = nil)
103 106
               if options.nil?
104 107
                 @response.rendered[:template].blank?
105 108
               else
106  
-                rendered.to_s.match(options)
  109
+                rendered.to_s.match(options.to_s)
107 110
               end
108 111
             end
109 112
           when Hash
@@ -126,6 +129,8 @@ def assert_template(options = {}, message = nil)
126 129
               assert @response.rendered[:partials].empty?,
127 130
                 "Expected no partials to be rendered"
128 131
             end
  132
+          else
  133
+            raise ArgumentError  
129 134
           end
130 135
         end
131 136
       end
27  actionpack/test/controller/action_pack_assertions_test.rb
@@ -11,6 +11,9 @@ def hello_world() render :template => "test/hello_world"; end
11 11
 
12 12
   # a standard template
13 13
   def hello_xml_world() render :template => "test/hello_xml_world"; end
  14
+  
  15
+  # a standard partial
  16
+  def partial() render :partial => 'test/partial'; end
14 17
 
15 18
   # a redirect to an internal location
16 19
   def redirect_internal() redirect_to "/nothing"; end
@@ -332,6 +335,30 @@ def test_rendered_action
332 335
     assert @response.rendered[:template]
333 336
     assert 'hello_world', @response.rendered[:template].to_s
334 337
   end
  338
+  
  339
+  def test_assert_template_with_partial
  340
+    get :partial
  341
+    assert_template :partial => '_partial'
  342
+  end
  343
+  
  344
+  def test_assert_template_with_nil
  345
+    get :nothing
  346
+    assert_template nil
  347
+  end
  348
+  
  349
+  def test_assert_template_with_string
  350
+    get :hello_world
  351
+    assert_template 'hello_world'    
  352
+  end
  353
+  
  354
+  def test_assert_template_with_symbol
  355
+    get :hello_world
  356
+    assert_template :hello_world
  357
+  end
  358
+  
  359
+  def test_assert_template_with_bad_argument
  360
+    assert_raise(ArgumentError) { assert_template 1 }    
  361
+  end
335 362
 
336 363
   # check the redirection location
337 364
   def test_redirection_location

0 notes on commit f383a4a

Please sign in to comment.
Something went wrong with that request. Please try again.