Skip to content

Commit

Permalink
Merge pull request #2797 from tmesquita/empty-relation-csv-exports-fix
Browse files Browse the repository at this point in the history
fixing error raised when converting an empty array/relation into csv
  • Loading branch information
mshibuya authored Dec 22, 2016
2 parents 34c55b0 + afe1398 commit 464440c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rails_admin/support/csv_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
module RailsAdmin
class CSVConverter
def initialize(objects = [], schema = {})
@fields = []
@associations = []

return self if (@objects = objects).blank?

@model = objects.dup.first.class
Expand Down
9 changes: 9 additions & 0 deletions spec/rails_admin/support/csv_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,14 @@
end
end
end

context "when objects is empty" do
let(:objects) { [] }
let(:options) { {} }

it "generates an empty csv" do
expect(subject[2]).to eq("\n")
end
end
end
end

0 comments on commit 464440c

Please # to comment.