Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions app/models/event_procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ class EventProcedure < ApplicationRecord
validates :room_type, presence: true, if: -> { health_insurance? }
validates :urgency, inclusion: [true, false], if: -> { health_insurance? }
validates :payment, presence: true

validates_with CustomAndUrgencyValidator
end
9 changes: 9 additions & 0 deletions app/validations/custom_and_urgency_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class CustomAndUrgencyValidator < ActiveModel::Validator
def validate(record)
return unless record.procedure&.custom && record.urgency

record.errors.add(:base, "EventProcedure cannot have both custom and urgency as true")
end
end
6 changes: 6 additions & 0 deletions spec/models/event_procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@
end

describe "validations" do
let(:event) { build(:event_procedure, urgency: true, procedure_attributes: { custom: true }) }

it { is_expected.to validate_presence_of(:date) }
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) }

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

describe ".enumerations" do
Expand Down
Loading