Merge pull request #8326 from tchak/feat-allow-rebase-champs-with-value-made-mandatory

feat(dossier): allow to rebase champs with value made mandatory
This commit is contained in:
mfo 2022-12-22 13:49:09 +01:00 committed by GitHub
commit f7cdbe56ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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