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..021fc1fc1 100644 --- a/spec/rails_admin/support/csv_converter_spec.rb +++ b/spec/rails_admin/support/csv_converter_spec.rb @@ -166,11 +166,13 @@ context 'when objects are ordered' do before do - FactoryBot.create_list :player, 30 + FactoryBot.create_list :player, 2 do |player, index| + player.name = "Player #{index}" + end FactoryBot.create :player, name: 'Player zzz' end - let(:objects) { Player.all.order('name desc') } + let(:objects) { Player.all.order(name: :desc) } let(:options) { {} } it 'preserves the ordering' do