1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Deprecate Class#superclass_delegating_accessor

This commit is contained in:
Akshay Vishnoi 2014-03-20 18:29:09 +05:30
parent 8cea8ae278
commit 41548df342
3 changed files with 36 additions and 6 deletions

View file

@ -1,3 +1,7 @@
* Deprecate `Class#superclass_delegating_accessor`, use `Class#class_attribute` instead.
*Akshay Vishnoi*
* Ensure classes which `include Enumerable` get `#to_json` in addition to * Ensure classes which `include Enumerable` get `#to_json` in addition to
`#as_json`. `#as_json`.

View file

@ -1,5 +1,7 @@
require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/kernel/singleton_class'
require 'active_support/core_ext/module/remove_method' require 'active_support/core_ext/module/remove_method'
require 'active_support/core_ext/module/deprecation'
class Class class Class
def superclass_delegating_accessor(name, options = {}) def superclass_delegating_accessor(name, options = {})
@ -21,6 +23,8 @@ class Class
end end
end end
deprecate superclass_delegating_accessor: :class_attribute
private private
# Take the object being set and store it in a method. This gives us automatic # Take the object being set and store it in a method. This gives us automatic
# inheritance behavior, without having to store the object in an instance # inheritance behavior, without having to store the object in an instance

View file

@ -6,14 +6,18 @@ module DelegatingFixtures
end end
class Child < Parent class Child < Parent
superclass_delegating_accessor :some_attribute ActiveSupport::Deprecation.silence do
superclass_delegating_accessor :some_attribute
end
end end
class Mokopuna < Child class Mokopuna < Child
end end
class PercysMom class PercysMom
superclass_delegating_accessor :superpower ActiveSupport::Deprecation.silence do
superclass_delegating_accessor :superpower
end
end end
class Percy < PercysMom class Percy < PercysMom
@ -29,7 +33,10 @@ class DelegatingAttributesTest < ActiveSupport::TestCase
end end
def test_simple_accessor_declaration def test_simple_accessor_declaration
single_class.superclass_delegating_accessor :both ActiveSupport::Deprecation.silence do
single_class.superclass_delegating_accessor :both
end
# Class should have accessor and mutator # Class should have accessor and mutator
# the instance should have an accessor only # the instance should have an accessor only
assert_respond_to single_class, :both assert_respond_to single_class, :both
@ -40,7 +47,11 @@ class DelegatingAttributesTest < ActiveSupport::TestCase
def test_simple_accessor_declaration_with_instance_reader_false def test_simple_accessor_declaration_with_instance_reader_false
_instance_methods = single_class.public_instance_methods _instance_methods = single_class.public_instance_methods
single_class.superclass_delegating_accessor :no_instance_reader, :instance_reader => false
ActiveSupport::Deprecation.silence do
single_class.superclass_delegating_accessor :no_instance_reader, :instance_reader => false
end
assert_respond_to single_class, :no_instance_reader assert_respond_to single_class, :no_instance_reader
assert_respond_to single_class, :no_instance_reader= assert_respond_to single_class, :no_instance_reader=
assert !_instance_methods.include?(:no_instance_reader) assert !_instance_methods.include?(:no_instance_reader)
@ -49,7 +60,9 @@ class DelegatingAttributesTest < ActiveSupport::TestCase
end end
def test_working_with_simple_attributes def test_working_with_simple_attributes
single_class.superclass_delegating_accessor :both ActiveSupport::Deprecation.silence do
single_class.superclass_delegating_accessor :both
end
single_class.both = "HMMM" single_class.both = "HMMM"
@ -65,7 +78,11 @@ class DelegatingAttributesTest < ActiveSupport::TestCase
def test_child_class_delegates_to_parent_but_can_be_overridden def test_child_class_delegates_to_parent_but_can_be_overridden
parent = Class.new parent = Class.new
parent.superclass_delegating_accessor :both
ActiveSupport::Deprecation.silence do
parent.superclass_delegating_accessor :both
end
child = Class.new(parent) child = Class.new(parent)
parent.both = "1" parent.both = "1"
assert_equal "1", child.both assert_equal "1", child.both
@ -97,4 +114,9 @@ class DelegatingAttributesTest < ActiveSupport::TestCase
Child.some_attribute=nil Child.some_attribute=nil
end end
def test_deprecation_warning
assert_deprecated(/superclass_delegating_accessor is deprecated/) do
single_class.superclass_delegating_accessor :test_attribute
end
end
end end