Skip to content

Commit

Permalink
code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
pcai committed Jul 12, 2023
1 parent d90183f commit 8f5bf70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
11 changes: 5 additions & 6 deletions lib/rails_admin/support/csv_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@ def generate_csv_string(options)

if @objects.respond_to?(:page)
page_num = 1
batch = @objects.page(page_num)
while batch.any?
loop do
batch = @objects.page(page_num)
break if batch.blank?

batch.each { |object| csv << generate_csv_row(object) }
page_num += 1
batch = @objects.page(page_num)
end
else
@objects.each do |object|
csv << generate_csv_row(object)
end
@objects.each { |object| csv << generate_csv_row(object) }
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions spec/rails_admin/support/csv_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,16 @@

context 'when objects are ordered' do
before do
FactoryBot.create_list :player, 30
FactoryBot.create :player, name: 'Player zzz'
FactoryBot.create_list :player, 2 do |player, index|
player.name = "Player #{index}"
end
end

let(:objects) { Player.all.order('name desc') }
let(:objects) { Player.all.order(name: :desc) }
let(:options) { {} }

it 'preserves the ordering' do
expect(subject[2].split("\n")[1]).to include('Player zzz')
expect(subject[2].split("\n")[1]).to include('Player 2')
end
end
end
Expand Down

0 comments on commit 8f5bf70

Please sign in to comment.