dossiers: put last updated dossiers first

This commit is contained in:
Pierre de La Morinerie 2018-06-27 15:03:13 +00:00
parent a544b2e2a3
commit f2ee88b278
2 changed files with 19 additions and 2 deletions

View file

@ -88,8 +88,8 @@ module NewUser
end
def index
@user_dossiers = current_user.dossiers.includes(:procedure).page(page)
@dossiers_invites = current_user.dossiers_invites.includes(:procedure).page(page)
@user_dossiers = current_user.dossiers.includes(:procedure).order_by_updated_at.page(page)
@dossiers_invites = current_user.dossiers_invites.includes(:procedure).order_by_updated_at.page(page)
@current_tab = current_tab(@user_dossiers.count, @dossiers_invites.count)

View file

@ -418,6 +418,23 @@ describe NewUser::DossiersController, type: :controller do
it { expect(assigns(:current_tab)).to eq('mes-dossiers') }
end
end
describe 'sort order' do
before do
Timecop.freeze(4.days.ago) { create(:dossier, user: user) }
Timecop.freeze(2.days.ago) { create(:dossier, user: user) }
Timecop.freeze(4.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
Timecop.freeze(2.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
get(:index)
end
it 'displays the most recently updated dossiers first' do
expect(assigns(:user_dossiers).first.updated_at.to_date).to eq(2.days.ago.to_date)
expect(assigns(:user_dossiers).second.updated_at.to_date).to eq(4.days.ago.to_date)
expect(assigns(:dossiers_invites).first.updated_at.to_date).to eq(2.days.ago.to_date)
expect(assigns(:dossiers_invites).second.updated_at.to_date).to eq(4.days.ago.to_date)
end
end
end
describe '#ask_deletion' do