-
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.
Merge pull request #2725 from DFE-Digital/CAPT-1600
CAPT-1600 Form object for /subjects-taught (TSLR)
- Loading branch information
Showing
16 changed files
with
259 additions
and
165 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
app/forms/journeys/teacher_student_loan_reimbursement/subjects_taught_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,73 @@ | ||
module Journeys | ||
module TeacherStudentLoanReimbursement | ||
class SubjectsTaughtForm < Form | ||
attr_accessor :subjects_taught | ||
|
||
attribute :taught_eligible_subjects, :boolean | ||
attribute :biology_taught, :boolean | ||
attribute :chemistry_taught, :boolean | ||
attribute :physics_taught, :boolean | ||
attribute :computing_taught, :boolean | ||
attribute :languages_taught, :boolean | ||
|
||
validate :one_subject_must_be_selected | ||
|
||
before_validation :determine_dependant_attributes | ||
|
||
def save | ||
return false unless valid? | ||
|
||
update!(eligibility_attributes: attributes) | ||
end | ||
|
||
def claim_school_name | ||
@claim_school_name ||= claim.eligibility.claim_school_name | ||
end | ||
|
||
def subject_attributes | ||
Policies::StudentLoans::Eligibility::SUBJECT_ATTRIBUTES | ||
end | ||
|
||
def subject_taught_selected?(subject) | ||
public_send(subject) == true if respond_to?(subject) | ||
end | ||
|
||
private | ||
|
||
def determine_dependant_attributes | ||
subject_attributes.each(&method(:update_subject_taught_attribute)) | ||
assign_attributes(taught_eligible_subjects: selected_subjects.empty? ? nil : !no_subject_taught_selected?) | ||
end | ||
|
||
def update_subject_taught_attribute(subject) | ||
assign_attributes(subject => subject.to_s.in?(selected_subjects)) | ||
end | ||
|
||
def no_subject_taught_selected? | ||
"none_taught".in?(selected_subjects) | ||
end | ||
|
||
def selected_subjects | ||
permitted_params.fetch(:subjects_taught, []) | ||
end | ||
|
||
def permitted_params | ||
@permitted_params ||= params.fetch(:claim, {}).permit(subjects_taught: []) | ||
end | ||
|
||
def any_subjects_taught_selected? | ||
subject_attributes.any?(&method(:subject_taught_selected?)) | ||
end | ||
|
||
def not_taught_eligible_subjects? | ||
taught_eligible_subjects == false | ||
end | ||
|
||
def one_subject_must_be_selected | ||
return if not_taught_eligible_subjects? || any_subjects_taught_selected? | ||
|
||
errors.add(:subjects_taught, i18n_errors_path(:select_subject)) | ||
end | ||
end | ||
end | ||
end |
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
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
46 changes: 0 additions & 46 deletions
46
app/views/additional_payments/claims/disciplinary_action.html.erb
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
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
Oops, something went wrong.