diff options
Diffstat (limited to 'activesupport/test/core_ext/class')
-rw-r--r-- | activesupport/test/core_ext/class/attribute_test.rb | 35 | ||||
-rw-r--r-- | activesupport/test/core_ext/class/delegating_attributes_test.rb | 2 |
2 files changed, 27 insertions, 10 deletions
diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb index ef84b9f255..06b4cf075f 100644 --- a/activesupport/test/core_ext/class/attribute_test.rb +++ b/activesupport/test/core_ext/class/attribute_test.rb @@ -2,13 +2,6 @@ require 'abstract_unit' require 'active_support/core_ext/class/attribute' class ClassAttributeTest < ActiveSupport::TestCase - class Base - class_attribute :setting - end - - class Subclass < Base - end - def setup @klass = Class.new { class_attribute :setting } @sub = Class.new(@klass) @@ -40,8 +33,30 @@ class ClassAttributeTest < ActiveSupport::TestCase assert_equal true, @klass.setting? end - test 'no instance delegates' do - assert_raise(NoMethodError) { @klass.new.setting } - assert_raise(NoMethodError) { @klass.new.setting? } + test 'instance reader delegates to class' do + assert_nil @klass.new.setting + + @klass.setting = 1 + assert_equal 1, @klass.new.setting + end + + test 'instance override' do + object = @klass.new + object.setting = 1 + assert_nil @klass.setting + @klass.setting = 2 + assert_equal 1, object.setting + end + + test 'instance query' do + object = @klass.new + assert_equal false, object.setting? + object.setting = 1 + assert_equal true, object.setting? + end + + test 'disabling instance writer' do + object = Class.new { class_attribute :setting, :instance_writer => false }.new + assert_raise(NoMethodError) { object.setting = 'boom' } end end diff --git a/activesupport/test/core_ext/class/delegating_attributes_test.rb b/activesupport/test/core_ext/class/delegating_attributes_test.rb index 011068ab74..636edb8d4b 100644 --- a/activesupport/test/core_ext/class/delegating_attributes_test.rb +++ b/activesupport/test/core_ext/class/delegating_attributes_test.rb @@ -84,6 +84,8 @@ class DelegatingAttributesTest < Test::Unit::TestCase assert_equal "1", Child.some_attribute assert_nil Mokopuna.some_attribute + ensure + Child.some_attribute=nil end end |