Skip to content

Commit

Permalink
Query#to_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
tessro committed May 6, 2012
1 parent 2f45fba commit 967af6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/oculus/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def succeeded?
complete? && !error
end

def to_csv
CSV.generate do |csv|
results.each do |row|
csv << row
end
end
end

class << self
def create(attributes)
query = new(attributes)
Expand Down
6 changes: 6 additions & 0 deletions spec/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,10 @@
query.execute(connection)
query.succeeded?.should be false
end

it "exports to CSV" do
query = Oculus::Query.new
query.results = [['id', 'name'], [1, 'Paul']]
query.to_csv.should == "id,name\n1,Paul\n"
end
end

0 comments on commit 967af6b

Please sign in to comment.