aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2014-09-08 13:12:04 +0930
committerMatthew Draper <matthew@trebex.net>2014-09-08 13:12:04 +0930
commitc3207a12be646483e7e0ce8c916e730e7ea5070d (patch)
treee79b4ac9fc7787e63612f6ee3c76a24da4b812c9 /activerecord/test/cases
parent42e69c352fc58f9af2c09dd7e8a7fa70bfe46898 (diff)
parent72d1663bc7353813f3ec5f4e841a2243baedb473 (diff)
downloadrails-c3207a12be646483e7e0ce8c916e730e7ea5070d.tar.gz
rails-c3207a12be646483e7e0ce8c916e730e7ea5070d.tar.bz2
rails-c3207a12be646483e7e0ce8c916e730e7ea5070d.zip
Merge pull request #16825 from cristianbica/fix-ar-nested-arrays
Fix query with nested array in Active Record
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/finder_test.rb28
-rw-r--r--activerecord/test/cases/relation/where_test.rb4
2 files changed, 31 insertions, 1 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index befbec4e1b..fc91b728c2 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -521,6 +521,34 @@ class FinderTest < ActiveRecord::TestCase
assert_equal [1,2,3,5,6,7,8,9], Comment.where(id: [1..2, 3, 5, 6..8, 9]).to_a.map(&:id).sort
end
+ def test_find_on_hash_conditions_with_array_of_ranges
+ assert_equal [1,2,6,7,8], Comment.where(id: [1..2, 6..8]).to_a.map(&:id).sort
+ end
+
+ def test_find_on_hash_conditions_with_nested_array_of_integers_and_ranges
+ assert_deprecated do
+ assert_equal [1,2,3,5,6,7,8,9], Comment.where(id: [[1..2], 3, [5], 6..8, 9]).to_a.map(&:id).sort
+ end
+ end
+
+ def test_find_on_hash_conditions_with_array_of_integers_and_arrays
+ assert_deprecated do
+ assert_equal [1,2,3,5,6,7,8,9], Comment.where(id: [[1, 2], 3, 5, [6, [7], 8], 9]).to_a.map(&:id).sort
+ end
+ end
+
+ def test_find_on_hash_conditions_with_nested_array_of_integers_and_ranges_and_nils
+ assert_deprecated do
+ assert_equal [1,3,4,5], Topic.where(parent_id: [[2..6], nil]).to_a.map(&:id).sort
+ end
+ end
+
+ def test_find_on_hash_conditions_with_nested_array_of_integers_and_ranges_and_more_nils
+ assert_deprecated do
+ assert_equal [], Topic.where(parent_id: [[7..10, nil, [nil]], [nil]]).to_a.map(&:id).sort
+ end
+ end
+
def test_find_on_multiple_hash_conditions
assert Topic.where(author_name: "David", title: "The First Topic", replies_count: 1, approved: false).find(1)
assert_raise(ActiveRecord::RecordNotFound) { Topic.where(author_name: "David", title: "The First Topic", replies_count: 1, approved: true).find(1) }
diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb
index 580ea98910..39c8afdd23 100644
--- a/activerecord/test/cases/relation/where_test.rb
+++ b/activerecord/test/cases/relation/where_test.rb
@@ -181,7 +181,9 @@ module ActiveRecord
end
def test_where_with_table_name_and_nested_empty_array
- assert_equal [], Post.where(:id => [[]]).to_a
+ assert_deprecated do
+ assert_equal [], Post.where(:id => [[]]).to_a
+ end
end
def test_where_with_empty_hash_and_no_foreign_key