diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 9db4e35c1..1ac98809d 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -20,7 +20,7 @@ class Users::DossiersController < UsersController when 'a_traiter' @user_dossiers.en_construction.order_by_updated_at when 'en_instruction' - @user_dossiers.en_instruction + @user_dossiers.en_instruction.order_by_updated_at when 'termine' @user_dossiers.termine when 'invite' diff --git a/app/models/dossier.rb b/app/models/dossier.rb index f563ffcac..3842a1c48 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -191,9 +191,7 @@ class Dossier < ActiveRecord::Base where(state: A_INSTRUIRE, archived: false).order("updated_at #{order}") end - def self.en_instruction order = 'ASC' - where(state: EN_INSTRUCTION, archived: false).order("updated_at #{order}") - end + scope :en_instruction, -> { where(state: EN_INSTRUCTION) } def self.termine order = 'ASC' where(state: TERMINE, archived: false).order("updated_at #{order}") diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 37ca54b3a..754d7e3ed 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -418,23 +418,23 @@ describe Dossier do let(:procedure_admin) { create(:procedure, administrateur: admin) } let(:procedure_admin_2) { create(:procedure, administrateur: admin_2) } + let!(:dossier) { create(:dossier, procedure: procedure_admin, state: 'draft') } + let!(:dossier2) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux + let!(:dossier3) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux + let!(:dossier4) { create(:dossier, procedure: procedure_admin, state: 'replied') } #en_attente + let!(:dossier5) { create(:dossier, procedure: procedure_admin, state: 'updated') } #a_traiter + let!(:dossier6) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire + let!(:dossier7) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire + let!(:dossier8) { create(:dossier, procedure: procedure_admin, state: 'closed') } #termine + let!(:dossier9) { create(:dossier, procedure: procedure_admin, state: 'refused') } #termine + let!(:dossier10) { create(:dossier, procedure: procedure_admin, state: 'without_continuation') } #termine + let!(:dossier11) { create(:dossier, procedure: procedure_admin_2, state: 'closed') } #termine + let!(:dossier12) { create(:dossier, procedure: procedure_admin, state: 'initiated', archived: true) } #a_traiter #archived + let!(:dossier13) { create(:dossier, procedure: procedure_admin, state: 'replied', archived: true) } #en_attente #archived + let!(:dossier14) { create(:dossier, procedure: procedure_admin, state: 'closed', archived: true) } #termine #archived + before do create :assign_to, gestionnaire: gestionnaire, procedure: procedure_admin - - create(:dossier, procedure: procedure_admin, state: 'draft') - create(:dossier, procedure: procedure_admin, state: 'initiated') #nouveaux - create(:dossier, procedure: procedure_admin, state: 'initiated') #nouveaux - create(:dossier, procedure: procedure_admin, state: 'replied') #en_attente - create(:dossier, procedure: procedure_admin, state: 'updated') #a_traiter - create(:dossier, procedure: procedure_admin, state: 'received') #a_instruire - create(:dossier, procedure: procedure_admin, state: 'received') #a_instruire - create(:dossier, procedure: procedure_admin, state: 'closed') #termine - create(:dossier, procedure: procedure_admin, state: 'refused') #termine - create(:dossier, procedure: procedure_admin, state: 'without_continuation') #termine - create(:dossier, procedure: procedure_admin_2, state: 'closed') #termine - create(:dossier, procedure: procedure_admin, state: 'initiated', archived: true) #a_traiter #archived - create(:dossier, procedure: procedure_admin, state: 'replied', archived: true) #en_attente #archived - create(:dossier, procedure: procedure_admin, state: 'closed', archived: true) #termine #archived end describe '#nouveaux' do @@ -466,8 +466,14 @@ describe Dossier do it { expect(subject.size).to eq(3) } end - end + describe '#en_instruction' do + subject { gestionnaire.dossiers.en_instruction } + + it { expect(subject.size).to eq(2) } + it { expect(subject).to include(dossier6, dossier7) } + end + end end describe '#cerfa_available?' do