Browse files

Merge pull request #7848 from senny/3415_assert_template_has_nil_vari…

…able

can't pass :locals to #assert_template without a view test case (#3415)
  • Loading branch information...
2 parents 05e9258 + af677da commit bcbf1bbba439346b9b16e9b3dbc417d4e3abb717 @rafaelfranca rafaelfranca committed Oct 6, 2012
View
7 actionpack/CHANGELOG.md
@@ -1,6 +1,11 @@
## Rails 4.0.0 (unreleased) ##
-* The `Rack::Cache` middleware is now disabled by default. To enable it,
+* Warn when the `:locals` option is passed to `assert_template` outside of a view test case
+ Fix #3415
+
+ *Yves Senn*
+
+* The `Rack::Cache` middleware is now disabled by default. To enable it,
set `config.action_dispatch.rack_cache = true` and add `gem rack-cache` to your Gemfile.
*Guillermo Iguaran*
View
10 actionpack/lib/action_controller/test_case.rb
@@ -123,9 +123,13 @@ def assert_template(options = {}, message = nil)
if expected_partial = options[:partial]
if expected_locals = options[:locals]
- actual_locals = @locals[expected_partial.to_s.sub(/^_/,'')]
- expected_locals.each_pair do |k,v|
- assert_equal(v, actual_locals[k])
+ if defined?(@locals)
+ actual_locals = @locals[expected_partial.to_s.sub(/^_/,'')]
+ expected_locals.each_pair do |k,v|
+ assert_equal(v, actual_locals[k])
+ end
+ else
+ warn "the :locals option to #assert_template is only supported in a ActionView::TestCase"
end
elsif expected_count = options[:count]
actual_count = @_partials[expected_partial]
View
11 actionpack/test/controller/render_test.rb
@@ -1428,6 +1428,17 @@ def test_partial_collection_with_locals
assert_equal "Bonjour: davidBonjour: mary", @response.body
end
+ def test_locals_option_to_assert_template_is_not_supported
+ warning_buffer = StringIO.new
+ $stderr = warning_buffer
+
+ get :partial_collection_with_locals
+ assert_template partial: 'customer_greeting', locals: { greeting: 'Bonjour' }
+ assert_equal "the :locals option to #assert_template is only supported in a ActionView::TestCase\n", warning_buffer.string
+ ensure
+ $stderr = STDERR
+ end
+
def test_partial_collection_with_spacer
get :partial_collection_with_spacer
assert_equal "Hello: davidonly partialHello: mary", @response.body

0 comments on commit bcbf1bb

Please sign in to comment.