Define .en_instruction as a scope and remove archived=false filter

This commit is contained in:
Mathieu Magnin 2017-04-12 14:38:01 +02:00
parent 7a9fd77af0
commit 320ff4839f
3 changed files with 24 additions and 20 deletions

View file

@ -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'

View file

@ -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}")

View file

@ -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