Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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_be_true

private

def custom_and_urgency_cannot_be_true
return unless procedure&.custom && urgency

errors.add(:base, "Custom procedures can't be urgent")
end
end
21 changes: 21 additions & 0 deletions spec/models/event_procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@
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(:user) { create(:user) }
let(:procedure) { build(:procedure, custom: true, user: user) }
let(:event) { build(:event_procedure, urgency: true, procedure: procedure) }

it "is invalid when custom and urgency true" do
expect(event).not_to be_valid
expect(event.errors[:base]).to include("Custom procedures can't be urgent")
end

it "is valid when urgency is false and custom is true" do
event.urgency = false
expect(event).to be_valid
end

it "is valid when urgency is true and custom is false" do
event.procedure.custom = false
expect(event).to be_valid
end
end
end

describe ".enumerations" do
Expand Down
2 changes: 1 addition & 1 deletion spec/operations/event_procedures/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
health_insurance_id: create(:health_insurance).id,
patient_service_number: "1234567890",
date: Time.zone.now.to_date,
urgency: true,
urgency: false,
room_type: EventProcedures::RoomTypes::WARD,
payment: EventProcedures::Payments::HEALTH_INSURANCE,
patient_attributes: { id: create(:patient).id },
Expand Down