aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/callbacks_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-01-19 08:50:35 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-02-04 20:48:29 +0900
commit09525527a5a35cb60106aadc8c8c95fa0e4bf83e (patch)
treef891799caaf3797a172af6fdf61231ca41638f40 /activesupport/test/callbacks_test.rb
parentf8d3fed1679b487485e32b52b15fe154efe0f10c (diff)
downloadrails-09525527a5a35cb60106aadc8c8c95fa0e4bf83e.tar.gz
rails-09525527a5a35cb60106aadc8c8c95fa0e4bf83e.tar.bz2
rails-09525527a5a35cb60106aadc8c8c95fa0e4bf83e.zip
Deprecate passing string to `:if` and `:unless` conditional options on `set_callback` and `skip_callback`
Diffstat (limited to 'activesupport/test/callbacks_test.rb')
-rw-r--r--activesupport/test/callbacks_test.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index dd6b89e8a7..ed26081d4e 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -192,10 +192,12 @@ module CallbacksTest
before_save Proc.new { |r| r.history << [:before_save, :symbol] }, unless: :no
before_save Proc.new { |r| r.history << "b00m" }, unless: :yes
# string
- before_save Proc.new { |r| r.history << [:before_save, :string] }, if: "yes"
- before_save Proc.new { |r| r.history << "b00m" }, if: "no"
- before_save Proc.new { |r| r.history << [:before_save, :string] }, unless: "no"
- before_save Proc.new { |r| r.history << "b00m" }, unless: "yes"
+ ActiveSupport::Deprecation.silence do
+ before_save Proc.new { |r| r.history << [:before_save, :string] }, if: "yes"
+ before_save Proc.new { |r| r.history << "b00m" }, if: "no"
+ before_save Proc.new { |r| r.history << [:before_save, :string] }, unless: "no"
+ before_save Proc.new { |r| r.history << "b00m" }, unless: "yes"
+ end
# Combined if and unless
before_save Proc.new { |r| r.history << [:before_save, :combined_symbol] }, if: :yes, unless: :no
before_save Proc.new { |r| r.history << "b00m" }, if: :yes, unless: :yes
@@ -1204,6 +1206,17 @@ module CallbacksTest
end
end
+ class DeprecatedWarningTest < ActiveSupport::TestCase
+ def test_deprecate_string_conditional_options
+ klass = Class.new(Record)
+
+ assert_deprecated { klass.before_save :tweedle, if: "true" }
+ assert_deprecated { klass.after_save :tweedle, unless: "false" }
+ assert_deprecated { klass.skip_callback :save, :before, :tweedle, if: "true" }
+ assert_deprecated { klass.skip_callback :save, :after, :tweedle, unless: "false" }
+ end
+ end
+
class NotPermittedStringCallbackTest < ActiveSupport::TestCase
def test_passing_string_callback_is_not_permitted
klass = Class.new(Record)