Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix: assert_template shouldn't search for partial matches #3879

Closed
wants to merge 4 commits into from

3 participants

Sandeep Fabrizio Regini sandeepr-sourcebits
Sandeep

assert_template searches for matches anywhere in the path.

Changed this so that the method search only at the end of the template path.

Fabrizio Regini

Hi, looks like we've been working on the same thing:
freegenie@197b7ce

Fabrizio Regini

Your test is passing with 'hello' string, but it fails if you assert a template named 'world'

Sandeep

Hey,

Yes! it does look like it. I just happened to use assert_template in my application and it gave a false positive which was weird.
And yea, my fix may also give false positives in cases like you mentioned where there is matching part at the end of the string but I think it's cleaner code to have a regex match here.

Fabrizio Regini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  actionpack/lib/action_controller/test_case.rb
View
@@ -84,7 +84,7 @@ def assert_template(options = {}, message = nil)
options.inspect, rendered.keys)
assert_block(msg) do
if options
- rendered.any? { |t,num| t.match(options) }
+ rendered.any? { |t,num| t.match(options + "$") }
else
@templates.blank?
end
7 actionpack/test/controller/action_pack_assertions_test.rb
View
@@ -481,6 +481,13 @@ def test_assert_template_reset_between_requests
get :nothing
assert_template nil
end
+
+ def test_fails_with_partially_matching_string
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template 'hello'
+ end
+ end
end
class ActionPackHeaderTest < ActionController::TestCase
2  activesupport/test/file_update_checker_test.rb
View
@@ -86,7 +86,7 @@ def test_should_not_block_if_a_strange_filename_used
FileUtils.touch(FILES.map { |file_name| "tmp_watcher/valid,yetstrange,path,/#{file_name}" } )
test = Thread.new do
- checker = ActiveSupport::FileUpdateChecker.new([],"tmp_watcher/valid,yetstrange,path," => :txt){ i += 1 }
+ ActiveSupport::FileUpdateChecker.new([],"tmp_watcher/valid,yetstrange,path," => :txt){ i += 1 }
Thread.exit
end
test.priority = -1
Something went wrong with that request. Please try again.