feat(dossier): allow to rebase champs with value made mandatory

This commit is contained in:
Paul Chavard 2022-12-22 13:08:04 +01:00
parent 5a7ddd52d2
commit 4c516a6991
2 changed files with 16 additions and 1 deletions

View file

@ -43,7 +43,7 @@ module DossierRebaseConcern
when :drop_down_other
!change[:from] && change[:to]
when :mandatory
change[:from] && !change[:to]
(change[:from] && !change[:to]) || can_change_mandatory?(change)
when :type_champ, :condition
false
else
@ -160,4 +160,8 @@ module DossierRebaseConcern
def purge_piece_justificative_file(champ)
ActiveStorage::Attachment.where(id: champ.piece_justificative_file.ids).delete_all
end
def can_change_mandatory?(change)
!champs.filter { _1.stable_id == change[:stable_id] }.any?(&:blank?)
end
end

View file

@ -72,6 +72,17 @@ describe Dossier do
expect(dossier.pending_changes).not_to be_empty
expect(dossier.can_rebase?).to be_falsey
end
context 'with a value' do
before do
dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'a value')
end
it 'should be true' do
expect(dossier.pending_changes).not_to be_empty
expect(dossier.can_rebase?).to be_truthy
end
end
end
context 'with type de champ change type' do