Add dossier_legacy_state helper

This commit is contained in:
Paul Chavard 2018-11-07 14:46:22 +01:00
parent a524c72add
commit 0fe59a7c65
2 changed files with 51 additions and 0 deletions

View file

@ -31,4 +31,21 @@ module DossierHelper
state = I18n.t(dossier.state, scope: [:activerecord, :attributes, :dossier, :state])
lower ? state.downcase : state
end
def dossier_legacy_state(dossier)
case dossier.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
dossier.state
end
end
end

View file

@ -166,4 +166,38 @@ RSpec.describe DossierHelper, type: :helper do
end
end
end
describe '.dossier_legacy_state' do
subject { dossier_legacy_state(dossier) }
context 'when the dossier is en instruction' do
let(:dossier) { create(:dossier) }
it { is_expected.to eq('brouillon') }
end
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