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
This commit is contained in:
Carlos Antonio da Silva 2012-11-26 02:41:45 -08:00
commit 02c30c6426
3 changed files with 11 additions and 1 deletions

@ -1,6 +1,8 @@
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* `assert_template` is no more passing with empty string. * `assert_template`:
- is no more passing with empty string.
- is now validating option keys. It accepts: `:layout`, `:partial`, `:locals` and `:count`.
*Roberto Soares* *Roberto Soares*

@ -106,6 +106,8 @@ def assert_template(options = {}, message = nil)
end end
assert matches_template, msg assert matches_template, msg
when Hash when Hash
options.assert_valid_keys(:layout, :partial, :locals, :count)
if options.key?(:layout) if options.key?(:layout)
expected_layout = options[:layout] expected_layout = options[:layout]
msg = message || sprintf("expecting layout <%s> but action rendered <%s>", msg = message || sprintf("expecting layout <%s> but action rendered <%s>",

@ -430,6 +430,12 @@ def test_assert_response_failure_response_with_no_exception
class AssertTemplateTest < ActionController::TestCase class AssertTemplateTest < ActionController::TestCase
tests ActionPackAssertionsController tests ActionPackAssertionsController
def test_with_invalid_hash_keys_raises_argument_error
assert_raise(ArgumentError) do
assert_template foo: "bar"
end
end
def test_with_partial def test_with_partial
get :partial get :partial
assert_template :partial => '_partial' assert_template :partial => '_partial'