Skip to content

Commit

Permalink
Update program type before save is committed
Browse files Browse the repository at this point in the history
`after_save :update_program_type!` sets the program type after the record has been saved to the database. This doesn't update the database record unless it is saved again.
  • Loading branch information
Nitemaeric committed Nov 22, 2024
1 parent 137a46e commit cbf3d15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Course < ApplicationRecord
after_validation :remove_unnecessary_enrichments_validation_message
before_save :set_applications_open_from

after_save :update_program_type!, if: :saved_change_to_funding?
before_save :update_program_type!, if: :will_save_change_to_funding?

belongs_to :provider

Expand Down
21 changes: 14 additions & 7 deletions spec/features/find/result_page_filters/salary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,56 @@ def given_i_have_salaried_and_fee_courses
:secondary,
:open,
site_statuses:,
program_type: :higher_education_programme
program_type: :higher_education_programme,
funding: :fee
)
@course_scitt_salaried_programme = create(
:course,
:secondary,
:open,
site_statuses:,
program_type: :scitt_salaried_programme
program_type: :scitt_salaried_programme,
funding: :salary
)
@course_higher_education_salaried_programme = create(
:course,
:secondary,
:open,
site_statuses:,
program_type: :higher_education_salaried_programme
program_type: :higher_education_salaried_programme,
funding: :salary
)
@course_school_direct_training_programme = create(
:course,
:secondary,
:open,
site_statuses:,
program_type: :school_direct_training_programme
program_type: :school_direct_training_programme,
funding: :fee
)
@course_school_direct_salaried_training_programme = create(
:course,
:secondary,
:open,
site_statuses:,
program_type: :school_direct_salaried_training_programme
program_type: :school_direct_salaried_training_programme,
funding: :salary
)
@course_scitt_programme = create(
:course,
:secondary,
:open,
site_statuses:,
program_type: :scitt_programme
program_type: :scitt_programme,
funding: :fee
)
@course_pg_teaching_apprenticeship = create(
:course,
:secondary,
:open,
site_statuses:,
program_type: :pg_teaching_apprenticeship
program_type: :pg_teaching_apprenticeship,
funding: :apprenticeship
)
end

Expand Down

0 comments on commit cbf3d15

Please sign in to comment.