-
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 #2937 from DFE-Digital/fe-teaching-qualification
[LUPEYALPHA-554] add teaching qualification form to FE journey
- Loading branch information
Showing
10 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/forms/journeys/further_education_payments/teaching_qualification_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,39 @@ | ||
module Journeys | ||
module FurtherEducationPayments | ||
class TeachingQualificationForm < Form | ||
attribute :teaching_qualification, :string | ||
|
||
validates :teaching_qualification, | ||
presence: {message: i18n_error_message(:inclusion)}, | ||
inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)} | ||
|
||
def radio_options | ||
[ | ||
OpenStruct.new( | ||
id: "yes", | ||
name: "Yes" | ||
), | ||
OpenStruct.new( | ||
id: "not-yet", | ||
name: "Not yet, I am currently enrolled on one and working towards completing it" | ||
), | ||
OpenStruct.new( | ||
id: "no-but-planned", | ||
name: "No, but I plan to enrol on one in the next 12 months" | ||
), | ||
OpenStruct.new( | ||
id: "no-not-planned", | ||
name: "No, and I do not plan to enrol on one in the next 12 months " | ||
) | ||
] | ||
end | ||
|
||
def save | ||
return false unless valid? | ||
|
||
journey_session.answers.assign_attributes(teaching_qualification:) | ||
journey_session.save! | ||
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
7 changes: 0 additions & 7 deletions
7
app/views/further_education_payments/claims/qualification.html.erb
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
app/views/further_education_payments/claims/teaching_qualification.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: @form, url: claim_path(current_journey_routing_name), method: :patch, builder: GOVUKDesignSystemFormBuilder::FormBuilder, html: { novalidate: false } do |f| %> | ||
<%= f.govuk_error_summary %> | ||
|
||
<%= f.govuk_collection_radio_buttons :teaching_qualification, @form.radio_options, :id, :name, | ||
legend: { | ||
text: @form.t(:question), | ||
tag: "h1", | ||
size: "l" | ||
}, | ||
hint: { text: @form.t(:hint) } %> | ||
|
||
<%= f.govuk_submit %> | ||
<% end %> | ||
</div> | ||
</div> |
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
59 changes: 59 additions & 0 deletions
59
spec/forms/journeys/further_education_payments/teaching_qualification_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,59 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::FurtherEducationPayments::TeachingQualificationForm, type: :model do | ||
let(:journey) { Journeys::FurtherEducationPayments } | ||
let(:journey_session) { create(:further_education_payments_session) } | ||
let(:teaching_qualification) { nil } | ||
|
||
let(:params) do | ||
ActionController::Parameters.new( | ||
claim: { | ||
teaching_qualification: | ||
} | ||
) | ||
end | ||
|
||
subject do | ||
described_class.new( | ||
journey_session:, | ||
journey:, | ||
params: | ||
) | ||
end | ||
|
||
describe "validations" do | ||
context "when no option selected" do | ||
let(:teaching_qualification) { nil } | ||
|
||
it do | ||
is_expected.not_to( | ||
allow_value(nil) | ||
.for(:teaching_qualification) | ||
.with_message("Select whether you have, are currently enrolled or plan to enrol on a teaching qualification") | ||
) | ||
end | ||
end | ||
|
||
context "when non-existent injection option selected" do | ||
let(:teaching_qualification) { "foo" } | ||
|
||
it do | ||
is_expected.not_to( | ||
allow_value("foo") | ||
.for(:teaching_qualification) | ||
.with_message("Select whether you have, are currently enrolled or plan to enrol on a teaching qualification") | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe "#save" do | ||
let(:teaching_qualification) { "yes" } | ||
|
||
it "updates the journey session" do | ||
expect { expect(subject.save).to be(true) }.to( | ||
change { journey_session.reload.answers.teaching_qualification }.to("yes") | ||
) | ||
end | ||
end | ||
end |