aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorBenjamin Quorning <benjamin@quorning.net>2016-06-24 09:49:42 +0200
committerBenjamin Quorning <benjamin@quorning.net>2016-06-24 11:43:48 +0200
commit763de2ac1c85d3e9f82639783a55244d6c0517c2 (patch)
treeb3ea6e9eec0572399f4d9d4d0c36867f86290ed9 /activerecord/test
parentaf834fb2c03358fe9a1b8fd9ec36eb5658a63260 (diff)
downloadrails-763de2ac1c85d3e9f82639783a55244d6c0517c2.tar.gz
rails-763de2ac1c85d3e9f82639783a55244d6c0517c2.tar.bz2
rails-763de2ac1c85d3e9f82639783a55244d6c0517c2.zip
Optimize ActiveRecord::Result#last
If you only want the last element of a result set, there's no need to create all of hash_rows. Also, add a test.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/result_test.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/test/cases/result_test.rb b/activerecord/test/cases/result_test.rb
index 565593c500..83dc5347e0 100644
--- a/activerecord/test/cases/result_test.rb
+++ b/activerecord/test/cases/result_test.rb
@@ -27,6 +27,11 @@ module ActiveRecord
{'col_1' => 'row 1 col 1', 'col_2' => 'row 1 col 2'}, result.first)
end
+ test "last returns last row as a hash" do
+ assert_equal(
+ {'col_1' => 'row 3 col 1', 'col_2' => 'row 3 col 2'}, result.last)
+ end
+
test "each with block returns row hashes" do
result.each do |row|
assert_equal ['col_1', 'col_2'], row.keys