Permalink
Browse files

Do not mutate options hash

  • Loading branch information...
1 parent 22ffc3d commit ba77ff3c1b583fdacf733404bbf4508042b45656 @carlosantoniodasilva carlosantoniodasilva committed Jan 18, 2012
@@ -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

1 comment on commit ba77ff3

Can someone merge this into 3-2-stable, please ?

Please sign in to comment.