Skip to content

Commit 464440c

Browse files
authored
Merge pull request #2797 from tmesquita/empty-relation-csv-exports-fix
fixing error raised when converting an empty array/relation into csv
2 parents 34c55b0 + afe1398 commit 464440c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/rails_admin/support/csv_converter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
module RailsAdmin
55
class CSVConverter
66
def initialize(objects = [], schema = {})
7+
@fields = []
8+
@associations = []
9+
710
return self if (@objects = objects).blank?
811

912
@model = objects.dup.first.class

spec/rails_admin/support/csv_converter_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,14 @@
112112
end
113113
end
114114
end
115+
116+
context "when objects is empty" do
117+
let(:objects) { [] }
118+
let(:options) { {} }
119+
120+
it "generates an empty csv" do
121+
expect(subject[2]).to eq("\n")
122+
end
123+
end
115124
end
116125
end

0 commit comments

Comments
 (0)