Skip to content

Commit

Permalink
handle empty datasets correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mwlang committed Feb 21, 2010
1 parent d7852b9 commit 48a930e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.1.4
0.1.5
5 changes: 4 additions & 1 deletion lib/extensions/export.rb
Expand Up @@ -31,8 +31,11 @@ def initialize(fd, dataset, options)
end

def output
first_row = @dataset.first
return unless first_row

quot = @options[:quote_char]
@columns ||= @dataset.first.keys.sort_by{|x|x.to_s}
@columns ||= first_row.keys.sort_by{|x|x.to_s}

if @options[:headers] == true
@file.puts @columns.map{|col| "#{quot}#{col}#{quot}"}.join(@options[:delimiter])
Expand Down
7 changes: 7 additions & 0 deletions test/test_export.rb
Expand Up @@ -50,6 +50,13 @@ module ExportTest
DB[:nodes].all.size.should == 12
end

it "should do nothing with empty result sets" do
mem_stream = StringIO.new("", "w+")
DB[:nodes].filter(:name => 'bogus').export(mem_stream)
mem_stream.pos = 0
mem_stream.read.should == ""
end

it "should export everything tab delimited w/o quotes" do
mem_stream = StringIO.new("", "w+")
DB[:nodes].export(mem_stream)
Expand Down

0 comments on commit 48a930e

Please sign in to comment.