aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-02-15 11:34:54 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-02-15 17:40:15 +0900
commit4c6171d6056a346a953792a954853d14c000dc90 (patch)
tree6828ab3c21482a8a81bc0c9229e2028e9e26bdc0 /activerecord/test
parentcdb8697b4a654aad2e65590d58c5f581a53d6b33 (diff)
downloadrails-4c6171d6056a346a953792a954853d14c000dc90.tar.gz
rails-4c6171d6056a346a953792a954853d14c000dc90.tar.bz2
rails-4c6171d6056a346a953792a954853d14c000dc90.zip
Deprecate using class level querying methods if the receiver scope regarded as leaked
This deprecates using class level querying methods if the receiver scope regarded as leaked, since #32380 and #35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making those.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relations_test.rb30
-rw-r--r--activerecord/test/cases/scoping/named_scoping_test.rb6
2 files changed, 22 insertions, 14 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 98ba47f1b8..2ac81ba425 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1169,9 +1169,11 @@ class RelationTest < ActiveRecord::TestCase
def test_first_or_create_with_after_initialize
Bird.create!(color: "yellow", name: "canary")
- parrot = Bird.where(color: "green").first_or_create do |bird|
- bird.name = "parrot"
- bird.enable_count = true
+ parrot = assert_deprecated do
+ Bird.where(color: "green").first_or_create do |bird|
+ bird.name = "parrot"
+ bird.enable_count = true
+ end
end
assert_equal 0, parrot.total_count
end
@@ -1180,7 +1182,7 @@ class RelationTest < ActiveRecord::TestCase
Bird.create!(color: "yellow", name: "canary")
parrot = Bird.where(color: "green").first_or_create do |bird|
bird.name = "parrot"
- assert_equal 0, Bird.count
+ assert_deprecated { assert_equal 0, Bird.count }
end
assert_kind_of Bird, parrot
assert_predicate parrot, :persisted?
@@ -1224,9 +1226,11 @@ class RelationTest < ActiveRecord::TestCase
def test_first_or_create_bang_with_after_initialize
Bird.create!(color: "yellow", name: "canary")
- parrot = Bird.where(color: "green").first_or_create! do |bird|
- bird.name = "parrot"
- bird.enable_count = true
+ parrot = assert_deprecated do
+ Bird.where(color: "green").first_or_create! do |bird|
+ bird.name = "parrot"
+ bird.enable_count = true
+ end
end
assert_equal 0, parrot.total_count
end
@@ -1235,7 +1239,7 @@ class RelationTest < ActiveRecord::TestCase
Bird.create!(color: "yellow", name: "canary")
parrot = Bird.where(color: "green").first_or_create! do |bird|
bird.name = "parrot"
- assert_equal 0, Bird.count
+ assert_deprecated { assert_equal 0, Bird.count }
end
assert_kind_of Bird, parrot
assert_predicate parrot, :persisted?
@@ -1287,9 +1291,11 @@ class RelationTest < ActiveRecord::TestCase
def test_first_or_initialize_with_after_initialize
Bird.create!(color: "yellow", name: "canary")
- parrot = Bird.where(color: "green").first_or_initialize do |bird|
- bird.name = "parrot"
- bird.enable_count = true
+ parrot = assert_deprecated do
+ Bird.where(color: "green").first_or_initialize do |bird|
+ bird.name = "parrot"
+ bird.enable_count = true
+ end
end
assert_equal 0, parrot.total_count
end
@@ -1298,7 +1304,7 @@ class RelationTest < ActiveRecord::TestCase
Bird.create!(color: "yellow", name: "canary")
parrot = Bird.where(color: "green").first_or_initialize do |bird|
bird.name = "parrot"
- assert_equal 0, Bird.count
+ assert_deprecated { assert_equal 0, Bird.count }
end
assert_kind_of Bird, parrot
assert_not_predicate parrot, :persisted?
diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb
index 1a3a95f168..8b08e40468 100644
--- a/activerecord/test/cases/scoping/named_scoping_test.rb
+++ b/activerecord/test/cases/scoping/named_scoping_test.rb
@@ -50,7 +50,7 @@ class NamedScopingTest < ActiveRecord::TestCase
def test_calling_merge_at_first_in_scope
Topic.class_eval do
- scope :calling_merge_at_first_in_scope, Proc.new { merge(Topic.replied) }
+ scope :calling_merge_at_first_in_scope, Proc.new { merge(Topic.unscoped.replied) }
end
assert_equal Topic.calling_merge_at_first_in_scope.to_a, Topic.replied.to_a
end
@@ -448,7 +448,9 @@ class NamedScopingTest < ActiveRecord::TestCase
end
def test_class_method_in_scope
- assert_equal [topics(:second)], topics(:first).approved_replies.ordered
+ assert_deprecated do
+ assert_equal [topics(:second)], topics(:first).approved_replies.ordered
+ end
end
def test_nested_scoping