From a51dad1c525c674ba9e08697332f86790e3570ca Mon Sep 17 00:00:00 2001 From: Lachlan Sylvester Date: Fri, 7 Aug 2015 20:05:02 +1000 Subject: Only invoke the default block for mattr_accessor once so that it does not cause issues if it is not idempotent --- activesupport/test/core_ext/module/attribute_accessor_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/test') 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 -- cgit v1.2.3