Skip to content

Commit

Permalink
Do not validate Org when creating a Vacancy
Browse files Browse the repository at this point in the history
The has_many association validates the associated object by default.

This is causing issues with some existing Organisations have an
pre-existing invalid email since we added email validation to the Org.
model.

Disabling the check on Org validity when creating a Vacancy will allow
the publishers to still publish nw vacancies.
  • Loading branch information
scruti committed Oct 24, 2024
1 parent 5f0412d commit 3d5e76d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class Vacancy < ApplicationRecord
has_many :job_applications, dependent: :destroy
has_one :equal_opportunities_report, dependent: :destroy
has_many :organisation_vacancies, dependent: :destroy
has_many :organisations, through: :organisation_vacancies, dependent: :destroy, after_add: :refresh_geolocation, after_remove: :refresh_geolocation
has_many :organisations,
through: :organisation_vacancies,
dependent: :destroy,
validate: false, # If an organisation has some validation error, we do not want to block users from creating a vacancy.
after_add: :refresh_geolocation,
after_remove: :refresh_geolocation
has_many :markers, dependent: :destroy
has_many :feedbacks, dependent: :destroy, inverse_of: :vacancy

Expand Down
10 changes: 10 additions & 0 deletions spec/models/vacancy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,16 @@
it { is_expected.to be_valid }
end
end

describe "organisation association" do
it "is valid when an associated organisation has validation errors" do
publisher = build_stubbed(:publisher)
invalid_school = build_stubbed(:school, email: "invalid")
expect(invalid_school).not_to be_valid

expect(Vacancy.new(organisations: [invalid_school], publisher: publisher)).to be_valid
end
end
end

describe "#geolocation" do
Expand Down

0 comments on commit 3d5e76d

Please sign in to comment.