Skip to content

Commit

Permalink
Merge pull request #1783 from oruen/optimize-csv-converter
Browse files Browse the repository at this point in the history
ActiveRecord csv export optimization.
  • Loading branch information
mshibuya committed Oct 24, 2013
2 parents 334965f + 725ab85 commit a70b2fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/rails_admin/support/csv_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def initialize(objects = [], schema = {})

def to_csv(options)
options ||= {}
return '' if @objects.blank?

# encoding shenanigans first
@encoding_from = UTF8_ENCODINGS.include?(@abstract_model.encoding) ? 'UTF-8' : @abstract_model.encoding
Expand All @@ -66,7 +65,8 @@ def to_csv(options)
end
end.flatten
end
@objects.each do |o|
method = @objects.respond_to?(:find_each) ? :find_each : :each
@objects.send(method) do |o|


csv << @fields.map do |field|
Expand Down
3 changes: 2 additions & 1 deletion spec/rails_admin/support/csv_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
end
end

objects = [FactoryGirl.create(:player)]
FactoryGirl.create :player
objects = Player.all
schema = {:only =>[:number, :name]}
expect(RailsAdmin::CSVConverter.new(objects, schema).to_csv({})[2]).to match /Number,Name/
end
Expand Down

0 comments on commit a70b2fe

Please sign in to comment.