From 09525527a5a35cb60106aadc8c8c95fa0e4bf83e Mon Sep 17 00:00:00 2001
From: Ryuta Kamizono <kamipo@gmail.com>
Date: Thu, 19 Jan 2017 08:50:35 +0900
Subject: Deprecate passing string to `:if` and `:unless` conditional options
 on `set_callback` and `skip_callback`

---
 .../cases/validations/conditional_validation_test.rb | 20 +++++++++++++++-----
 .../test/cases/validations/with_validation_test.rb   | 20 +++++++++++++++-----
 2 files changed, 30 insertions(+), 10 deletions(-)

(limited to 'activemodel')

diff --git a/activemodel/test/cases/validations/conditional_validation_test.rb b/activemodel/test/cases/validations/conditional_validation_test.rb
index 4881008017..048d27446e 100644
--- a/activemodel/test/cases/validations/conditional_validation_test.rb
+++ b/activemodel/test/cases/validations/conditional_validation_test.rb
@@ -43,7 +43,9 @@ class ConditionalValidationTest < ActiveModel::TestCase
 
   def test_if_validation_using_string_true
     # When the evaluated string returns true
-    Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: "a = 1; a == 1")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: "a = 1; a == 1")
+    end
     t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
     assert t.invalid?
     assert t.errors[:title].any?
@@ -52,7 +54,9 @@ class ConditionalValidationTest < ActiveModel::TestCase
 
   def test_unless_validation_using_string_true
     # When the evaluated string returns true
-    Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: "a = 1; a == 1")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: "a = 1; a == 1")
+    end
     t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
     assert t.valid?
     assert_empty t.errors[:title]
@@ -60,7 +64,9 @@ class ConditionalValidationTest < ActiveModel::TestCase
 
   def test_if_validation_using_string_false
     # When the evaluated string returns false
-    Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: "false")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: "false")
+    end
     t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
     assert t.valid?
     assert_empty t.errors[:title]
@@ -68,7 +74,9 @@ class ConditionalValidationTest < ActiveModel::TestCase
 
   def test_unless_validation_using_string_false
     # When the evaluated string returns false
-    Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: "false")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: "false")
+    end
     t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
     assert t.invalid?
     assert t.errors[:title].any?
@@ -118,7 +126,9 @@ class ConditionalValidationTest < ActiveModel::TestCase
   # ensure that it works correctly
   def test_validation_with_if_as_string
     Topic.validates_presence_of(:title)
-    Topic.validates_presence_of(:author_name, if: "title.to_s.match('important')")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_presence_of(:author_name, if: "title.to_s.match('important')")
+    end
 
     t = Topic.new
     assert t.invalid?, "A topic without a title should not be valid"
diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb
index 20c11dd852..5ce86738cd 100644
--- a/activemodel/test/cases/validations/with_validation_test.rb
+++ b/activemodel/test/cases/validations/with_validation_test.rb
@@ -69,26 +69,34 @@ class ValidatesWithTest < ActiveModel::TestCase
   end
 
   test "with if statements that return false" do
-    Topic.validates_with(ValidatorThatAddsErrors, if: "1 == 2")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_with(ValidatorThatAddsErrors, if: "1 == 2")
+    end
     topic = Topic.new
     assert topic.valid?
   end
 
   test "with if statements that return true" do
-    Topic.validates_with(ValidatorThatAddsErrors, if: "1 == 1")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_with(ValidatorThatAddsErrors, if: "1 == 1")
+    end
     topic = Topic.new
     assert topic.invalid?
     assert_includes topic.errors[:base], ERROR_MESSAGE
   end
 
   test "with unless statements that return true" do
-    Topic.validates_with(ValidatorThatAddsErrors, unless: "1 == 1")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_with(ValidatorThatAddsErrors, unless: "1 == 1")
+    end
     topic = Topic.new
     assert topic.valid?
   end
 
   test "with unless statements that returns false" do
-    Topic.validates_with(ValidatorThatAddsErrors, unless: "1 == 2")
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_with(ValidatorThatAddsErrors, unless: "1 == 2")
+    end
     topic = Topic.new
     assert topic.invalid?
     assert_includes topic.errors[:base], ERROR_MESSAGE
@@ -102,7 +110,9 @@ class ValidatesWithTest < ActiveModel::TestCase
     validator.expect(:is_a?, false, [Symbol])
     validator.expect(:is_a?, false, [String])
 
-    Topic.validates_with(validator, if: "1 == 1", foo: :bar)
+    ActiveSupport::Deprecation.silence do
+      Topic.validates_with(validator, if: "1 == 1", foo: :bar)
+    end
     assert topic.valid?
     validator.verify
   end
-- 
cgit v1.2.3