Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate community clinic ODS code doesn't match organisation #2756

Merged
merged 1 commit into from
Jan 21, 2025
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
8 changes: 6 additions & 2 deletions app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ class Location < ApplicationRecord
validates :team, presence: true
end

with_options if: :community_clinic? do
validates :ods_code, exclusion: { in: :organisation_ods_code }
end

with_options if: :generic_clinic? do
validates :ods_code, comparison: { equal_to: :organisation_ods_code }
validates :ods_code, inclusion: { in: :organisation_ods_code }
end

with_options if: :gp_practice? do
Expand All @@ -92,6 +96,6 @@ def dfe_number
private

def organisation_ods_code
team&.organisation&.ods_code
[team&.organisation&.ods_code]
end
end
16 changes: 12 additions & 4 deletions spec/models/location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,22 @@
it { should validate_presence_of(:name) }

context "with a community clinic" do
subject(:location) { build(:community_clinic, ods_code: "abc") }
subject(:location) { build(:community_clinic, organisation:) }

let(:organisation) { create(:organisation) }

it { should_not validate_presence_of(:gias_establishment_number) }
it { should_not validate_presence_of(:gias_local_authority_code) }

it { should_not validate_presence_of(:ods_code) }
it { should validate_uniqueness_of(:ods_code).ignoring_case_sensitivity }

it do
expect(location).to validate_exclusion_of(:ods_code).in_array(
[organisation.ods_code]
)
end

it { should_not validate_presence_of(:urn) }
it { should validate_uniqueness_of(:urn) }
end
Expand All @@ -71,12 +79,12 @@
it { should_not validate_presence_of(:gias_establishment_number) }
it { should_not validate_presence_of(:gias_local_authority_code) }

it { should validate_presence_of(:ods_code) }
it { should_not validate_presence_of(:ods_code) }
it { should validate_uniqueness_of(:ods_code).ignoring_case_sensitivity }

it do
expect(location).to validate_comparison_of(:ods_code).is_equal_to(
organisation.ods_code
expect(location).to validate_inclusion_of(:ods_code).in_array(
[organisation.ods_code]
)
end

Expand Down
Loading