aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-04-27 15:39:52 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-04-27 15:39:52 -0700
commit434be0fd69a58cc744cd48c0d69440df1102b157 (patch)
tree97c406055e4a4aa9d60948a728ff0dcd0217c5aa
parent05bee990b4bd0ce3b02e75399c857e168f41edb6 (diff)
parent7006e975ac29e48cb9645733df04b9841bb2c29d (diff)
downloadrails-434be0fd69a58cc744cd48c0d69440df1102b157.tar.gz
rails-434be0fd69a58cc744cd48c0d69440df1102b157.tar.bz2
rails-434be0fd69a58cc744cd48c0d69440df1102b157.zip
Merge pull request #6022 from sikachu/3-2-stable-record_tag_backport
Do not mutate options hash
-rw-r--r--actionpack/lib/action_view/helpers/record_tag_helper.rb4
-rw-r--r--actionpack/test/template/record_tag_helper_test.rb6
2 files changed, 8 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb
index b351302d01..aae6389445 100644
--- a/actionpack/lib/action_view/helpers/record_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb
@@ -96,8 +96,8 @@ module ActionView
# 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
diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb
index 80d6f130ed..b4db6d9a71 100644
--- a/actionpack/test/template/record_tag_helper_test.rb
+++ b/actionpack/test/template/record_tag_helper_test.rb
@@ -100,4 +100,10 @@ class RecordTagHelperTest < ActionView::TestCase
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