fix(groupe-instructeur): a closed groupe with an active groupe is a valid record
This commit is contained in:
parent
f752dd7085
commit
20d4a8153d
2 changed files with 19 additions and 1 deletions
|
@ -22,7 +22,7 @@ class GroupeInstructeur < ApplicationRecord
|
||||||
|
|
||||||
validates :label, presence: true, allow_nil: false
|
validates :label, presence: true, allow_nil: false
|
||||||
validates :label, uniqueness: { scope: :procedure }
|
validates :label, uniqueness: { scope: :procedure }
|
||||||
validates :closed, acceptance: { accept: [false] }, if: -> { self.procedure.groupe_instructeurs.active.one? }
|
validates :closed, acceptance: { accept: [false] }, if: -> { closed_changed? && self.procedure.groupe_instructeurs.active.one? }
|
||||||
|
|
||||||
before_validation -> { label&.strip! }
|
before_validation -> { label&.strip! }
|
||||||
after_save :toggle_routing
|
after_save :toggle_routing
|
||||||
|
|
|
@ -98,6 +98,24 @@ describe GroupeInstructeur, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "active group validations" do
|
||||||
|
context "there is at least one active groupe instructeur" do
|
||||||
|
let!(:gi_active) { create(:groupe_instructeur, procedure:, closed: false) }
|
||||||
|
let!(:gi_closed) { create(:groupe_instructeur, procedure:, closed: true) }
|
||||||
|
before { procedure.defaut_groupe_instructeur.destroy! }
|
||||||
|
|
||||||
|
it "closed is valid when there is one other active groupe" do
|
||||||
|
expect(gi_active).to be_valid
|
||||||
|
expect(gi_closed).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "closed is invalid when there is no active groupe" do
|
||||||
|
gi_active.closed = true
|
||||||
|
expect(gi_active).not_to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assign(procedure_to_assign, instructeur_assigne: instructeur)
|
def assign(procedure_to_assign, instructeur_assigne: instructeur)
|
||||||
|
|
Loading…
Reference in a new issue