зеркало из https://github.com/github/ruby.git
Fixed to write_headers option behavior when given no rows.
[Bug #9988][ruby-core:63375] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2c69f7b278
Коммит
9c38a08f28
|
@ -1561,6 +1561,12 @@ class CSV
|
|||
|
||||
# track our own lineno since IO gets confused about line-ends is CSV fields
|
||||
@lineno = 0
|
||||
|
||||
# make sure headers have been assigned
|
||||
if header_row? and [Array, String].include? @use_headers.class and @write_headers
|
||||
parse_headers # won't read data for Array or String
|
||||
self << @headers
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -1677,9 +1683,8 @@ class CSV
|
|||
#
|
||||
def <<(row)
|
||||
# make sure headers have been assigned
|
||||
if header_row? and [Array, String].include? @use_headers.class
|
||||
if header_row? and [Array, String].include? @use_headers.class and !@write_headers
|
||||
parse_headers # won't read data for Array or String
|
||||
self << @headers if @write_headers
|
||||
end
|
||||
|
||||
# handle CSV::Row objects and Hashes
|
||||
|
|
|
@ -295,6 +295,19 @@ class TestCSV::Interface < TestCSV
|
|||
end
|
||||
end
|
||||
|
||||
def test_write_headers_empty
|
||||
File.unlink(@path)
|
||||
|
||||
CSV.open( @path, "wb", headers: "b|a|c",
|
||||
write_headers: true,
|
||||
col_sep: "|" ) do |csv|
|
||||
end
|
||||
|
||||
File.open(@path, "rb") do |f|
|
||||
assert_equal("b|a|c", f.gets.strip)
|
||||
end
|
||||
end
|
||||
|
||||
def test_append # aliased add_row() and puts()
|
||||
File.unlink(@path)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче