aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/class
diff options
context:
space:
mode:
authorAlexey Chernenkov <laise@pisem.net>2013-06-05 13:05:53 +0600
committerAlexey Chernenkov <laise@pisem.net>2013-11-15 19:54:51 +0600
commit0e953c94b152abf0de1c04dba74c22f935bc85c7 (patch)
treea916e031786e90c2fc96200b573d51e879e9ffb8 /activesupport/test/core_ext/class
parent81475534ed9e2e1b7bade50f1e1099975e385a46 (diff)
downloadrails-0e953c94b152abf0de1c04dba74c22f935bc85c7.tar.gz
rails-0e953c94b152abf0de1c04dba74c22f935bc85c7.tar.bz2
rails-0e953c94b152abf0de1c04dba74c22f935bc85c7.zip
Unify `cattr_*` interface: allow to pass a block to `cattr_reader`.
Example: class A cattr_reader(:defr) { 'default_reader_value' } end A.defr # => 'default_reader_value'
Diffstat (limited to 'activesupport/test/core_ext/class')
-rw-r--r--activesupport/test/core_ext/class/attribute_accessor_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/class/attribute_accessor_test.rb b/activesupport/test/core_ext/class/attribute_accessor_test.rb
index 0d5f39a72b..3bc948f3a6 100644
--- a/activesupport/test/core_ext/class/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/class/attribute_accessor_test.rb
@@ -8,6 +8,9 @@ class ClassAttributeAccessorTest < ActiveSupport::TestCase
cattr_accessor :bar, :instance_writer => false
cattr_reader :shaq, :instance_reader => false
cattr_accessor :camp, :instance_accessor => false
+ cattr_accessor(:defa) { 'default_accessor_value' }
+ cattr_reader(:defr) { 'default_reader_value' }
+ cattr_writer(:defw) { 'default_writer_value' }
end
@object = @class.new
end
@@ -58,4 +61,10 @@ class ClassAttributeAccessorTest < ActiveSupport::TestCase
end
assert_equal "invalid class attribute name: 1nvalid", exception.message
end
+
+ def test_should_use_default_value_if_block_passed
+ assert_equal 'default_accessor_value', @class.defa
+ assert_equal 'default_reader_value', @class.defr
+ assert_equal 'default_writer_value', @class.class_variable_get('@@defw')
+ end
end