Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/models/event_procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ class EventProcedure < ApplicationRecord
validates :room_type, presence: true, if: -> { health_insurance? }
validates :urgency, inclusion: [true, false], if: -> { health_insurance? }
validates :payment, presence: true

validate :custom_and_urgency_cannot_both_be_true

private

def custom_and_urgency_cannot_both_be_true
return unless procedure&.custom && urgency

errors.add(:base, "EventProcedure cannot have both custom and urgency as true")
end
end
8 changes: 8 additions & 0 deletions spec/models/event_procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
it { is_expected.to validate_presence_of(:patient_service_number) }
it { is_expected.to validate_presence_of(:room_type) }
it { is_expected.to validate_presence_of(:payment) }

context "when validating custom and urgency" do
let(:event) { build(:event_procedure, urgency: true, procedure_attributes: { custom: true }) }

it "is invalid when both are true" do
expect(event).not_to be_valid
end
end
end

describe ".enumerations" do
Expand Down
Loading