diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-01-17 23:05:18 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-01-18 00:44:26 -0200 |
commit | ba77ff3c1b583fdacf733404bbf4508042b45656 (patch) | |
tree | 799d97147368aad3c4a671087b7a9bcbecae9f90 | |
parent | 22ffc3dceaa83bcbfcfa541cc992346e6d428fbf (diff) | |
download | rails-ba77ff3c1b583fdacf733404bbf4508042b45656.tar.gz rails-ba77ff3c1b583fdacf733404bbf4508042b45656.tar.bz2 rails-ba77ff3c1b583fdacf733404bbf4508042b45656.zip |
Do not mutate options hash
-rw-r--r-- | actionpack/lib/action_view/helpers/record_tag_helper.rb | 4 | ||||
-rw-r--r-- | actionpack/test/template/record_tag_helper_test.rb | 6 |
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 8e667fe30b..8dcead64fb 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -92,8 +92,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 127e1b6bdd..e7e489b96d 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -105,4 +105,10 @@ class RecordTagHelperTest < ActionView::TestCase 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 |