diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-06-25 20:07:59 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-06-25 20:07:59 -0300 |
commit | 755069ee4e954ae66f6a8bb4a810c2dbb1bbc0d7 (patch) | |
tree | 149bfdb6f2dc447f1d45a0938f58d624b0fe980e /activerecord/test/cases | |
parent | a1bcf1fb921006bf154ded168b1119220ef9af68 (diff) | |
parent | d6cfbaea72e1b2852ed3206c0ffea8a572048369 (diff) | |
download | rails-755069ee4e954ae66f6a8bb4a810c2dbb1bbc0d7.tar.gz rails-755069ee4e954ae66f6a8bb4a810c2dbb1bbc0d7.tar.bz2 rails-755069ee4e954ae66f6a8bb4a810c2dbb1bbc0d7.zip |
Merge pull request #10993 from Empact/result-each-enumerator
Change Result#each to return an Enumerator when called without a block.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/result_test.rb | 32 |
1 files changed, 32 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..b6c583dbf5 --- /dev/null +++ b/activerecord/test/cases/result_test.rb @@ -0,0 +1,32 @@ +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 |