aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/deprecation/method_wrappers_test.rb
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2018-07-10 12:03:54 -0400
committerEdouard CHIN <edouard.chin@shopify.com>2018-07-30 18:12:56 -0400
commit015477ae9109d4105d5a5057d82338f198febb74 (patch)
treec491df5cda00133217c5d4d99cd35b2f7f5506e5 /activesupport/test/deprecation/method_wrappers_test.rb
parentd4ea114bd611c608482375af94f49e2d54889202 (diff)
downloadrails-015477ae9109d4105d5a5057d82338f198febb74.tar.gz
rails-015477ae9109d4105d5a5057d82338f198febb74.tar.bz2
rails-015477ae9109d4105d5a5057d82338f198febb74.zip
A regression in deprecate_methods was introduced in a982a42:
- Refactoring alias_chain to Module#prepend broke the possibility to deprecate class methods since the module generated was prepended to the target's instance. A suggestion to fix this was to use `AS#redefine_method` which would solve the problem but with the cost of redefining directly the method. Decided to go with the same alias_chain implementation as before instead. - Fixes #33253
Diffstat (limited to 'activesupport/test/deprecation/method_wrappers_test.rb')
-rw-r--r--activesupport/test/deprecation/method_wrappers_test.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/activesupport/test/deprecation/method_wrappers_test.rb b/activesupport/test/deprecation/method_wrappers_test.rb
index 439e117c1d..b04bce7a11 100644
--- a/activesupport/test/deprecation/method_wrappers_test.rb
+++ b/activesupport/test/deprecation/method_wrappers_test.rb
@@ -55,4 +55,39 @@ class MethodWrappersTest < ActiveSupport::TestCase
assert(@klass.private_method_defined?(:old_private_method))
end
+
+ def test_deprecate_class_method
+ mod = Module.new do
+ extend self
+
+ def old_method
+ "abc"
+ end
+ end
+ ActiveSupport::Deprecation.deprecate_methods(mod, old_method: :new_method)
+
+ warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/
+ assert_deprecated(warning) { assert_equal "abc", mod.old_method }
+ end
+
+ def test_deprecate_method_when_class_extends_module
+ mod = Module.new do
+ def old_method
+ "abc"
+ end
+ end
+ @klass.extend mod
+ ActiveSupport::Deprecation.deprecate_methods(mod, old_method: :new_method)
+
+ warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/
+ assert_deprecated(warning) { assert_equal "abc", @klass.old_method }
+ end
+
+ def test_method_with_without_deprecation_is_exposed
+ ActiveSupport::Deprecation.deprecate_methods(@klass, old_method: :new_method)
+
+ warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/
+ assert_deprecated(warning) { assert_equal "abc", @klass.new.old_method_with_deprecation }
+ assert_equal "abc", @klass.new.old_method_without_deprecation
+ end
end