helpers: allow dossier_display_state
to take a state as input
This allow to use either: - `dossier_display_state(dossier)` - `dossier_display_state(:en_construction)`
This commit is contained in:
parent
0b54af822f
commit
c7a307553c
2 changed files with 11 additions and 27 deletions
|
@ -47,9 +47,10 @@ module DossierHelper
|
||||||
dossier.brouillon? && dossier.procedure.close?
|
dossier.brouillon? && dossier.procedure.close?
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossier_display_state(dossier, lower: false)
|
def dossier_display_state(dossier_or_state, lower: false)
|
||||||
state = I18n.t(dossier.state, scope: [:activerecord, :attributes, :dossier, :state])
|
state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state
|
||||||
lower ? state.downcase : state
|
display_state = I18n.t(state, scope: [:activerecord, :attributes, :dossier, :state])
|
||||||
|
lower ? display_state.downcase : display_state
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossier_legacy_state(dossier)
|
def dossier_legacy_state(dossier)
|
||||||
|
|
|
@ -132,37 +132,20 @@ RSpec.describe DossierHelper, type: :helper do
|
||||||
expect(subject).to eq('Refusé')
|
expect(subject).to eq('Refusé')
|
||||||
end
|
end
|
||||||
|
|
||||||
context "lower: true" do
|
context 'when requesting lowercase' do
|
||||||
subject { dossier_display_state(dossier, lower: true) }
|
subject { dossier_display_state(dossier, lower: true) }
|
||||||
|
|
||||||
it 'brouillon is brouillon' do
|
it 'lowercases the display name' do
|
||||||
dossier.brouillon!
|
dossier.brouillon!
|
||||||
expect(subject).to eq('brouillon')
|
expect(subject).to eq('brouillon')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'en_construction is En construction' do
|
|
||||||
dossier.en_construction!
|
|
||||||
expect(subject).to eq('en construction')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accepte is traité' do
|
context 'when providing directly a state name' do
|
||||||
dossier.accepte!
|
subject { dossier_display_state(:brouillon) }
|
||||||
expect(subject).to eq('accepté')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'en_instruction is reçu' do
|
it 'generates a display name for the given state' do
|
||||||
dossier.en_instruction!
|
expect(subject).to eq('Brouillon')
|
||||||
expect(subject).to eq('en instruction')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'sans_suite is traité' do
|
|
||||||
dossier.sans_suite!
|
|
||||||
expect(subject).to eq('sans suite')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'refuse is traité' do
|
|
||||||
dossier.refuse!
|
|
||||||
expect(subject).to eq('refusé')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue