Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

assert_template: validating option keys #8316

Merged
merged 1 commit into from

3 participants

@roberto

assert_template is only handling the keys locals, partial, layout and count(thx @carlosantoniodasilva) , anything else never fails or passes, giving false positives.

assert_template(foo: "bar") # it isn't raising anything and "passes"
assert_template(leiaute: "test") # misspelled option, same issue

Change: I've added assert_valid_keys to raise ArgumentError in those cases.

assert_template(foo: "bar") # raises ArgumentError
assert_template(leiaute: "test") # raises ArgumentError

Thanks!

@carlosantoniodasilva carlosantoniodasilva merged commit 02c30c6 into rails:master
@carlosantoniodasilva

Thanks!

@rafaelfranca

Thanks

@roberto

Thank you, guys!

@jcoyne jcoyne referenced this pull request from a commit in jcoyne/rails
@jcoyne jcoyne Allow testing of assert_template with the :file option.
This is a patch for a regression introduced in #8316
870dcb8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 26, 2012
  1. @roberto
This page is out of date. Refresh to see the latest.
View
4 actionpack/CHANGELOG.md
@@ -1,6 +1,8 @@
## 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*
View
2  actionpack/lib/action_controller/test_case.rb
@@ -106,6 +106,8 @@ def assert_template(options = {}, message = nil)
end
assert matches_template, msg
when Hash
+ options.assert_valid_keys(:layout, :partial, :locals, :count)
+
if options.key?(:layout)
expected_layout = options[:layout]
msg = message || sprintf("expecting layout <%s> but action rendered <%s>",
View
6 actionpack/test/controller/action_pack_assertions_test.rb
@@ -430,6 +430,12 @@ def test_assert_response_failure_response_with_no_exception
class AssertTemplateTest < ActionController::TestCase
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
get :partial
assert_template :partial => '_partial'
Something went wrong with that request. Please try again.