Fixes #3451: New created overviews should be at the end of the overview list

This commit is contained in:
Bola Ahmed Buari 2021-03-18 10:03:38 +01:00 committed by Thorsten Eckel
parent 8e85508fa4
commit dadb564d1f
2 changed files with 17 additions and 1 deletions

View file

@ -63,7 +63,7 @@ class Overview < ApplicationModel
def fill_prio def fill_prio
return true if prio.present? return true if prio.present?
self.prio = Overview.count + 1 self.prio = Overview.maximum(:prio) + 1
true true
end end

View file

@ -73,4 +73,20 @@ RSpec.describe Overview, type: :model do
expect(overviews.third).to eq(overview2.id) expect(overviews.third).to eq(overview2.id)
end end
end end
describe '#fill_prio' do
it 'fill an empty prio with the maximum prio plus one' do
overview1 = create(:overview, prio: 1)
overview2 = create(:overview, prio: 200)
overview3 = create(:overview, prio: nil)
overviews = described_class.all.order(prio: :asc).pluck(:id)
expect(overviews.first).to eq(overview1.id)
expect(overviews.second).to eq(overview2.id)
expect(overviews.last).to eq(overview3.id)
end
end
end end