From 8f5bf704d6206d40ddff788df6acaeb57e2e9ab1 Mon Sep 17 00:00:00 2001 From: Peter Cai <222655+pcai@users.noreply.github.com> Date: Wed, 12 Jul 2023 16:07:18 +0000 Subject: [PATCH] code review suggestions --- lib/rails_admin/support/csv_converter.rb | 11 +++++------ spec/rails_admin/support/csv_converter_spec.rb | 9 +++++---- 2 files changed, 10 insertions(+), 10 deletions(-) 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