Permalink
Browse files

Merge pull request #7659 from HugoLnx/template_error_no_matches_rebased

REBASED: fixing assert_template bug when template matches expected, but not ends with
Conflicts:
	actionpack/CHANGELOG.md
	actionpack/lib/action_controller/test_case.rb
  • Loading branch information...
1 parent c2a7084 commit 7d17cd2cbfc086f5aa9dd636e1207eb130150428 @rafaelfranca rafaelfranca committed Sep 30, 2012
View
19 actionpack/CHANGELOG.md
@@ -1,5 +1,24 @@
## Rails 3.2.9 (unreleased) ##
+* `assert_template` is no more passing with what ever string that matches
+ with the template name.
+
+ Before when we have a template `/layout/hello.html.erb`, `assert_template`
+ was passing with any string that matches. This behavior allowed false
+ positive like:
+
+ assert_template "layout"
+ assert_template "out/hello"
+
+ Now it only passes with:
+
+ assert_template "layout/hello"
+ assert_template "hello"
+
+ Fixes #3849.
+
+ *Hugolnx*
+
* Fixed a bug with shorthand routes scoped with the `:module` option not
adding the module to the controller as described in issue #6497.
This should now work properly:
View
19 actionpack/lib/action_controller/test_case.rb
@@ -72,19 +72,26 @@ def assert_template(options = {}, message = nil)
validate_request!
case options
- when NilClass, String, Symbol
+ when NilClass, Regexp, String, Symbol
options = options.to_s if Symbol === options
rendered = @templates
msg = build_message(message,
"expecting <?> but rendering with <?>",
options, rendered.keys.join(', '))
- assert_block(msg) do
- if options
+ 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
+ end
+ when Regexp
rendered.any? { |t,num| t.match(options) }
- else
- @templates.blank?
+ when NilClass
+ rendered.blank?
end
- end
+ assert matches_template, msg
when Hash
if expected_layout = options[:layout]
msg = build_message(message,
View
22 actionpack/test/controller/action_pack_assertions_test.rb
@@ -7,6 +7,7 @@ class ActionPackAssertionsController < ActionController::Base
def nothing() head :ok end
def hello_world() render :template => "test/hello_world"; end
+ def hello_repeating_in_path() render :template => "test/hello/hello"; end
def hello_xml_world() render :template => "test/hello_xml_world"; end
@@ -469,13 +470,34 @@ def test_fails_with_incorrect_string
end
end
+ def test_fails_with_incorrect_string_that_matches
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template 'est/he'
+ end
+ end
+
+ def test_fails_with_repeated_name_in_path
+ get :hello_repeating_in_path
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template 'test/hello'
+ end
+ end
+
def test_fails_with_incorrect_symbol
get :hello_world
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_template :hello_planet
end
end
+ def test_fails_with_incorrect_symbol_that_matches
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template :"est/he"
+ end
+ end
+
def test_fails_with_wrong_layout
get :render_with_layout
assert_raise(ActiveSupport::TestCase::Assertion) do
View
1 actionpack/test/fixtures/test/hello/hello.erb
@@ -0,0 +1 @@
+Hello world!

0 comments on commit 7d17cd2

Please sign in to comment.