Skip to content

Commit

Permalink
Merge pull request #1742 from DFE-Digital/fix-initial-status-change
Browse files Browse the repository at this point in the history
Update application form status after submission
  • Loading branch information
thomasleese authored Oct 6, 2023
2 parents 3a041bd + b5501d9 commit 8ccf13c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
1 change: 0 additions & 1 deletion app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class ApplicationForm < ApplicationRecord
belongs_to :assessor, class_name: "Staff", optional: true
belongs_to :reviewer, class_name: "Staff", optional: true

validates :submitted_at, presence: true, unless: :draft?
validates :awarded_at, absence: true, if: :declined_at?
validates :awarded_at, absence: true, if: :withdrawn_at?
validates :declined_at, absence: true, if: :awarded_at?
Expand Down
19 changes: 10 additions & 9 deletions app/services/submit_application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ def call
return if application_form.submitted_at.present?

ActiveRecord::Base.transaction do
application_form.subjects.compact_blank!
application_form.working_days_since_submission = 0
application_form.requires_preliminary_check =
region.requires_preliminary_check
application_form.submitted_at = Time.zone.now

ApplicationFormStatusUpdater.call(application_form:, user:)
application_form.update!(
subjects: application_form.subjects.compact_blank,
working_days_since_submission: 0,
requires_preliminary_check: region.requires_preliminary_check,
submitted_at: Time.zone.now,
)

assessment = AssessmentFactory.call(application_form:)

create_professional_standing_request(assessment)

if application_form.reduced_evidence_accepted
UpdateAssessmentInductionRequired.call(assessment:)
end

create_professional_standing_request(assessment)

ApplicationFormStatusUpdater.call(application_form:, user:)
end

TeacherMailer
Expand Down
12 changes: 0 additions & 12 deletions spec/models/application_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,6 @@
it { is_expected.to validate_absence_of(:english_language_provider) }
end

context "when submitted" do
before { application_form.status = "submitted" }

it { is_expected.to_not be_valid }

context "with submitted_at" do
before { application_form.submitted_at = Time.zone.now }

it { is_expected.to be_valid }
end
end

context "when awarded and declined" do
before do
application_form.assign_attributes(
Expand Down
14 changes: 14 additions & 0 deletions spec/services/submit_application_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
end
end

describe "application form preliminary check status" do
subject(:submitted?) { application_form.preliminary_check? }

it { is_expected.to be false }

context "when calling the service" do
let(:region) { create(:region, :requires_preliminary_check) }

before { call }

it { is_expected.to be true }
end
end

describe "compacting blank subjects" do
subject(:subjects) { application_form.subjects }

Expand Down

0 comments on commit 8ccf13c

Please sign in to comment.