[#1946] Once durees de conservation have been set, forbid unsetting them
This commit is contained in:
parent
bfa601d832
commit
346687bd33
2 changed files with 31 additions and 0 deletions
|
@ -56,6 +56,7 @@ class Procedure < ApplicationRecord
|
|||
validates :duree_conservation_dossiers_hors_ds, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, unless: :durees_conservation_required
|
||||
|
||||
before_save :update_juridique_required
|
||||
before_save :update_durees_conservation_required
|
||||
|
||||
include AASM
|
||||
|
||||
|
@ -383,4 +384,9 @@ class Procedure < ApplicationRecord
|
|||
'column' => column
|
||||
}
|
||||
end
|
||||
|
||||
def update_durees_conservation_required
|
||||
self.durees_conservation_required ||= duree_conservation_dossiers_hors_ds.present? && duree_conservation_dossiers_dans_ds.present?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -233,6 +233,31 @@ describe Procedure do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#duree_de_conservation_required' do
|
||||
it 'automatically jumps to true once both durees de conservation have been set' do
|
||||
p = build(
|
||||
:procedure,
|
||||
durees_conservation_required: false,
|
||||
duree_conservation_dossiers_dans_ds: nil,
|
||||
duree_conservation_dossiers_hors_ds: nil
|
||||
)
|
||||
p.save
|
||||
expect(p.durees_conservation_required).to be_falsey
|
||||
|
||||
p.duree_conservation_dossiers_hors_ds = 3
|
||||
p.save
|
||||
expect(p.durees_conservation_required).to be_falsey
|
||||
|
||||
p.duree_conservation_dossiers_dans_ds = 6
|
||||
p.save
|
||||
expect(p.durees_conservation_required).to be_truthy
|
||||
|
||||
p.duree_conservation_dossiers_dans_ds = nil
|
||||
p.save
|
||||
expect(p.durees_conservation_required).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe '#types_de_champ_ordered' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
|
|
Loading…
Reference in a new issue