diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-17 13:56:55 -0800 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-17 13:56:55 -0800 |
commit | f1866e81a392f61552bc03b4f9a54b97d65e98f0 (patch) | |
tree | 4168ff2a31a39b8a9c6161fedc5fa6ee01c9b35f /activerecord/test/cases/relation | |
parent | 011711ecc9bfe9bdbc1fc17d57d511373954d415 (diff) | |
parent | 359adaedd95293af3abde954279ad51e11856d57 (diff) | |
download | rails-f1866e81a392f61552bc03b4f9a54b97d65e98f0.tar.gz rails-f1866e81a392f61552bc03b4f9a54b97d65e98f0.tar.bz2 rails-f1866e81a392f61552bc03b4f9a54b97d65e98f0.zip |
Merge pull request #22365 from phuibonhoa/phuibonhoa/polymorphic_where_multiple_types
Fixed `where` for polymorphic associations when passed an array containing different types.
Diffstat (limited to 'activerecord/test/cases/relation')
-rw-r--r-- | activerecord/test/cases/relation/where_test.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index bc6378b90e..56a2b5b8c6 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -2,6 +2,7 @@ require "cases/helper" require "models/author" require "models/binary" require "models/cake_designer" +require "models/car" require "models/chef" require "models/comment" require "models/edge" @@ -14,7 +15,7 @@ require "models/vertex" module ActiveRecord class WhereTest < ActiveRecord::TestCase - fixtures :posts, :edges, :authors, :binaries, :essays + fixtures :posts, :edges, :authors, :binaries, :essays, :cars, :treasures, :price_estimates def test_where_copies_bind_params author = authors(:david) @@ -114,6 +115,17 @@ module ActiveRecord assert_equal expected.to_sql, actual.to_sql end + def test_polymorphic_array_where_multiple_types + treasure_1 = treasures(:diamond) + treasure_2 = treasures(:sapphire) + car = cars(:honda) + + expected = [price_estimates(:diamond), price_estimates(:sapphire_1), price_estimates(:sapphire_2), price_estimates(:honda)].sort + actual = PriceEstimate.where(estimate_of: [treasure_1, treasure_2, car]).to_a.sort + + assert_equal expected, actual + end + def test_polymorphic_nested_relation_where expected = PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: Treasure.where(id: [1,2])) actual = PriceEstimate.where(estimate_of: Treasure.where(id: [1,2])) |