From 4c6171d6056a346a953792a954853d14c000dc90 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 15 Feb 2019 11:34:54 +0900 Subject: 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. --- activerecord/test/cases/relations_test.rb | 30 +++++++++++++--------- .../test/cases/scoping/named_scoping_test.rb | 6 +++-- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'activerecord/test') 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 -- cgit v1.2.3