提交 c85fed05 编写于 作者: A Angelo capilleri 提交者: Rafael Mendonça França

fix error message of option as with invalid charters in partial rendering

before this PR IDENTIFIER_ERROR_MESSAGE could lead to misunderstand the convention of partial name.
Added OPTION_AS_ERROR_MESSAGE for unvalid charter in as option.
上级 c0329b3d
* Added an explicit error message, in `ActionView::PartialRenderer`
for partial `rendering`, when the value of option `as` has invalid characters.
*Angelo Capilleri*
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/actionview/CHANGELOG.md) for previous changes.
......@@ -384,7 +384,7 @@ def setup(context, options, block)
end
if as = options[:as]
raise_invalid_identifier(as) unless as.to_s =~ /\A[a-z_]\w*\z/
raise_invalid_option_as(as) unless as.to_s =~ /\A[a-z_]\w*\z/
as = as.to_sym
end
......@@ -530,11 +530,19 @@ def retrieve_variable(path, as)
end
IDENTIFIER_ERROR_MESSAGE = "The partial name (%s) is not a valid Ruby identifier; " +
"make sure your partial name starts with a lowercase letter or underscore, " +
"make sure your partial name starts with underscore, " +
"and is followed by any combination of letters, numbers and underscores."
OPTION_AS_ERROR_MESSAGE = "The value (%s) of the option `as` is not a valid Ruby identifier; " +
"make sure it starts with lowercase letter, " +
"and is followed by any combination of letters, numbers and underscores."
def raise_invalid_identifier(path)
raise ArgumentError.new(IDENTIFIER_ERROR_MESSAGE % (path))
end
def raise_invalid_option_as(as)
raise ArgumentError.new(OPTION_AS_ERROR_MESSAGE % (as))
end
end
end
......@@ -175,14 +175,14 @@ def test_render_partial_with_locals_from_default
def test_render_partial_with_invalid_name
e = assert_raises(ArgumentError) { @view.render(:partial => "test/200") }
assert_equal "The partial name (test/200) is not a valid Ruby identifier; " +
"make sure your partial name starts with a lowercase letter or underscore, " +
"make sure your partial name starts with underscore, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end
def test_render_partial_with_missing_filename
e = assert_raises(ArgumentError) { @view.render(:partial => "test/") }
assert_equal "The partial name (test/) is not a valid Ruby identifier; " +
"make sure your partial name starts with a lowercase letter or underscore, " +
"make sure your partial name starts with underscore, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end
......@@ -194,7 +194,21 @@ def test_render_partial_with_incompatible_object
def test_render_partial_with_hyphen
e = assert_raises(ArgumentError) { @view.render(:partial => "test/a-in") }
assert_equal "The partial name (test/a-in) is not a valid Ruby identifier; " +
"make sure your partial name starts with a lowercase letter or underscore, " +
"make sure your partial name starts with underscore, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end
def test_render_partial_with_invalid_option_as
e = assert_raises(ArgumentError) { @view.render(:partial => "test/partial_only", :as => 'a-in') }
assert_equal "The value (a-in) of the option `as` is not a valid Ruby identifier; " +
"make sure it starts with lowercase letter, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end
def test_render_partial_with_hyphen_and_invalid_option_as
e = assert_raises(ArgumentError) { @view.render(:partial => "test/a-in", :as => 'a-in') }
assert_equal "The value (a-in) of the option `as` is not a valid Ruby identifier; " +
"make sure it starts with lowercase letter, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册