From 4f2c25d39d264aca09a000a1c44be0f1937203fa Mon Sep 17 00:00:00 2001 From: Michael Ryan Date: Thu, 10 Mar 2016 12:13:45 -0500 Subject: Fix `thread_mattr_accessor` thread-local variable naming The current implentation of `thread_mattr_accessor` is setting differently-named thread variables when defining class and instance writer methods, so the method isn't working as documented: Account.user = "DHH" Account.user # => "DHH" Account.new.user # => nil a = Account.new a.user = "ABC" # => "ABC" a.class.user # => "DHH" At this point `:attr_Account_user` and `:attr_Class_user` thread-local variables have been created. Modify the reader and writer methods to use the class name instead of 'Class'. --- .../test/core_ext/module/attribute_accessor_per_thread_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb') diff --git a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb index 65fadc5c20..a9fd878b80 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb @@ -106,4 +106,10 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase end assert_equal "invalid attribute name: 2valid_part", exception.message end + + def test_should_return_same_value_by_class_or_instance_accessor + @class.foo = 'fries' + + assert_equal @class.foo, @object.foo + end end -- cgit v1.2.3