Skip to content

Commit

Permalink
Ignore ApplicationWorkHistoryBreak#application_form_id
Browse files Browse the repository at this point in the history
We don't need the application_form_id on the
application_work_history_break table, we use the breakable column to
link it to an application form.

This commit ignores the application_form_id and makes sure the deletion
of the history break is going to happen when deleting a candidate, just
like before.

We made application_form_id nullable here
9d60480
  • Loading branch information
CatalinVoineag committed Aug 21, 2024
1 parent 9f19fb8 commit 874221f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/models/application_work_history_break.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationWorkHistoryBreak < ApplicationRecord
belongs_to :breakable, polymorphic: true, touch: true
self.ignored_columns += %w[application_form_id]

before_save -> { self.application_form_id = breakable_id }, if: -> { application_form_id.nil? }
belongs_to :breakable, polymorphic: true, touch: true

audited associated_with: :breakable

Expand Down
5 changes: 5 additions & 0 deletions app/models/candidate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def delete
experienceable_id: application_form_ids,
experienceable_type: 'ApplicationForm',
).delete_all

ApplicationWorkHistoryBreak.where(
breakable_id: application_form_ids,
breakable_type: 'ApplicationForm',
).delete_all
end

private
Expand Down
1 change: 1 addition & 0 deletions app/workers/delete_test_applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ def candidates_to_purge

def delete_work_experiences(ids)
ApplicationExperience.where(experienceable_id: ids, experienceable_type: 'ApplicationForm').delete_all
ApplicationWorkHistoryBreak.where(breakable_id: ids, breakable_type: 'ApplicationForm').delete_all
end
end
1 change: 0 additions & 1 deletion config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ shared:
- degree_institution_uuid
- degree_grade_uuid
application_work_history_breaks:
- application_form_id
- breakable_type
- breakable_id
- created_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@
work_break.update(application_work_history_break)

expect(application_work_history_break.reason).to eq('Updated reason.')
expect(application_work_history_break.breakable_id).to eq(
application_work_history_break.application_form_id,
)
expect(application_work_history_break.breakable_type).to eq(
'ApplicationForm',
)
end
end
end
2 changes: 2 additions & 0 deletions spec/models/candidate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
application_choice = create(:application_choice, application_form:)
application_work_experience = create(:application_work_experience, experienceable: application_form)
application_volunteering_experience = create(:application_volunteering_experience, experienceable: application_form)
application_work_history_break = create(:application_work_history_break, breakable: application_form)
application_qualification = create(:application_qualification, application_form:)
application_reference = create(:reference, application_form:)

Expand All @@ -92,6 +93,7 @@
expect { application_choice.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { application_work_experience.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { application_volunteering_experience.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { application_work_history_break.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { application_qualification.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { application_reference.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
Expand Down

0 comments on commit 874221f

Please sign in to comment.