aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2013-06-18 03:32:01 -0700
committerBen Woosley <ben.woosley@gmail.com>2013-06-18 15:34:18 -0700
commitd6cfbaea72e1b2852ed3206c0ffea8a572048369 (patch)
tree69ae89c3fd99c398b319bb2e438ace16d44b5eed /activerecord/test/cases
parent353a398bee68c5ea99d76ac7601de0a5fef6f4a5 (diff)
downloadrails-d6cfbaea72e1b2852ed3206c0ffea8a572048369.tar.gz
rails-d6cfbaea72e1b2852ed3206c0ffea8a572048369.tar.bz2
rails-d6cfbaea72e1b2852ed3206c0ffea8a572048369.zip
Change Result#each to return an Enumerator when called without a block.
As with #10992, this lets us call #with_index, etc on the results.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/result_test.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/test/cases/result_test.rb b/activerecord/test/cases/result_test.rb
new file mode 100644
index 0000000000..c305d273fb
--- /dev/null
+++ b/activerecord/test/cases/result_test.rb
@@ -0,0 +1,33 @@
+require "cases/helper"
+
+module ActiveRecord
+ class ResultTest < ActiveRecord::TestCase
+
+ def result
+ Result.new(['col_1', 'col_2'], [
+ ['row 1 col 1', 'row 1 col 2'],
+ ['row 2 col 1', 'row 2 col 2']
+ ])
+ end
+
+ def test_to_hash_returns_row_hashes
+ assert_equal [
+ {'col_1' => 'row 1 col 1', 'col_2' => 'row 1 col 2'},
+ {'col_1' => 'row 2 col 1', 'col_2' => 'row 2 col 2'}
+ ], result.to_hash
+ end
+
+ def test_each_with_block_returns_row_hashes
+ result.each do |row|
+ assert_equal ['col_1', 'col_2'], row.keys
+ end
+ end
+
+ def test_each_without_block_returns_an_enumerator
+ result.each.with_index do |row, index|
+ assert_equal ['col_1', 'col_2'], row.keys
+ assert_kind_of Integer, index
+ end
+ end
+ end
+end