diff options
author | Guilherme Mansur <guilherme.mansur@shopify.com> | 2019-05-21 14:45:04 -0400 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2019-08-05 02:31:36 +0200 |
commit | 2bd2d853da78c248b1d50add92ce21f43430abe9 (patch) | |
tree | dea198daa021157fb4cdd72b4ab1a09f95277366 /activesupport/test/core_ext | |
parent | cebbf6c6cfc88ed2bd64853bad8d0c9adf420fd9 (diff) | |
download | rails-2bd2d853da78c248b1d50add92ce21f43430abe9.tar.gz rails-2bd2d853da78c248b1d50add92ce21f43430abe9.tar.bz2 rails-2bd2d853da78c248b1d50add92ce21f43430abe9.zip |
Able to initalize default value for thread_mattr_*
Added the ability to initialize `thread_mattr_*` methods with default
values like so:
``` ruby
class MyClass
thread_attr_reader :foo, default: :foo
thread_attr_writer :bar, default: :bar
thread_attr_accessor: baz do
"baz"
end
end
```
This is consistent with the api exposed by `mattr_accessor`.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb | 38 |
1 files changed, 27 insertions, 11 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 e0e331fc91..c73ca0be0c 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 @@ -4,21 +4,37 @@ require "abstract_unit" require "active_support/core_ext/module/attribute_accessors_per_thread" class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase + class MyClass + thread_mattr_accessor :foo + thread_mattr_accessor :bar, instance_writer: false + thread_mattr_reader :shaq, instance_reader: false + thread_mattr_accessor :camp, instance_accessor: false + end + + class SubMyClass < MyClass + end + def setup - @class = Class.new do - thread_mattr_accessor :foo - thread_mattr_accessor :bar, instance_writer: false - thread_mattr_reader :shaq, instance_reader: false - thread_mattr_accessor :camp, instance_accessor: false + @class = MyClass + @subclass = SubMyClass + @object = @class.new + end - def self.name; "MyClass" end - end + def test_can_initialize_with_default_value + Thread.new do + @class.thread_mattr_accessor :baz, default: "default_value" + assert_equal "default_value", @class.baz + end.join + end - @subclass = Class.new(@class) do - def self.name; "SubMyClass" end - end + def test_can_initialize_with_a_block_as_default_value + Thread.new do + @class.thread_mattr_accessor :baz do + "default_value" + end - @object = @class.new + assert_equal "default_value", @class.baz + end.join end def test_should_use_mattr_default |