-
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.
In IRP the trainee details page writes it's value to the state_funded_secondary_school so we've preserved this behaviour with the trainee details form writing to this field.
- Loading branch information
Showing
13 changed files
with
240 additions
and
37 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/forms/journeys/get_a_teacher_relocation_payment/trainee_details_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,27 @@ | ||
module Journeys | ||
module GetATeacherRelocationPayment | ||
class TraineeDetailsForm < Form | ||
attribute :state_funded_secondary_school, :boolean | ||
|
||
validates :state_funded_secondary_school, | ||
inclusion: { | ||
in: [true, false], | ||
message: i18n_error_message(:inclusion) | ||
} | ||
|
||
def available_options | ||
[true, false] | ||
end | ||
|
||
def save | ||
return false unless valid? | ||
|
||
journey_session.answers.assign_attributes( | ||
state_funded_secondary_school: state_funded_secondary_school | ||
) | ||
|
||
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
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
34 changes: 34 additions & 0 deletions
34
app/views/get_a_teacher_relocation_payment/claims/trainee_details.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,34 @@ | ||
<% content_for( | ||
:page_title, | ||
page_title( | ||
t("get_a_teacher_relocation_payment.forms.trainee_details.question"), | ||
journey: current_journey_routing_name, | ||
show_error: @form.errors.any? | ||
) | ||
) %> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_for( | ||
@form, | ||
url: claim_path(current_journey_routing_name), | ||
builder: GOVUKDesignSystemFormBuilder::FormBuilder | ||
) do |f| %> | ||
<% if f.object.errors.any? %> | ||
<%= render("shared/error_summary", instance: f.object) %> | ||
<% end %> | ||
|
||
<%= f.govuk_collection_radio_buttons( | ||
:state_funded_secondary_school, | ||
f.object.available_options, | ||
-> (option) { option }, | ||
-> (option) { t("get_a_teacher_relocation_payment.forms.trainee_details.answers.#{option}.answer") }, | ||
legend: { text: t("get_a_teacher_relocation_payment.forms.trainee_details.question") }, | ||
hint: { html: t("get_a_teacher_relocation_payment.forms.trainee_details.hint_html") } | ||
) %> | ||
|
||
<%= 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
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: 46 additions & 0 deletions
46
spec/forms/journeys/get_a_teacher_relocation_payment/trainee_details_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,46 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::GetATeacherRelocationPayment::TraineeDetailsForm, type: :model do | ||
let(:journey_session) { create(:get_a_teacher_relocation_payment_session) } | ||
|
||
let(:params) do | ||
ActionController::Parameters.new( | ||
claim: { | ||
state_funded_secondary_school: option | ||
} | ||
) | ||
end | ||
|
||
let(:form) do | ||
described_class.new( | ||
journey_session: journey_session, | ||
journey: Journeys::GetATeacherRelocationPayment, | ||
params: params | ||
) | ||
end | ||
|
||
describe "validations" do | ||
subject { form } | ||
|
||
let(:option) { nil } | ||
|
||
it do | ||
is_expected.not_to( | ||
allow_value(nil) | ||
.for(:state_funded_secondary_school) | ||
.with_message("Select the option that applies to you") | ||
) | ||
end | ||
end | ||
|
||
describe "#save" do | ||
let(:option) { true } | ||
|
||
it "updates the journey session" do | ||
expect { expect(form.save).to be(true) }.to( | ||
change { journey_session.reload.answers.state_funded_secondary_school } | ||
.to(true) | ||
) | ||
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
Oops, something went wrong.