diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-12-16 15:46:56 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-12-16 15:46:56 -0800 |
commit | a6f88d0924649c70d74efe5a09f9abd3117c3920 (patch) | |
tree | d048e55de1c12bf291317fe5c4441f1129cb420e /activerecord/test/cases/relation/where_test.rb | |
parent | 0dea33f770305f32ed7476f520f7c1ff17434fdc (diff) | |
parent | 8062a307942cb3f7a83bfc1a8cd81e3a1f8edc5b (diff) | |
download | rails-a6f88d0924649c70d74efe5a09f9abd3117c3920.tar.gz rails-a6f88d0924649c70d74efe5a09f9abd3117c3920.tar.bz2 rails-a6f88d0924649c70d74efe5a09f9abd3117c3920.zip |
Merge pull request #12873 from martinemde/fix-where-assoc-nil
Better support for AR:B.where(belongs_to_assoc: val) which previously generated invalid SQL
Diffstat (limited to 'activerecord/test/cases/relation/where_test.rb')
-rw-r--r-- | activerecord/test/cases/relation/where_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index 56e4605ccc..937f226b1d 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -35,6 +35,21 @@ module ActiveRecord assert_equal Post.where(author_id: 1).to_sql, Post.where(author: author).to_sql end + def test_belongs_to_nil_where + assert_equal Post.where(author_id: nil).to_sql, Post.where(author: nil).to_sql + end + + def test_belongs_to_array_value_where + assert_equal Post.where(author_id: [1,2]).to_sql, Post.where(author: [1,2]).to_sql + end + + def test_belongs_to_nested_relation_where + expected = Post.where(author_id: Author.where(id: [1,2])).to_sql + actual = Post.where(author: Author.where(id: [1,2])).to_sql + + assert_equal expected, actual + end + def test_belongs_to_nested_where parent = Comment.new parent.id = 1 @@ -55,6 +70,25 @@ module ActiveRecord assert_equal expected.to_sql, actual.to_sql end + def test_polymorphic_nested_array_where + treasure = Treasure.new + treasure.id = 1 + hidden = HiddenTreasure.new + hidden.id = 2 + + expected = PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: [treasure, hidden]) + actual = PriceEstimate.where(estimate_of: [treasure, hidden]) + + assert_equal expected.to_sql, actual.to_sql + 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])) + + assert_equal expected.to_sql, actual.to_sql + end + def test_polymorphic_sti_shallow_where treasure = HiddenTreasure.new treasure.id = 1 |