diff options
Diffstat (limited to 'activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb')
-rw-r--r-- | activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb | 42 |
1 files changed, 32 insertions, 10 deletions
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..b816fa50e3 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 @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/attribute_accessors_per_thread' +require "abstract_unit" +require "active_support/core_ext/module/attribute_accessors_per_thread" class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase def setup @@ -8,6 +8,12 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase thread_mattr_accessor :bar, instance_writer: false thread_mattr_reader :shaq, instance_reader: false thread_mattr_accessor :camp, instance_accessor: false + + def self.name; "MyClass" end + end + + @subclass = Class.new(@class) do + def self.name; "SubMyClass" end end @object = @class.new @@ -57,23 +63,23 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase def test_values_should_not_bleed_between_threads threads = [] threads << Thread.new do - @class.foo = 'things' + @class.foo = "things" sleep 1 - assert_equal 'things', @class.foo + assert_equal "things", @class.foo end threads << Thread.new do - @class.foo = 'other things' + @class.foo = "other things" sleep 1 - assert_equal 'other things', @class.foo + assert_equal "other things", @class.foo end - + threads << Thread.new do - @class.foo = 'really other things' + @class.foo = "really other things" sleep 1 - assert_equal 'really other things', @class.foo + assert_equal "really other things", @class.foo end - + threads.each { |t| t.join } end @@ -106,4 +112,20 @@ 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 + + def test_should_not_affect_superclass_if_subclass_set_value + @class.foo = "super" + assert_equal @class.foo, "super" + assert_nil @subclass.foo + + @subclass.foo = "sub" + assert_equal @class.foo, "super" + assert_equal @subclass.foo, "sub" + end end |