提交 19dff78d 编写于 作者: H Hugo Roque

`assert_template` no more passing with what ever string that matches.

Given Im rendering an template `/layout/hello.html.erb`, assert_template was
passing with any string that matches. This behavior allowed false passing like:

	assert_template "layout"
	assert_template "out/hello"

Now the passing possibilities are:

	assert_template "layout/hello"
	assert_template "hello"

fixing assert_template bug when template matches expected, but not ends with

Cherry Pick Merge: Fixes issue #3849 assert_template false positive

taking redundant test off

prevening incorrect assert_template when rendering with repeated names in path

updating CHANGELOG with bugfix: assert_template false passing
上级 f655108c
## Rails 4.0.0 (unreleased) ##
* `assert_template` no more passing with what ever string that matches.
Given Im rendering an template `/layout/hello.html.erb`, assert_template was
passing with any string that matches. This behavior allowed false passing like:
assert_template "layout"
assert_template "out/hello"
Now the passing possibilities are:
assert_template "layout/hello"
assert_template "hello"
*Hugolnx*
* `image_tag` will set the same width and height for image if numerical value
passed to `size` option.
......
......@@ -86,16 +86,23 @@ def assert_template(options = {}, message = nil)
response.body
case options
when NilClass, String, Symbol, Regexp
when NilClass, Regexp, String, Symbol
options = options.to_s if Symbol === options
rendered = @templates
msg = message || sprintf("expecting <%s> but rendering with <%s>",
options.inspect, rendered.keys)
matches_template =
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
assert matches_template, msg
when Hash
......
......@@ -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
......@@ -464,6 +465,20 @@ 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
......@@ -471,6 +486,13 @@ def test_fails_with_incorrect_symbol
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
......
Hello world!
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册