aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-07-19 07:52:53 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-07-19 18:55:29 +0900
commit1173c7cad3684048c53f2ef9a5c936d9e58e75d0 (patch)
treea4f1c125a8cb84b98e45f2d2d1711ce81731e813 /activerecord/test
parent9fc728cf09adf318bf58c59b7f4ca41f57a6f6b1 (diff)
downloadrails-1173c7cad3684048c53f2ef9a5c936d9e58e75d0.tar.gz
rails-1173c7cad3684048c53f2ef9a5c936d9e58e75d0.tar.bz2
rails-1173c7cad3684048c53f2ef9a5c936d9e58e75d0.zip
Avoid extra scoping in delegating to klass methods in the `scope` block
Since #29301, delegating to klass methods in the `scope` block would cause extra scoping by the receiver itself. The extra scoping would always override intermediate scoping like `unscoped` and caused the regression #33387. To keep the original scoping behavior, should avoid the extra scoping in the `scope` block. Fixes #33387.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/scoping/relation_scoping_test.rb5
-rw-r--r--activerecord/test/models/post.rb1
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/scoping/relation_scoping_test.rb b/activerecord/test/cases/scoping/relation_scoping_test.rb
index f18f1ed981..544adc9b39 100644
--- a/activerecord/test/cases/scoping/relation_scoping_test.rb
+++ b/activerecord/test/cases/scoping/relation_scoping_test.rb
@@ -254,6 +254,11 @@ class RelationScopingTest < ActiveRecord::TestCase
end
end
+ def test_scoping_works_in_the_scope_block
+ expected = SpecialPostWithDefaultScope.unscoped.to_a
+ assert_equal expected, SpecialPostWithDefaultScope.unscoped_all
+ end
+
def test_circular_joins_with_scoping_does_not_crash
posts = Post.joins(comments: :post).scoping do
Post.first(10)
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 54eb5e6783..640cdb33b4 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -253,6 +253,7 @@ class SpecialPostWithDefaultScope < ActiveRecord::Base
self.inheritance_column = :disabled
self.table_name = "posts"
default_scope { where(id: [1, 5, 6]) }
+ scope :unscoped_all, -> { unscoped { all } }
end
class PostThatLoadsCommentsInAnAfterSaveHook < ActiveRecord::Base