Skip to content
This repository
Browse code

Merge pull request #8316 from roberto/assert_template_validate_options

assert_template: validating option keys

It only handles the keys locals, partial, layout and count.

    assert_template(foo: "bar") # raises ArgumentError
    assert_template(leiaute: "test") # raises ArgumentError
  • Loading branch information...
commit 02c30c64262fd9e1625bc7f3723729c4e62e610b 2 parents 1081ae2 + 3f2c011
Carlos Antonio da Silva carlosantoniodasilva authored
4 actionpack/CHANGELOG.md
Source Rendered
... ... @@ -1,6 +1,8 @@
1 1 ## Rails 4.0.0 (unreleased) ##
2 2
3   -* `assert_template` is no more passing with empty string.
  3 +* `assert_template`:
  4 + - is no more passing with empty string.
  5 + - is now validating option keys. It accepts: `:layout`, `:partial`, `:locals` and `:count`.
4 6
5 7 *Roberto Soares*
6 8
2  actionpack/lib/action_controller/test_case.rb
@@ -106,6 +106,8 @@ def assert_template(options = {}, message = nil)
106 106 end
107 107 assert matches_template, msg
108 108 when Hash
  109 + options.assert_valid_keys(:layout, :partial, :locals, :count)
  110 +
109 111 if options.key?(:layout)
110 112 expected_layout = options[:layout]
111 113 msg = message || sprintf("expecting layout <%s> but action rendered <%s>",
6 actionpack/test/controller/action_pack_assertions_test.rb
@@ -430,6 +430,12 @@ def test_assert_response_failure_response_with_no_exception
430 430 class AssertTemplateTest < ActionController::TestCase
431 431 tests ActionPackAssertionsController
432 432
  433 + def test_with_invalid_hash_keys_raises_argument_error
  434 + assert_raise(ArgumentError) do
  435 + assert_template foo: "bar"
  436 + end
  437 + end
  438 +
433 439 def test_with_partial
434 440 get :partial
435 441 assert_template :partial => '_partial'

0 comments on commit 02c30c6

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