Skip to content

Commit

Permalink
assert_template fails with empty string when a template has been re…
Browse files Browse the repository at this point in the history
…ndered

For instance, it prevents false positive in this case:

    file = nil
    get :index
    assert_template("#{file}")
  • Loading branch information
roberto committed Nov 23, 2012
1 parent 36ee580 commit 20723ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##

* `assert_template` is no more passing with empty string when some template has been rendered.

*Roberto Soares*

* Allow setting a symbol as path in scope on routes. This is now allowed:

scope :api do
Expand Down
12 changes: 8 additions & 4 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -94,10 +94,14 @@ def assert_template(options = {}, message = nil)
matches_template =
case options
when String
rendered.any? do |t, num|
options_splited = options.split(File::SEPARATOR)
t_splited = t.split(File::SEPARATOR)
t_splited.last(options_splited.size) == options_splited
if options.empty?
rendered.blank?
else
rendered.any? do |t, num|
options_splited = options.split(File::SEPARATOR)
t_splited = t.split(File::SEPARATOR)
t_splited.last(options_splited.size) == options_splited
end
end
when Regexp
rendered.any? { |t,num| t.match(options) }
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/action_pack_assertions_test.rb
Expand Up @@ -447,6 +447,13 @@ def test_with_nil_fails_when_template_rendered
end
end

def test_with_empty_string_fails_when_template_rendered
get :hello_world
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_template ""
end
end

def test_passes_with_correct_string
get :hello_world
assert_template 'hello_world'
Expand Down

0 comments on commit 20723ca

Please sign in to comment.