Add tests for privates methods in view's helpers

Test that using private methods in `options_from_collection_for_select`
is deprecated.

Make the unused `secret` paramether in the `Post` Struct private to use
it in the test.
上级 4ca9fa11
文件已添加
......@@ -21,7 +21,12 @@ class FormOptionsHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormOptionsHelper
silence_warnings do
Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on, :category, :origin, :allow_comments)
Post = Struct.new("Post", :title, :author_name, :body, :written_on, :category, :origin, :allow_comments) do
private
def secret
"This is super secret: #{author_name} is not the real author of #{title}"
end
end
Continent = Struct.new("Continent", :continent_name, :countries)
Country = Struct.new("Country", :country_id, :country_name)
Firm = Struct.new("Firm", :time_zone)
......@@ -68,6 +73,14 @@ def test_collection_options
)
end
def test_collection_options_with_private_value_method
assert_deprecated(/Using private methods in view's helpers is deprecated/) { options_from_collection_for_select(dummy_posts, "secret", "title") }
end
def test_collection_options_with_private_text_method
assert_deprecated(/Using private methods in view's helpers is deprecated/) { options_from_collection_for_select(dummy_posts, "author_name", "secret") }
end
def test_collection_options_with_preselected_value
assert_dom_equal(
"<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册