Procedure: Once deliberation or cadre_juridique have been set, forbid unsetting them
This commit is contained in:
parent
b998425005
commit
c72421fb9e
2 changed files with 33 additions and 0 deletions
|
@ -48,6 +48,8 @@ class Procedure < ApplicationRecord
|
|||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
validate :check_juridique
|
||||
|
||||
before_save :update_juridique_required
|
||||
|
||||
include AASM
|
||||
|
||||
aasm whiny_persistence: true do
|
||||
|
@ -343,6 +345,11 @@ class Procedure < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def update_juridique_required
|
||||
self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?)
|
||||
true
|
||||
end
|
||||
|
||||
def clone_attachment(cloned_procedure, attachment_symbol)
|
||||
attachment = send(attachment_symbol)
|
||||
if attachment.attached?
|
||||
|
|
|
@ -677,4 +677,30 @@ describe Procedure do
|
|||
|
||||
it { expect(Champ.count).to eq(0) }
|
||||
end
|
||||
|
||||
describe '#juridique_required' do
|
||||
it 'automatically jumps to true once cadre_juridique or deliberation have been set' do
|
||||
p = create(
|
||||
:procedure,
|
||||
juridique_required: false,
|
||||
cadre_juridique: nil,
|
||||
)
|
||||
|
||||
expect(p.juridique_required).to be_falsey
|
||||
|
||||
p.update(cadre_juridique: 'cadre')
|
||||
expect(p.juridique_required).to be_truthy
|
||||
|
||||
p.update(cadre_juridique: nil)
|
||||
expect(p.juridique_required).to be_truthy
|
||||
|
||||
p.update_columns(cadre_juridique: nil, juridique_required: false)
|
||||
p.reload
|
||||
expect(p.juridique_required).to be_falsey
|
||||
|
||||
allow(p).to receive(:deliberation).and_return(double('attached?': true))
|
||||
p.save
|
||||
expect(p.juridique_required).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue