Project

General

Profile

Feature #9143 » csv-freeze-headers.patch

avit (Andrew Vit), 11/23/2013 05:05 AM

View differences:

lib/csv.rb
# prepare converted and unconverted copies
row = @headers if row.nil?
@headers = convert_fields(@headers, true)
@headers.map { |h| h.freeze if h.is_a? String }
if @return_headers # return headers
return self.class::Row.new(@headers, row, true)
test/csv/test_interface.rb
end
end
def test_write_hash_with_string_keys
File.unlink(@path)
lines = [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]
CSV.open( @path, "wb", headers: true ) do |csv|
csv << lines.first.keys
lines.each { |line| csv << line }
end
CSV.open( @path, "rb", headers: true ) do |csv|
csv.each do |line|
csv.headers.each_with_index do |header, h|
keys = line.to_hash.keys
assert_equal(String, keys[h].class)
assert_equal(header.object_id, keys[h].object_id)
end
end
end
end
def test_write_hash_with_headers_array
File.unlink(@path)
(1-1/2)