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

This commit is contained in:
Mathieu Magnin 2017-04-12 14:48:44 +02:00
parent 320ff4839f
commit 762a11fc6f
5 changed files with 35 additions and 17 deletions

View file

@ -22,7 +22,7 @@ class Users::DossiersController < UsersController
when 'en_instruction'
@user_dossiers.en_instruction.order_by_updated_at
when 'termine'
@user_dossiers.termine
@user_dossiers.termine.order_by_updated_at
when 'invite'
current_user.invites
else

View file

@ -193,9 +193,7 @@ class Dossier < ActiveRecord::Base
scope :en_instruction, -> { where(state: EN_INSTRUCTION) }
def self.termine order = 'ASC'
where(state: TERMINE, archived: false).order("updated_at #{order}")
end
scope :termine, -> { where(state: TERMINE) }
scope :archived, -> { where(archived: true) }
scope :not_archived, -> { where(archived: false) }

View file

@ -45,7 +45,7 @@ class DossiersListGestionnaireService
end
def termine
@termine ||= filter_dossiers.termine
@termine ||= filter_dossiers.termine.not_archived
end
def filter_dossiers

View file

@ -455,18 +455,6 @@ describe Dossier do
it { expect(subject.size).to eq(1) }
end
describe '#a_instruire' do
subject { gestionnaire.dossiers.a_instruire }
it { expect(subject.size).to eq(2) }
end
describe '#termine' do
subject { gestionnaire.dossiers.termine }
it { expect(subject.size).to eq(3) }
end
describe '#en_instruction' do
subject { gestionnaire.dossiers.en_instruction }

View file

@ -345,4 +345,36 @@ describe DossiersListGestionnaireService do
end
end
end
describe 'state filter methods' do
let!(:procedure) { create :procedure }
let!(:dossier) { create(:dossier, procedure: procedure, state: 'draft') }
let!(:dossier2) { create(:dossier, procedure: procedure, state: 'initiated') } #nouveaux
let!(:dossier3) { create(:dossier, procedure: procedure, state: 'initiated') } #nouveaux
let!(:dossier4) { create(:dossier, procedure: procedure, state: 'replied') } #en_attente
let!(:dossier5) { create(:dossier, procedure: procedure, state: 'updated') } #a_traiter
let!(:dossier6) { create(:dossier, procedure: procedure, state: 'received') } #a_instruire
let!(:dossier7) { create(:dossier, procedure: procedure, state: 'received') } #a_instruire
let!(:dossier8) { create(:dossier, procedure: procedure, state: 'closed') } #termine
let!(:dossier9) { create(:dossier, procedure: procedure, state: 'refused') } #termine
let!(:dossier10) { create(:dossier, procedure: procedure, state: 'without_continuation') } #termine
let!(:dossier11) { create(:dossier, procedure: procedure, state: 'closed') } #termine
let!(:dossier12) { create(:dossier, procedure: procedure, state: 'initiated', archived: true) } #a_traiter #archived
let!(:dossier13) { create(:dossier, procedure: procedure, state: 'replied', archived: true) } #en_attente #archived
let!(:dossier14) { create(:dossier, procedure: procedure, state: 'closed', archived: true) } #termine #archived
describe '#termine' do
subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).termine }
it { expect(subject.size).to eq(4) }
it { expect(subject).to include(dossier8, dossier9, dossier10, dossier11) }
end
describe '#a_instruire' do
subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).a_instruire }
it { expect(subject.size).to eq(2) }
it { expect(subject).to include(dossier6, dossier7) }
end
end
end