diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-07-18 10:22:05 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-07-19 00:50:40 +0900 |
commit | d13f54d50a166d49c683f79d49341185788faed8 (patch) | |
tree | 14468a7ece9ce1bfcc4aa06c027a50f722146170 /activerecord/test/cases/scoping | |
parent | 58c567adaeba1208522640e7890db9e07cbb768a (diff) | |
download | rails-d13f54d50a166d49c683f79d49341185788faed8.tar.gz rails-d13f54d50a166d49c683f79d49341185788faed8.tar.bz2 rails-d13f54d50a166d49c683f79d49341185788faed8.zip |
Fix unscoping `default_scope` in STI associations
Since 5c71000, it has lost to be able to unscope `default_scope` in STI
associations. This change will use `.empty_scope?` instead of
`.values.empty?` to regard as an empty scope if only have
`type_condition`.
Diffstat (limited to 'activerecord/test/cases/scoping')
-rw-r--r-- | activerecord/test/cases/scoping/default_scoping_test.rb | 16 |
1 files changed, 16 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..83f3868f3f 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -392,6 +392,22 @@ 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 + end + end + def test_default_scope_select_ignored_by_aggregations assert_equal DeveloperWithSelect.all.to_a.count, DeveloperWithSelect.count end |