aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMiguel Grazziotin <miguelgraz@gmail.com>2015-05-29 17:42:54 -0300
committerMiguel Grazziotin <miguelgraz@gmail.com>2015-05-29 17:42:54 -0300
commitdcee87c9fc2f16e240a90c564a82d23e9f9e9181 (patch)
tree99eb0d1f9cf8c6f98ee16e22aa8694f8d428e48a /activerecord
parentf7c0d133f982e4607c8b78e13fef6edafa7eb590 (diff)
downloadrails-dcee87c9fc2f16e240a90c564a82d23e9f9e9181.tar.gz
rails-dcee87c9fc2f16e240a90c564a82d23e9f9e9181.tar.bz2
rails-dcee87c9fc2f16e240a90c564a82d23e9f9e9181.zip
[#20338] WIP: first basic implementation and specs
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb6
-rw-r--r--activerecord/test/cases/finder_test.rb12
2 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 6020aa238f..e75ff6fd69 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -459,7 +459,11 @@ module ActiveRecord
end
if result.size == expected_size
- result
+ # result
+ records_by_id = result.each_with_object(Hash.new) do |record, by_id|
+ by_id[record.id] = record
+ end
+ ids.first(expected_size).collect { |id| records_by_id[id] }
else
raise_record_not_found_exception!(ids, result.size, expected_size)
end
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 4b819a82e8..f9d75fc937 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -48,6 +48,18 @@ class FinderTest < ActiveRecord::TestCase
end
end
+ def test_find_with_ids_returning_ordered
+ records = Topic.find([4,2,5])
+ assert_equal 'The Fourth Topic of the day', records[0].title
+ assert_equal 'The Second Topic of the day', records[1].title
+ assert_equal 'The Fifth Topic of the day', records[2].title
+
+ records = Topic.find(4,2,5)
+ assert_equal 'The Fourth Topic of the day', records[0].title
+ assert_equal 'The Second Topic of the day', records[1].title
+ assert_equal 'The Fifth Topic of the day', records[2].title
+ end
+
def test_find_passing_active_record_object_is_deprecated
assert_deprecated do
Topic.find(Topic.last)