Permalink
Browse files

Do not mutate options hash

  • Loading branch information...
1 parent 05bee99 commit 7006e975ac29e48cb9645733df04b9841bb2c29d @carlosantoniodasilva carlosantoniodasilva committed with sikachu Jan 18, 2012
@@ -96,8 +96,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
@@ -100,4 +100,10 @@ def test_content_tag_for_collection_is_html_safe
result = content_tag_for(:li, [post_1, post_2]) { |post| concat 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

0 comments on commit 7006e97

Please sign in to comment.