-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CRIMAPP-1516] Property ownership validation (#1303)
- Loading branch information
1 parent
d203445
commit def1beb
Showing
20 changed files
with
407 additions
and
8 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
21 changes: 21 additions & 0 deletions
21
app/controllers/steps/capital/usual_property_details_controller.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,21 @@ | ||
module Steps | ||
module Capital | ||
class UsualPropertyDetailsController < Steps::CapitalStepController | ||
def edit | ||
@form_object = UsualPropertyDetailsForm.build( | ||
current_crime_application | ||
) | ||
end | ||
|
||
def update | ||
update_and_advance(UsualPropertyDetailsForm, as: :usual_property_details) | ||
end | ||
|
||
private | ||
|
||
def additional_permitted_params | ||
[:action] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Steps | ||
module Capital | ||
class UsualPropertyDetailsForm < Steps::BaseFormObject | ||
attr_accessor :action | ||
|
||
validates :action, presence: true | ||
validates :action, inclusion: { in: :choices } | ||
|
||
def choices | ||
UsualPropertyDetailsAnswer.values | ||
end | ||
|
||
def home_address | ||
crime_application.applicant.home_address.values_at( | ||
*::Address::ADDRESS_ATTRIBUTES | ||
).compact_blank.join("\r\n") | ||
end | ||
|
||
def residence_ownership | ||
crime_application.applicant.residence_type | ||
end | ||
|
||
private | ||
|
||
# :nocov: | ||
def persist! | ||
true | ||
end | ||
# :nocov: | ||
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
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,6 @@ | ||
class UsualPropertyDetailsAnswer < ValueObject | ||
VALUES = [ | ||
PROVIDE_DETAILS = new(:provide_details), | ||
CHANGE_ANSWER = new(:change_answer) | ||
].freeze | ||
end |
22 changes: 22 additions & 0 deletions
22
app/views/steps/capital/usual_property_details/edit.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,22 @@ | ||
<% title t('.heading', residence_ownership: t(".residence_ownership.#{@form_object.residence_ownership}")) %> | ||
<% step_header %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= govuk_error_summary(@form_object) %> | ||
|
||
<span class="govuk-caption-xl"><%= t('steps.capital.caption') %></span> | ||
|
||
<h1 class="govuk-heading-xl"> | ||
<%= t('.heading', residence_ownership: t(".residence_ownership.#{@form_object.residence_ownership}")) %> | ||
</h1> | ||
|
||
<p class="govuk-body"><%= t('.info', residence_ownership: t(".residence_ownership.#{@form_object.residence_ownership}")) %></p> | ||
<%= simple_format(@form_object.home_address, class: 'govuk-body') %> | ||
|
||
<%= step_form @form_object do |f| %> | ||
<%= f.govuk_collection_radio_buttons :action, @form_object.choices, :value %> | ||
<%= f.continue_button %> | ||
<% 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
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
6 changes: 6 additions & 0 deletions
6
spec/controllers/steps/capital/usual_property_details_controller_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,6 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Steps::Capital::UsualPropertyDetailsController, type: :controller do | ||
it_behaves_like 'a generic step controller', Steps::Capital::UsualPropertyDetailsForm, | ||
Decisions::CapitalDecisionTree | ||
end |
59 changes: 59 additions & 0 deletions
59
spec/forms/steps/capital/usual_property_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,59 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Steps::Capital::UsualPropertyDetailsForm do | ||
subject(:form) { described_class.new(crime_application:) } | ||
|
||
let(:applicant) { instance_double(Applicant, home_address:, residence_type:) } | ||
let(:home_address) { nil } | ||
let(:residence_type) { nil } | ||
let(:capital) { instance_double(Capital) } | ||
let(:crime_application) { instance_double(CrimeApplication, applicant:, capital:) } | ||
|
||
describe 'validations' do | ||
it { is_expected.to validate_presence_of(:action, :blank, 'Select what you want to do next') } | ||
|
||
context 'when the action is an invalid option' do | ||
before { form.action = 'invalid_option' } | ||
|
||
it 'raises an inclusion error' do | ||
expect(form).not_to be_valid | ||
expect(form.errors.of_kind?(:action, :inclusion)).to be(true) | ||
end | ||
end | ||
end | ||
|
||
describe '#choices' do | ||
it { expect(form.choices).to eq(UsualPropertyDetailsAnswer.values) } | ||
end | ||
|
||
describe '#home_address' do | ||
let(:home_address) { | ||
HomeAddress.new(address_line_one: '1 Test Road', city: 'London', postcode: 'SW1 1RT', | ||
country: 'United Kingdom') | ||
} | ||
|
||
it "returns client's formatted home address" do | ||
expect(form.home_address).to eq("1 Test Road\r\nLondon\r\nSW1 1RT\r\nUnited Kingdom") | ||
end | ||
end | ||
|
||
describe '#residence_ownership' do | ||
context 'when the residence is owned by the client' do | ||
let(:residence_type) { ResidenceType::APPLICANT_OWNED.to_s } | ||
|
||
it { expect(form.residence_ownership).to eq(ResidenceType::APPLICANT_OWNED.to_s) } | ||
end | ||
|
||
context 'when the residence is owned by the partner' do | ||
let(:residence_type) { ResidenceType::PARTNER_OWNED.to_s } | ||
|
||
it { expect(form.residence_ownership).to eq(ResidenceType::PARTNER_OWNED.to_s) } | ||
end | ||
|
||
context 'when the residence is joint owned by the client and the partner' do | ||
let(:residence_type) { ResidenceType::JOINT_OWNED.to_s } | ||
|
||
it { expect(form.residence_ownership).to eq(ResidenceType::JOINT_OWNED.to_s) } | ||
end | ||
end | ||
end |
Oops, something went wrong.