-
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.
- Loading branch information
Showing
9 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
app/forms/journeys/further_education_payments/contract_type_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,36 @@ | ||
module Journeys | ||
module FurtherEducationPayments | ||
class ContractTypeForm < Form | ||
attribute :contract_type, :string | ||
|
||
validates :contract_type, | ||
inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)} | ||
|
||
def radio_options | ||
[ | ||
OpenStruct.new( | ||
id: "permanent", | ||
name: "Permanent contract", | ||
hint: "This includes full-time and part-time contracts" | ||
), | ||
OpenStruct.new( | ||
id: "fixed-term", | ||
name: "Fixed-term contract" | ||
), | ||
OpenStruct.new( | ||
id: "variable-hours", | ||
name: "Variable hours contract", | ||
hint: "This includes zero hours contract and hourly paid" | ||
) | ||
] | ||
end | ||
|
||
def save | ||
return if invalid? | ||
|
||
journey_session.answers.assign_attributes(contract_type:) | ||
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
13 changes: 9 additions & 4 deletions
13
app/views/further_education_payments/claims/contract_type.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
<p class="govuk-body"> | ||
FE contract type goes here | ||
</p> | ||
|
||
<%= 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 :contract_type, @form.radio_options, :id, :name, :hint, | ||
legend: { | ||
text: @form.t(:question, school_name: journey_session.answers.school.name), | ||
tag: "h1", | ||
size: "l" | ||
} %> | ||
|
||
<%= f.govuk_submit %> | ||
<% 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
4 changes: 4 additions & 0 deletions
4
spec/factories/journeys/further_education_payments/session_answers.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,4 @@ | ||
FactoryBot.define do | ||
factory :further_education_payments_answers, class: "Journeys::FurtherEducationPayments::SessionAnswers" do | ||
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
48 changes: 48 additions & 0 deletions
48
spec/forms/journeys/further_education_payments/contract_type_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,48 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::FurtherEducationPayments::ContractTypeForm, type: :model do | ||
let(:journey) { Journeys::FurtherEducationPayments } | ||
let(:journey_session) { create(:further_education_payments_session, answers:) } | ||
let(:answers) { build(:further_education_payments_answers, school_id: college.id) } | ||
let(:college) { create(:school) } | ||
let(:contract_type) { nil } | ||
|
||
let(:params) do | ||
ActionController::Parameters.new( | ||
claim: { | ||
contract_type: | ||
} | ||
) | ||
end | ||
|
||
subject do | ||
described_class.new( | ||
journey_session:, | ||
journey:, | ||
params: | ||
) | ||
end | ||
|
||
describe "validations" do | ||
context "when no option selected" do | ||
it do | ||
is_expected.not_to( | ||
allow_value(nil) | ||
.for(:contract_type) | ||
.with_message("Select the contract type you have") | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe "#save" do | ||
let(:contract_type) { %w[permanent fixed-term variable-hours].sample } | ||
|
||
it "updates the journey session" do | ||
expect { expect(subject.save).to be(true) }.to( | ||
change { journey_session.reload.answers.contract_type } | ||
.to(contract_type) | ||
) | ||
end | ||
end | ||
end |