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

Use ApplicationWorkHistoryBreak#breakable column #9723

Merged
merged 1 commit into from
Aug 20, 2024
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
2 changes: 1 addition & 1 deletion app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ApplicationForm < ApplicationRecord
has_many :application_volunteering_experiences, as: :experienceable
has_many :application_qualifications
has_many :application_references
has_many :application_work_history_breaks
has_many :application_work_history_breaks, as: :breakable
has_many :emails

belongs_to :previous_application_form, class_name: 'ApplicationForm', optional: true, inverse_of: 'subsequent_application_form'
Expand Down
11 changes: 8 additions & 3 deletions app/models/application_work_history_break.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
class ApplicationWorkHistoryBreak < ApplicationRecord
include TouchApplicationChoices

belongs_to :application_form, touch: true
belongs_to :breakable, polymorphic: true, optional: true
belongs_to :application_form, touch: true, optional: true
belongs_to :breakable, polymorphic: true

before_save -> { self.breakable = application_form }, if: -> { breakable.nil? }
before_save -> { self.application_form_id = breakable_id }, if: -> { application_form_id.nil? }

audited associated_with: :application_form

def application_form=(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tested by our specs already, lots of them will fail if this is not here

super
self.breakable = value
end

def length
((end_date.year * 12) + end_date.month) - ((start_date.year * 12) + start_date.month) - 1
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/application_work_history_break_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'rails_helper'

RSpec.describe ApplicationWorkHistoryBreak do
it { is_expected.to belong_to(:application_form).touch(true) }
it { is_expected.to belong_to(:breakable).optional }
it { is_expected.to belong_to(:application_form).touch(true).optional }
it { is_expected.to belong_to(:breakable) }

describe 'auditing', :with_audited do
it { is_expected.to be_audited.associated_with :application_form }
Expand Down
Loading