Dossier: move state translation to model dossier
This commit is contained in:
parent
078cf03c03
commit
87e731bc75
4 changed files with 46 additions and 33 deletions
|
@ -277,6 +277,23 @@ class Dossier < ApplicationRecord
|
||||||
DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later
|
DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def old_state_value
|
||||||
|
case state
|
||||||
|
when Dossier.states.fetch(:en_construction)
|
||||||
|
'initiated'
|
||||||
|
when Dossier.states.fetch(:en_instruction)
|
||||||
|
'received'
|
||||||
|
when Dossier.states.fetch(:accepte)
|
||||||
|
'closed'
|
||||||
|
when Dossier.states.fetch(:refuse)
|
||||||
|
'refused'
|
||||||
|
when Dossier.states.fetch(:sans_suite)
|
||||||
|
'without_continuation'
|
||||||
|
else
|
||||||
|
state
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def update_state_dates
|
def update_state_dates
|
||||||
|
|
|
@ -43,20 +43,7 @@ class DossierSerializer < ActiveModel::Serializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def state
|
def state
|
||||||
case object.state
|
object.old_state_value
|
||||||
when Dossier.states.fetch(:en_construction)
|
|
||||||
'initiated'
|
|
||||||
when Dossier.states.fetch(:en_instruction)
|
|
||||||
'received'
|
|
||||||
when Dossier.states.fetch(:accepte)
|
|
||||||
'closed'
|
|
||||||
when Dossier.states.fetch(:refuse)
|
|
||||||
'refused'
|
|
||||||
when Dossier.states.fetch(:sans_suite)
|
|
||||||
'without_continuation'
|
|
||||||
else
|
|
||||||
object.state
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def simplified_state
|
def simplified_state
|
||||||
|
|
|
@ -1004,4 +1004,32 @@ describe Dossier do
|
||||||
it { expect(long_expired_dossier).to be_retention_expired }
|
it { expect(long_expired_dossier).to be_retention_expired }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'old_state_value' do
|
||||||
|
subject { dossier.old_state_value }
|
||||||
|
|
||||||
|
context 'when the dossier is en instruction' do
|
||||||
|
let(:dossier) { create(:dossier, :en_instruction) }
|
||||||
|
|
||||||
|
it { is_expected.to eq('received') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the dossier is accepte' do
|
||||||
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:accepte)) }
|
||||||
|
|
||||||
|
it { is_expected.to eq('closed') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the dossier is refuse' do
|
||||||
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:refuse)) }
|
||||||
|
|
||||||
|
it { is_expected.to eq('refused') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the dossier is sans_suite' do
|
||||||
|
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:sans_suite)) }
|
||||||
|
|
||||||
|
it { is_expected.to eq('without_continuation') }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,25 +13,6 @@ describe DossierSerializer do
|
||||||
let(:dossier) { create(:dossier, :en_instruction) }
|
let(:dossier) { create(:dossier, :en_instruction) }
|
||||||
|
|
||||||
it { is_expected.to include(received_at: dossier.en_instruction_at) }
|
it { is_expected.to include(received_at: dossier.en_instruction_at) }
|
||||||
it { is_expected.to include(state: 'received') }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the dossier is accepte' do
|
|
||||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:accepte)) }
|
|
||||||
|
|
||||||
it { is_expected.to include(state: 'closed') }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the dossier is refuse' do
|
|
||||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:refuse)) }
|
|
||||||
|
|
||||||
it { is_expected.to include(state: 'refused') }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the dossier is sans_suite' do
|
|
||||||
let(:dossier) { create(:dossier, state: Dossier.states.fetch(:sans_suite)) }
|
|
||||||
|
|
||||||
it { is_expected.to include(state: 'without_continuation') }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue