diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-31 16:11:43 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-31 17:51:38 +0900 |
commit | c11109da934d71b1d0a139da36e52423844fa36e (patch) | |
tree | e4b733a72cae63606a6026247a10a9816fc22a93 | |
parent | 7c800fe5e338540ef195f071a7f3604ed4197f3f (diff) | |
download | rails-c11109da934d71b1d0a139da36e52423844fa36e.tar.gz rails-c11109da934d71b1d0a139da36e52423844fa36e.tar.bz2 rails-c11109da934d71b1d0a139da36e52423844fa36e.zip |
Fix `default_scoped` with defined `default_scope` on STI model
This regression is caused by d1249c1.
If STI model is defined `default_scope`, `base_rel` is not respected.
I fixed to merge `base_rel` in that case.
-rw-r--r-- | activerecord/lib/active_record/scoping/default.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb index ba5cc29ac1..70b2693b28 100644 --- a/activerecord/lib/active_record/scoping/default.rb +++ b/activerecord/lib/active_record/scoping/default.rb @@ -107,7 +107,11 @@ module ActiveRecord if default_scope_override # The user has defined their own default scope method, so call that - evaluate_default_scope { default_scope } + evaluate_default_scope do + if scope = default_scope + (base_rel ||= relation).merge(scope) + end + end elsif default_scopes.any? base_rel ||= relation evaluate_default_scope do diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index b4bbdc6dad..fb5a7bcc31 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -1,6 +1,7 @@ require "cases/helper" require "models/author" require "models/company" +require "models/membership" require "models/person" require "models/post" require "models/project" @@ -29,7 +30,7 @@ end class InheritanceTest < ActiveRecord::TestCase include InheritanceTestHelper - fixtures :companies, :projects, :subscribers, :accounts, :vegetables + fixtures :companies, :projects, :subscribers, :accounts, :vegetables, :memberships def test_class_with_store_full_sti_class_returns_full_name with_store_full_sti_class do @@ -435,6 +436,10 @@ class InheritanceTest < ActiveRecord::TestCase assert_nothing_raised { Company.of_first_firm } assert_nothing_raised { Client.of_first_firm } end + + def test_inheritance_with_default_scope + assert_equal 1, SelectedMembership.count(:all) + end end class InheritanceComputeTypeTest < ActiveRecord::TestCase |