diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-10-20 15:30:38 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-10-20 15:30:38 -0200 |
commit | 2ba92bb8090b676b664c793f45cbe40e51cb1832 (patch) | |
tree | ba9fe49dc5ff7dd9f53f82520d724375dba85369 /activerecord/test | |
parent | d68e81afa0e5b2697755a34e9b1d11b9b5d1df9d (diff) | |
parent | 209f3b30af1beffbf1cd2fd933c3453661239b07 (diff) | |
download | rails-2ba92bb8090b676b664c793f45cbe40e51cb1832.tar.gz rails-2ba92bb8090b676b664c793f45cbe40e51cb1832.tar.bz2 rails-2ba92bb8090b676b664c793f45cbe40e51cb1832.zip |
Merge branch 'fix-21955'
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index cd19a7a5bc..eb94870a35 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -2181,6 +2181,26 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [bulb1, bulb2], car.all_bulbs.sort_by(&:id) end + test "can unscope and where the default scope of the associated model" do + Car.has_many :other_bulbs, -> { unscope(where: [:name]).where(name: 'other') }, class_name: "Bulb" + car = Car.create! + bulb1 = Bulb.create! name: "defaulty", car: car + bulb2 = Bulb.create! name: "other", car: car + + assert_equal [bulb1], car.bulbs + assert_equal [bulb2], car.other_bulbs + end + + test "can rewhere the default scope of the associated model" do + Car.has_many :old_bulbs, -> { rewhere(name: 'old') }, class_name: "Bulb" + car = Car.create! + bulb1 = Bulb.create! name: "defaulty", car: car + bulb2 = Bulb.create! name: "old", car: car + + assert_equal [bulb1], car.bulbs + assert_equal [bulb2], car.old_bulbs + end + test 'unscopes the default scope of associated model when used with include' do car = Car.create! bulb = Bulb.create! name: "other", car: car |