aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-08-15 21:39:40 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-08-15 21:41:54 +0900
commit56b870f243c1a73a1d15638500e5aa5e7ae9a1cc (patch)
tree20cfa559644eafcbdf42c0dc8a05065fa92525e4 /activerecord/test/cases/associations/has_many_through_associations_test.rb
parentfbeebded22f53337df339285164352f298639c63 (diff)
downloadrails-56b870f243c1a73a1d15638500e5aa5e7ae9a1cc.tar.gz
rails-56b870f243c1a73a1d15638500e5aa5e7ae9a1cc.tar.bz2
rails-56b870f243c1a73a1d15638500e5aa5e7ae9a1cc.zip
Through scope should not be affected by scoping
Follow up of #29834. Fixes #30266.
Diffstat (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 968c0eb944..f8ea51225a 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -1261,6 +1261,25 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal 0, users[2].family_members.to_a.size
end
+ def test_through_scope_is_affected_by_unscoping
+ author = authors(:david)
+
+ expected = author.comments.to_a
+ FirstPost.unscoped do
+ assert_equal expected.sort_by(&:id), author.comments_on_first_posts.sort_by(&:id)
+ end
+ end
+
+ def test_through_scope_isnt_affected_by_scoping
+ author = authors(:david)
+
+ expected = author.comments_on_first_posts.to_a
+ FirstPost.where(id: 2).scoping do
+ author.comments_on_first_posts.reset
+ assert_equal expected.sort_by(&:id), author.comments_on_first_posts.sort_by(&:id)
+ end
+ end
+
def test_incorrectly_ordered_through_associations
assert_raises(ActiveRecord::HasManyThroughOrderError) do
DeveloperWithIncorrectlyOrderedHasManyThrough.create(