Deprecate - Class#superclass_delegating_accessor #14271

Merged
merged 1 commit into from Mar 20, 2014

Projects

None yet

7 participants

@akshay-vishnoi
Contributor
class TestClass
  superclass_delegating_accessor :test_attribute
end

# Before
TestClass.private_methods.include?(:_test_attribute) # => false
TestClass.private_methods.include?(:_test_attribute=) # => false

# After
TestClass.private_methods.include?(:_test_attribute) # => true
TestClass.private_methods.include?(:_test_attribute=) # => true
@akshay-vishnoi
Contributor

Any update on this?

@chancancode
Member

Sorry, I must be missing some context here. What's the bug here? I am not familiar with this method and it has no docs. Is that even public API? Can you fill me in? Thanks 😄

@akshay-vishnoi
Contributor

@chancancode:

  1. Bug - Comment in Class#superclass_delegating_accessor says that this method creates private _name and _name= methods, which previously was not true. Refer here.

    Also test cases were not covering the whole functionality of Class#superclass_delegating_accessor.

  2. Yes it is in public API.

@akshay-vishnoi
Contributor

@chancancode Any update on this? 😄

@chancancode
Member

I still don't know what this method does =/

If it's a public API we should add docs? If not we should :nodoc it? You don't have to do those, but I don't feel comfortable merging this without understanding what this does. Maybe someone else more familiar with this can help you then :)

@akshay-vishnoi
Contributor
@akshay-vishnoi
Contributor

Any update on this?

@wycats
Member
wycats commented Mar 10, 2014

I'll take a look today.

@akshay-vishnoi
Contributor

Thanks @wycats

@akshay-vishnoi
Contributor

Any update on this?

@thedarkone
Contributor

I don't think superclass_delegating_accessor is used by Rails anymore, it also has no docs. So how about removing altogether?

@carlosantoniodasilva

Definitely +1 for deprecating this.

@wycats
Member
wycats commented Mar 12, 2014

I'm pretty sure this was an earlier experiment before we settled on class_attribute. I see no reason to keep it around if it's not used anywhere.

@akshay-vishnoi
Contributor

Should I update the PR?
That means updated PR will include:

  1. Remove activesupport/lib/active_support/core_ext/class/delegating_attributes.rb and activesupport/test/core_ext/class/delegating_attributes_test.rb
  2. Remove the require statements from active_support/core_ext/class.rb and activerecord/lib/active_record/base.rb.
@carlosantoniodasilva

Please do, just add a deprecation now for master/4.2, and we remove in the next version. It's not gonna be a problem for Rails, but other libs might be using it in ways we don't know, so deprecating first is always better.

@akshay-vishnoi
Contributor

Okay I will add deprecation warning and corresponding test cases.
But I think we should update the code for master/4.2 because

  1. Previous code was not correct.
  2. Previous test cases were incorrectly written. (If we are not updating the code, but we should atleast cover all test cases.)

cc @carlosantoniodasilva, @wycats, @thedarkone - Any thoughts?

@carlosantoniodasilva

I think it's not necessary to change code/tests we're going to rm, specially because we haven't received issues related to this piece of code in a long time as far as I remember. We can just go ahead and deprecate it as is. Thanks!

@akshay-vishnoi
Contributor

Sorry for late reply. I will do it today. Thanks for help!!!

@akshay-vishnoi
Contributor

@carlosantoniodasilva Please check the updated code.

@carlosantoniodasilva

Can you add a test that shows it's deprecated, and a changelog entry? It may also need to require the related deprecation file. Thanks.

@akshay-vishnoi
Contributor

@carlosantoniodasilva: Please check updated code.

  1. Test case added
  2. CHANGELOG.md updated
  3. deprecation file required

Thanks

@robin850
Member

@akshay-vishnoi : Could you please rebase your branch ? It doesn't apply cleanly. Also it would be nice if you could update the PR title and description accordingly. Thanks for your contribution! 👍

@akshay-vishnoi akshay-vishnoi changed the title from Bug Fix - Class#superclass_delegating_accessor to Deprecate - Class#superclass_delegating_accessor Mar 19, 2014
@akshay-vishnoi
Contributor

@robin850

  1. I have done rebasing. Please check updated code.
  2. Also changed the title of PR.
  3. Should I change my comment as well, as description of PR is now shown as a comment?
@carlosantoniodasilva

Looks good, however I think now other tests will show warnings when running the suite, maybe we should silence those?

Thanks @akshay-vishnoi

@rafaelfranca
Member

If we are going to deprecate we need to tell our users what they have to use instead. I searched on GitHub and there are a lot of ocorrences of this method https://github.com/search?p=1&q=superclass_delegating_accessor&type=Code

@akshay-vishnoi
Contributor

@rafaelfranca I am also working on it, I can extract a gem for this. So we can refer to it if necessary.

@thedarkone
Contributor

@akshay-vishnoi the deprecation message should refer users to class_attribute.

If we are going to deprecate we need to tell our users what they have to use instead. I searched on GitHub and there are a lot of ocorrences of this method https://github.com/search?p=1&q=superclass_delegating_accessor&type=Code

@rafaelfranca wow, that's a lot of code... but clicking through random pages, it all looks to be either vendored Rails code or an old (also vendored) version of active_merchant.

@akshay-vishnoi
Contributor

Could you please guide what should be the proper warning message? Thanks

@rafaelfranca
Member

@akshay-vishnoi something like:

".superclass_delegating_accessor is deprecated and will be removed in the next Rails 4.2. Please use .class_attribute instead."

@akshay-vishnoi
Contributor

@rafaelfranca - Code updated Please check
Now the message will be

DEPRECATION WARNING: superclass_delegating_accessor is deprecated and will be removed from Rails 4.2 (use class_attribute instead).
@rafaelfranca
Member

Ok, now we have to fix all the deprecations are being printed in our tests. See https://travis-ci.org/rails/rails/jobs/21113798#L2989 for example

@akshay-vishnoi
Contributor

@rafaelfranca : Could you please help, actually when I am running test cases it is showing the warning and full backtrace, but when I am using rails as a gem then it is not showing the backtrace but only warning. What could be the possible reason? Although all test cases are running and there is no error or failure, but I am not getting how to stop these backtraces.

@rafaelfranca
Member

You can use assert_deprecated or silence_warnings

@akshay-vishnoi
Contributor

I have already used assert_deprecated and backtrace is not coming for this test, and if i have to stop it for all other test cases then i will need to change it at each place where Class#superclass_delegating_accessor is getting used.
I also noticed that ActiveSupport::Deprecation.debug is true here. Backtrace is coming due to this reason. If I set ActiveSupport::Deprecation.debug to false, then only warning message is coming, like other methods i.e. without any backtrace. Do you have any idea about this?
Thanks

@akshay-vishnoi
Contributor

Okay it has been set in abstract_unit.rb. But how can we escape the deprecation warning for this line or similar to this line? As these lines are not the part of the test cases.

@rafaelfranca
Member

I think you can use silence_warnings for that case.

@akshay-vishnoi
Contributor

@rafaelfranca : Please check updated code. Will this work?

@akshay-vishnoi
Contributor

@rafaelfranca : Any updates?

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Mar 20, 2014
activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Deprecate `Class#superclass_delegating_accessor`.
@carlosantoniodasilva
carlosantoniodasilva Mar 20, 2014 Member

You can also add a comment to use class_attribute instead in this changelog entry.

@carlosantoniodasilva

@akshay-vishnoi just a minor comment on the changelog, and then we're good to go.

@akshay-vishnoi
Contributor

@carlosantoniodasilva Ya sure, Updating!!!!

@akshay-vishnoi
Contributor

@carlosantoniodasilva : Code updated Please check.
When are we expecting next stable release, so that I can make another PR removing the same from the codebase?

@carlosantoniodasilva carlosantoniodasilva merged commit a2a7f8b into rails:master Mar 20, 2014

1 check was pending

default The Travis CI build is in progress
Details
@carlosantoniodasilva

Thanks.

@carlosantoniodasilva

@akshay-vishnoi this is only going to be released on 4.2, which is going to take a while (considering 4.1 is in rc state), so keep it in your todo list :)

@akshay-vishnoi
Contributor

Ohkay Thanks 💚

@akshay-vishnoi akshay-vishnoi added a commit to akshay-vishnoi/rails that referenced this pull request May 4, 2014
@akshay-vishnoi akshay-vishnoi Remove `.superclass_delegating_accessor`. Refer #14271 5288554
@akshay-vishnoi akshay-vishnoi added a commit to akshay-vishnoi/rails that referenced this pull request Sep 17, 2014
@akshay-vishnoi akshay-vishnoi Remove `.superclass_delegating_accessor`. Refer #14271 09dfc2e
@akshay-vishnoi akshay-vishnoi added a commit to akshay-vishnoi/rails that referenced this pull request Sep 17, 2014
@akshay-vishnoi akshay-vishnoi Remove `.superclass_delegating_accessor`. Refer #14271 12a644c
@amccloud amccloud added a commit to amccloud/active_merchant that referenced this pull request Sep 28, 2014
@amccloud amccloud Switch to Class#class_attribute
Class#superclass_delegating_accessor was deprecated in Rails 4.2.0

rails/rails#14271
0710f45
@lulalala lulalala added a commit to lulalala/active_merchant that referenced this pull request Oct 10, 2014
@lulalala lulalala Class#superclass_delegating_accessor from Rails is now deprecated.
Switch to Class#class_attribute instead.
See rails/rails#14271
ae02c93
@larrylv larrylv added a commit to larrylv/active_merchant that referenced this pull request Apr 21, 2015
@larrylv larrylv Don't require active_support's delegating_attributes
Class#superclass_delegating_accessor from Rails is now deprecated.

rails/rails#14271

And uses of `superclass_delegating_accessor` use has been removed in #ffca0ca615bfa7bc99f8faae9b4ae95514a6604d and #ae02c93aaa52e4a63326d4b399bd8a9dd3977ed5
db63079
@larrylv larrylv referenced this pull request in activemerchant/active_merchant Apr 21, 2015
Closed

Don't require active_support's delegating_attributes #1655

@larrylv larrylv added a commit to larrylv/active_merchant that referenced this pull request Apr 21, 2015
@larrylv larrylv Don't require active_support's delegating_attributes
Class#superclass_delegating_accessor from Rails is now deprecated.

rails/rails#14271

And uses of `superclass_delegating_accessor` use has been removed in #ffca0ca615bfa7bc99f8faae9b4ae95514a6604d and #ae02c93aaa52e4a63326d4b399bd8a9dd3977ed5
113e1bf
@larrylv larrylv added a commit to larrylv/active_merchant that referenced this pull request Apr 30, 2015
@larrylv larrylv Don't require active_support's delegating_attributes
Class#superclass_delegating_accessor from Rails is now deprecated.

rails/rails#14271

And uses of `superclass_delegating_accessor` use has been removed in #ffca0ca615bfa7bc99f8faae9b4ae95514a6604d and #ae02c93aaa52e4a63326d4b399bd8a9dd3977ed5
f542e4e
@akshay-vishnoi akshay-vishnoi added a commit to akshay-vishnoi/rails that referenced this pull request May 24, 2015
@akshay-vishnoi akshay-vishnoi Remove `.superclass_delegating_accessor`. Refer #14271 20c1484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment