diff options
Diffstat (limited to 'activesupport/test/core_ext/class')
3 files changed, 26 insertions, 16 deletions
diff --git a/activesupport/test/core_ext/class/attribute_accessor_test.rb b/activesupport/test/core_ext/class/attribute_accessor_test.rb index 2c896d0cdb..456f4b7948 100644 --- a/activesupport/test/core_ext/class/attribute_accessor_test.rb +++ b/activesupport/test/core_ext/class/attribute_accessor_test.rb @@ -10,27 +10,27 @@ class ClassAttributeAccessorTest < Test::Unit::TestCase end @object = @class.new end - + def test_should_use_mattr_default assert_nil @class.foo assert_nil @object.foo end - + def test_should_set_mattr_value @class.foo = :test assert_equal :test, @object.foo - + @object.foo = :test2 assert_equal :test2, @class.foo end - + def test_should_not_create_instance_writer assert_respond_to @class, :foo assert_respond_to @class, :foo= assert_respond_to @object, :bar assert !@object.respond_to?(:bar=) end - + def test_should_not_create_instance_reader assert_respond_to @class, :shaq assert !@object.respond_to?(:shaq) diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb index 24aa5c0eba..d58b60482b 100644 --- a/activesupport/test/core_ext/class/attribute_test.rb +++ b/activesupport/test/core_ext/class/attribute_test.rb @@ -65,4 +65,9 @@ class ClassAttributeTest < ActiveSupport::TestCase object.singleton_class.setting = 'foo' assert_equal 'foo', object.setting end + + test 'setter returns set value' do + val = @klass.send(:setting=, 1) + assert_equal 1, val + end end diff --git a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb index 63ea46b564..020dfce56a 100644 --- a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb +++ b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb @@ -3,9 +3,14 @@ require 'active_support/core_ext/class/inheritable_attributes' class ClassInheritableAttributesTest < Test::Unit::TestCase def setup + ActiveSupport::Deprecation.silenced = true @klass = Class.new end + def teardown + ActiveSupport::Deprecation.silenced = false + end + def test_reader_declaration assert_nothing_raised do @klass.class_inheritable_reader :a @@ -21,7 +26,7 @@ class ClassInheritableAttributesTest < Test::Unit::TestCase assert_respond_to @klass.new, :a= end end - + def test_writer_declaration_without_instance_writer assert_nothing_raised do @klass.class_inheritable_writer :a, :instance_writer => false @@ -39,7 +44,7 @@ class ClassInheritableAttributesTest < Test::Unit::TestCase assert_respond_to @klass.new, :a= end end - + def test_accessor_declaration_without_instance_writer assert_nothing_raised do @klass.class_inheritable_accessor :a, :instance_writer => false @@ -176,37 +181,37 @@ class ClassInheritableAttributesTest < Test::Unit::TestCase assert_equal 'b', @klass.b assert_equal 'B', @sub.b end - + def test_array_inheritance @klass.class_inheritable_accessor :a @klass.a = [] @sub = eval("class SubbyArray < @klass; end; SubbyArray") - + assert_equal [], @klass.a assert_equal [], @sub.a - + @sub.a << :first - + assert_equal [:first], @sub.a assert_equal [], @klass.a end - + def test_array_inheritance_ @klass.class_inheritable_accessor :a @klass.a = {} @sub = eval("class SubbyHash < @klass; end; SubbyHash") - + assert_equal Hash.new, @klass.a assert_equal Hash.new, @sub.a - + @sub.a[:first] = :first - + assert_equal 1, @sub.a.keys.size assert_equal 0, @klass.a.keys.size end - + def test_reset_inheritable_attributes @klass.class_inheritable_accessor :a @klass.a = 'a' |