1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/result_test.rb
Carlos Antonio da Silva 755069ee4e Merge pull request #10993 from Empact/result-each-enumerator
Change Result#each to return an Enumerator when called without a block.
2013-06-25 20:07:59 -03:00

32 lines
815 B
Ruby

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