-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Preserve order when generating CSV #3575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,5 +150,34 @@ | |
expect(subject[2]).to eq("\n") | ||
end | ||
end | ||
|
||
context 'when more than one page of objects' do | ||
before do | ||
FactoryBot.create_list :player, 100 | ||
end | ||
|
||
let(:objects) { Player.all } | ||
let(:options) { {} } | ||
|
||
it 'generates a csv with all objects' do | ||
expect(subject[2].split("\n").count).to be 101 | ||
end | ||
end | ||
|
||
context 'when objects are ordered' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is okay to you, please also consider matching whole records. This will make sure of order even for other code changes. context 'when objects are ordered' do
# or use before block as before
let!(players) do
FactoryBot.create_list :player, 2 do |player, index|
player.name = "Player #{index}"
end
end
let(:objects) { Player.all.order(name: :desc) }
let(:options) { {} }
# modify the subject block to return the array of objects
it 'preserves the ordering' do
expect(subject[2].split("\n")[1]).to eq('Player 1', 'Player 2')
end
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I incorporated some of your suggestions, but matching the whole record is a bit nontrivial because the pk ids are not predictable when randomizing test seed |
||
before do | ||
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(:options) { {} } | ||
|
||
it 'preserves the ordering' do | ||
expect(subject[2].split("\n")[1]).to include('Player zzz') | ||
end | ||
end | ||
end | ||
end |
Uh oh!
There was an error while loading. Please reload this page.