diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-11-06 08:29:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-06 08:29:40 +0900 |
commit | ffc1ed9bd54f3cf746f7ddf798e000fc025edef6 (patch) | |
tree | 899877d845bcc4a6d0cd0c3b73070801205faa16 /activerecord/test/cases | |
parent | e0bef22665f93e88f6b2f3ac6bd55543ed0d6343 (diff) | |
download | rails-ffc1ed9bd54f3cf746f7ddf798e000fc025edef6.tar.gz rails-ffc1ed9bd54f3cf746f7ddf798e000fc025edef6.tar.bz2 rails-ffc1ed9bd54f3cf746f7ddf798e000fc025edef6.zip |
`scoping` should respect current class and STI constraint (#29199)
A relation includes `klass`, so it can not be used as it is if current
class is different from `current_scope.klass`. It should be created new
relation by current class to respect the klass and STI constraint.
Fixes #17603.
Fixes #23576.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/scoping/relation_scoping_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/scoping/relation_scoping_test.rb b/activerecord/test/cases/scoping/relation_scoping_test.rb index f3b84d88c2..116f8e83aa 100644 --- a/activerecord/test/cases/scoping/relation_scoping_test.rb +++ b/activerecord/test/cases/scoping/relation_scoping_test.rb @@ -240,6 +240,20 @@ class RelationScopingTest < ActiveRecord::TestCase assert_nil SpecialComment.current_scope end + def test_scoping_respects_current_class + Comment.unscoped do + assert_equal "a comment...", Comment.all.what_are_you + assert_equal "a special comment...", SpecialComment.all.what_are_you + end + end + + def test_scoping_respects_sti_constraint + Comment.unscoped do + assert_equal comments(:greetings), Comment.find(1) + assert_raises(ActiveRecord::RecordNotFound) { SpecialComment.find(1) } + end + end + def test_circular_joins_with_scoping_does_not_crash posts = Post.joins(comments: :post).scoping do Post.first(10) |