-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a form object for selecting a claim school
When someone is on the student loans journey and they already have a school associated with their claim, we ask them to confirm this. The form object here looks similar to the one for choosing the correct school #2704.
- Loading branch information
1 parent
6c773c6
commit 32c19f8
Showing
10 changed files
with
113 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/forms/journeys/teacher_student_loan_reimbursement/select_claim_school_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Journeys | ||
module TeacherStudentLoanReimbursement | ||
class SelectClaimSchoolForm < Form | ||
attribute :change_school, :boolean | ||
attribute :claim_school_id, :string | ||
|
||
delegate :address, :name, to: :claim_school, prefix: true, allow_nil: true | ||
delegate :eligibility, to: :claim | ||
delegate :claim_school_somewhere_else?, to: :eligibility | ||
|
||
def save | ||
claim.update(eligibility_attributes:) | ||
claim.reset_eligibility_dependent_answers(["claim_school_id"]) | ||
true | ||
end | ||
|
||
def claim_school_id | ||
@claim_school_id ||= permitted_params.fetch(:claim_school_id, claim_school&.id) | ||
end | ||
|
||
private | ||
|
||
def claim_school | ||
@claim_school ||= claim.tps_school_for_student_loan_in_previous_financial_year || claim.eligibility.claim_school | ||
end | ||
|
||
def change_school? | ||
change_school || claim_school_id.nil? || claim_school_id == "somewhere_else" | ||
end | ||
|
||
def eligibility_attributes | ||
return {claim_school_id: nil, claim_school_somewhere_else: true} if change_school? | ||
|
||
{claim_school_id:, claim_school_somewhere_else: false} | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 10 additions & 12 deletions
22
app/views/student_loans/claims/select_claim_school.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
spec/forms/journeys/teacher_student_loan_reimbursement/select_claim_school_form_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::TeacherStudentLoanReimbursement::SelectClaimSchoolForm, type: :model do | ||
before do | ||
create( | ||
:journey_configuration, | ||
:student_loans, | ||
current_academic_year: AcademicYear.new(2023) | ||
) | ||
end | ||
|
||
describe "#save" do | ||
subject(:save) { form.save } | ||
|
||
let(:claim) { CurrentClaim.new(claims: [create(:claim, policy: Policies::StudentLoans)]) } | ||
let(:journey) { Journeys::TeacherStudentLoanReimbursement } | ||
let(:params) { ActionController::Parameters.new } | ||
let(:form) { described_class.new(claim:, journey:, params:) } | ||
let!(:school) { create(:school, :eligible_for_journey, journey:) } | ||
|
||
context "when choosing a school" do | ||
let(:params) do | ||
ActionController::Parameters.new({ | ||
claim: { | ||
claim_school_id: school.id | ||
} | ||
}) | ||
end | ||
|
||
it "updates the claim with the correct school attributes" do | ||
expect { save }.to change { claim.reload.eligibility.claim_school_id }.to(school.id) | ||
end | ||
|
||
it "resets the somewhere_else attribute" do | ||
expect { save }.to change { claim.reload.eligibility.claim_school_somewhere_else }.to eq(false) | ||
end | ||
end | ||
|
||
context "with an existing school association and wants to change school" do | ||
let(:params) do | ||
ActionController::Parameters.new({ | ||
claim: { | ||
claim_school_id: nil | ||
} | ||
}) | ||
end | ||
|
||
before do | ||
claim.eligibility.update!(claim_school_id: school.id, claim_school_somewhere_else: false) | ||
end | ||
|
||
it "resets the school association" do | ||
expect { save }.to change { claim.reload.eligibility.claim_school_id }.to(nil) | ||
end | ||
|
||
it "resets the somewhere_else attribute" do | ||
expect { save }.to change { claim.reload.eligibility.claim_school_somewhere_else }.to eq(true) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.