提交 ba77ff3c 编写于 作者: C Carlos Antonio da Silva

Do not mutate options hash

上级 22ffc3dc
......@@ -92,8 +92,8 @@ def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options
# for each record.
def content_tag_for_single_record(tag_name, record, prefix, options, &block)
options, prefix = prefix, nil if prefix.is_a?(Hash)
options ||= {}
options.merge!({ :class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
options = options ? options.dup : {}
options.merge!(:class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix))
if block.arity == 0
content_tag(tag_name, capture(&block), options)
else
......
......@@ -105,4 +105,10 @@ def test_content_tag_for_collection_is_html_safe
result = content_tag_for(:li, [post_1, post_2]) { |post| post.body }
assert result.html_safe?
end
def test_content_tag_for_does_not_change_options_hash
options = { :class => "important" }
result = content_tag_for(:li, @post, options) { }
assert_equal({ :class => "important" }, options)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册