diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-07 10:50:40 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-07 10:50:40 -0300 |
commit | d96a1b62d7c957fcf4ab818ff06e6d5bfc6f3b2d (patch) | |
tree | beb481e05e5772d2a188938ca535d0dcd2beb534 /activesupport | |
parent | 4b91db5b125dd7bd735e7f42eb8e2c14c0e6757e (diff) | |
parent | a51dad1c525c674ba9e08697332f86790e3570ca (diff) | |
download | rails-d96a1b62d7c957fcf4ab818ff06e6d5bfc6f3b2d.tar.gz rails-d96a1b62d7c957fcf4ab818ff06e6d5bfc6f3b2d.tar.bz2 rails-d96a1b62d7c957fcf4ab818ff06e6d5bfc6f3b2d.zip |
Merge pull request #21158 from lsylvester/only-invoke-mattr_accessor-default-block-once
Prevent the default block for mattr_accessor being called multiple times
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/attribute_accessors.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/module/attribute_accessor_test.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb index d4e6b5a1ac..a77da573fe 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb @@ -206,7 +206,7 @@ class Module # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red] def mattr_accessor(*syms, &blk) mattr_reader(*syms, &blk) - mattr_writer(*syms, &blk) + mattr_writer(*syms) end alias :cattr_accessor :mattr_accessor end diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb index 48f3cc579f..128c5e3d1a 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb @@ -76,4 +76,10 @@ class ModuleAttributeAccessorTest < ActiveSupport::TestCase assert_equal 'default_reader_value', @module.defr assert_equal 'default_writer_value', @module.class_variable_get('@@defw') end + + def test_should_not_invoke_default_value_block_multiple_times + count = 0 + @module.cattr_accessor(:defcount){ count += 1 } + assert_equal 1, count + end end |