diff --git a/lib/rails_admin/support/csv_converter.rb b/lib/rails_admin/support/csv_converter.rb index 431fe234b..df4f75a1c 100644 --- a/lib/rails_admin/support/csv_converter.rb +++ b/lib/rails_admin/support/csv_converter.rb @@ -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 diff --git a/spec/rails_admin/support/csv_converter_spec.rb b/spec/rails_admin/support/csv_converter_spec.rb index 21be44fe6..c2f60a24a 100644 --- a/spec/rails_admin/support/csv_converter_spec.rb +++ b/spec/rails_admin/support/csv_converter_spec.rb @@ -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