aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2017-07-18 13:11:01 -0400
committerGitHub <noreply@github.com>2017-07-18 13:11:01 -0400
commit41d51b07160484b616e48658ddb76d1d1d13a6c0 (patch)
tree8667114fb9c227ad1459782f8405583828040a2f /activerecord/test/cases
parent8ebe1f2feed30809abb3f114242dda7379e66e4b (diff)
parent9aa04315febfb37b50f52471a2837c40313a2d5f (diff)
downloadrails-41d51b07160484b616e48658ddb76d1d1d13a6c0.tar.gz
rails-41d51b07160484b616e48658ddb76d1d1d13a6c0.tar.bz2
rails-41d51b07160484b616e48658ddb76d1d1d13a6c0.zip
Merge pull request #29834 from kamipo/fix_unscoping_default_scope_with_sti_association
Fix unscoping `default_scope` in STI associations
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/scoping/default_scoping_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb
index a5061cfce7..a8c79628e7 100644
--- a/activerecord/test/cases/scoping/default_scoping_test.rb
+++ b/activerecord/test/cases/scoping/default_scoping_test.rb
@@ -392,6 +392,24 @@ class DefaultScopingTest < ActiveRecord::TestCase
Comment.joins(:post).to_a
end
+ def test_sti_association_with_unscoped_not_affected_by_default_scope
+ post = posts(:thinking)
+ comments = [comments(:does_it_hurt)]
+
+ post.special_comments.update_all(deleted_at: Time.now)
+
+ assert_raises(ActiveRecord::RecordNotFound) { Post.joins(:special_comments).find(post.id) }
+ assert_equal [], post.special_comments
+
+ SpecialComment.unscoped do
+ assert_equal post, Post.joins(:special_comments).find(post.id)
+ assert_equal comments, Post.joins(:special_comments).find(post.id).special_comments
+ assert_equal comments, Post.eager_load(:special_comments).find(post.id).special_comments
+ assert_equal comments, Post.includes(:special_comments).find(post.id).special_comments
+ assert_equal comments, Post.preload(:special_comments).find(post.id).special_comments
+ end
+ end
+
def test_default_scope_select_ignored_by_aggregations
assert_equal DeveloperWithSelect.all.to_a.count, DeveloperWithSelect.count
end