Browse Source

Merge branch 'main' into CLDC-850-demographic-details-relationship-validation

# Conflicts:
#	spec/models/validations/sales/household_validations_spec.rb
pull/1178/head
natdeanlewissoftwire 3 years ago
parent
commit
d2af2e0e60
  1. 7
      app/frontend/styles/_document-list.scss
  2. 4
      app/helpers/tab_nav_helper.rb
  3. 6
      app/models/form/sales/pages/handover_date.rb
  4. 1
      app/models/form/sales/questions/deposit_amount.rb
  5. 1
      app/models/form/sales/questions/mortgage_amount.rb
  6. 1
      app/models/organisation.rb
  7. 4
      app/models/sales_log.rb
  8. 9
      app/models/validations/sales/sale_information_validations.rb
  9. 18
      app/views/layouts/_collection_resources.html.erb
  10. 4
      app/views/locations/index.html.erb
  11. 8
      db/seeds.rb
  12. 10
      spec/features/schemes_spec.rb
  13. 4
      spec/helpers/tab_nav_helper_spec.rb
  14. 4
      spec/models/form/sales/pages/handover_date_spec.rb
  15. 4
      spec/models/form/sales/questions/deposit_amount_spec.rb
  16. 2
      spec/models/form/sales/questions/mortgage_amount_spec.rb
  17. 21
      spec/models/validations/sales/household_validations_spec.rb
  18. 49
      spec/models/validations/sales/sale_information_validations_spec.rb
  19. 2
      spec/requests/form_controller_spec.rb

7
app/frontend/styles/_document-list.scss

@ -1,5 +1,10 @@
.app-document-list {
margin-top: govuk-spacing(3);
margin-bottom: govuk-spacing(6);
}
.app-document-list__item { .app-document-list__item {
margin-bottom: govuk-spacing(4); margin-bottom: govuk-spacing(3);
&:last-child { &:last-child {
margin-bottom: 0; margin-bottom: 0;

4
app/helpers/tab_nav_helper.rb

@ -8,13 +8,13 @@ module TabNavHelper
def location_cell_postcode(location, link) def location_cell_postcode(location, link)
link_text = location.postcode || "Add postcode" link_text = location.postcode || "Add postcode"
[govuk_link_to(link_text, link, method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n") [govuk_link_to(link_text, link, method: :patch), "<span class=\"govuk-visually-hidden\">Location</span>"].join("\n")
end end
def scheme_cell(scheme) def scheme_cell(scheme)
link_text = scheme.service_name link_text = scheme.service_name
link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme) link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme)
[govuk_link_to(link_text, link), "<span class=\"govuk-visually-hidden\">Scheme </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{scheme.primary_client_group}</span>"].join("\n") [govuk_link_to(link_text, link), "<span class=\"govuk-visually-hidden\">Scheme</span>"].join("\n")
end end
def org_cell(user) def org_cell(user)

6
app/models/form/sales/pages/handover_date.rb

@ -2,9 +2,9 @@ class Form::Sales::Pages::HandoverDate < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "handover_date" @id = "handover_date"
@depends_on = [{ @depends_on = [
"ownershipsch" => 1, { "ownershipsch" => 1, "resale" => 2 },
}] ]
end end
def questions def questions

1
app/models/form/sales/questions/deposit_amount.rb

@ -7,6 +7,7 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@width = 5 @width = 5
@max = 9_999_999
@prefix = "£" @prefix = "£"
@hint_text = "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage" @hint_text = "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage"
@derived = true @derived = true

1
app/models/form/sales/questions/mortgage_amount.rb

@ -8,5 +8,6 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question
@min = 0 @min = 0
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@hint_text = "Enter the amount of mortgage agreed with the mortgage lender. Exclude any deposits or cash payments. Numeric in pounds. Rounded to the nearest pound."
end end
end end

1
app/models/organisation.rb

@ -7,7 +7,6 @@ class Organisation < ApplicationRecord
has_many :data_protection_confirmations has_many :data_protection_confirmations
has_many :organisation_rent_periods has_many :organisation_rent_periods
has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id", dependent: :delete_all has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id", dependent: :delete_all
has_many :managed_schemes, class_name: "Scheme", foreign_key: "managing_organisation_id"
has_many :parent_organisation_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" has_many :parent_organisation_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship"
has_many :parent_organisations, through: :parent_organisation_relationships has_many :parent_organisations, through: :parent_organisation_relationships
has_many :child_organisation_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship" has_many :child_organisation_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship"

4
app/models/sales_log.rb

@ -1,7 +1,9 @@
class SalesLogValidator < ActiveModel::Validator class SalesLogValidator < ActiveModel::Validator
include Validations::Sales::HouseholdValidations include Validations::Sales::HouseholdValidations
include Validations::SharedValidations
include Validations::Sales::FinancialValidations include Validations::Sales::FinancialValidations
include Validations::Sales::SaleInformationValidations
include Validations::SharedValidations
include Validations::LocalAuthorityValidations include Validations::LocalAuthorityValidations
def validate(record) def validate(record)

9
app/models/validations/sales/sale_information_validations.rb

@ -0,0 +1,9 @@
module Validations::Sales::SaleInformationValidations
def validate_deposit_range(record)
return if record.deposit.blank?
unless record.deposit >= 0 && record.deposit <= 999_999
record.errors.add :deposit, "Cash deposit must be £0 - £999,999"
end
end
end

18
app/views/layouts/_collection_resources.html.erb

@ -1,16 +1,22 @@
<div class="app-card"> <div class="app-card">
<h2 class="govuk-heading-s">Collection resources</h2> <p class="govuk-body-l govuk-!-margin-bottom-3">Collection resources</p>
<p class="govuk-body govuk-!-margin-bottom-6">For lettings starting during 1 April 2023 - 31 March 2024 and sales completing during the same period, use the 23/24 forms.</p>
<h2 class="govuk-body-l govuk-!-margin-bottom-3">Lettings 23/24</h2>
<%= render DocumentListComponent.new(items: [
{
name: "Lettings log for tenants (2023/24)",
href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2023-24%20Lettings%20paper%20form.pdf?download-format=pdf",
metadata: "PDF, 281 KB, 8 pages",
},
]) %>
<h2 class="govuk-body-l govuk-!-margin-bottom-3">Lettings 22/23</h2>
<%= render DocumentListComponent.new(items: [ <%= render DocumentListComponent.new(items: [
{ {
name: "Lettings log for tenants (2022/23)", name: "Lettings log for tenants (2022/23)",
href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2022-23%20Lettings%20paper%20form.pdf?download-format=pdf", href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2022-23%20Lettings%20paper%20form.pdf?download-format=pdf",
metadata: "PDF, 654 KB, 4 pages", metadata: "PDF, 654 KB, 4 pages",
}, },
{
name: "Lettings log for tenants (2021/22)",
href: "https://core.communities.gov.uk/public/download/guides-and-manuals/2021_22%20Lettings%20Log.pdf?download-format=pdf",
metadata: "PDF, 302 KB, 3 pages",
},
]) %> ]) %>
</div> </div>

4
app/views/locations/index.html.erb

@ -39,6 +39,9 @@
<% row.cell(header: true, text: "Postcode", html_attributes: { <% row.cell(header: true, text: "Postcode", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
<% row.cell(header: true, text: "Name", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Location code", html_attributes: { <% row.cell(header: true, text: "Location code", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
@ -55,6 +58,7 @@
else else
location.postcode.present? ? scheme_location_check_answers_path(@scheme, location, route: "locations") : scheme_location_postcode_path(@scheme, location) location.postcode.present? ? scheme_location_check_answers_path(@scheme, location, route: "locations") : scheme_location_postcode_path(@scheme, location)
end), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> end), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.name) %>
<% row.cell(text: location.id) %> <% row.cell(text: location.id) %>
<% row.cell(text: status_tag(location.status)) %> <% row.cell(text: status_tag(location.status)) %>
<% end %> <% end %>

8
db/seeds.rb

@ -110,8 +110,8 @@ unless Rails.env.test?
) )
User.find_or_create_by!( User.find_or_create_by!(
name: "Provider Owns Stock", name: "Provider No Stock",
email: "provider.nostock1@example.com", email: "provider.nostock@example.com",
organisation: standalone_no_stock, organisation: standalone_no_stock,
role: "data_provider", role: "data_provider",
) do |user| ) do |user|
@ -120,8 +120,8 @@ unless Rails.env.test?
end end
User.find_or_create_by!( User.find_or_create_by!(
name: "Coordinator Owns Stock", name: "Coordinator No Stock",
email: "coordinator.nostock1@example.com", email: "coordinator.nostock@example.com",
organisation: standalone_no_stock, organisation: standalone_no_stock,
role: "data_coordinator", role: "data_coordinator",
) do |user| ) do |user|

10
spec/features/schemes_spec.rb

@ -101,9 +101,9 @@ RSpec.describe "Schemes scheme Features" do
it "shows a list of schemes" do it "shows a list of schemes" do
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_content(scheme.id)
expect(page).to have_link(scheme.service_name) expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group) expect(page).to have_content(scheme.id_to_display)
expect(page).to have_content(scheme.locations&.count)
end end
end end
@ -175,7 +175,8 @@ RSpec.describe "Schemes scheme Features" do
click_on("Back") click_on("Back")
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_link(scheme.service_name) expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group) expect(page).to have_content(scheme.id_to_display)
expect(page).to have_content(scheme.locations&.count)
end end
end end
end end
@ -671,7 +672,8 @@ RSpec.describe "Schemes scheme Features" do
it "shows list of links to schemes" do it "shows list of links to schemes" do
schemes.each do |scheme| schemes.each do |scheme|
expect(page).to have_link(scheme.service_name) expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group) expect(page).to have_content(scheme.id_to_display)
expect(page).to have_content(scheme.locations&.count)
end end
end end

4
spec/helpers/tab_nav_helper_spec.rb

@ -23,14 +23,14 @@ RSpec.describe TabNavHelper do
describe "#location_cell" do describe "#location_cell" do
it "returns the location link to the postcode with optional name" do it "returns the location link to the postcode with optional name" do
link = "/schemes/#{location.scheme.id}/locations/#{location.id}/edit" link = "/schemes/#{location.scheme.id}/locations/#{location.id}/edit"
expected_html = "<a class=\"govuk-link\" rel=\"nofollow\" data-method=\"patch\" href=\"/schemes/#{scheme.id}/locations/#{location.id}/edit\">#{location.postcode}</a>\n<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>" expected_html = "<a class=\"govuk-link\" rel=\"nofollow\" data-method=\"patch\" href=\"/schemes/#{scheme.id}/locations/#{location.id}/edit\">#{location.postcode}</a>\n<span class=\"govuk-visually-hidden\">Location</span>"
expect(location_cell_postcode(location, link)).to match(expected_html) expect(location_cell_postcode(location, link)).to match(expected_html)
end end
end end
describe "#scheme_cell" do describe "#scheme_cell" do
it "returns the scheme link service name and primary user group separated by a newline character" do it "returns the scheme link service name and primary user group separated by a newline character" do
expected_html = "<a class=\"govuk-link\" href=\"/schemes/#{scheme.id}\">#{scheme.service_name}</a>\n<span class=\"govuk-visually-hidden\">Scheme </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{scheme.primary_client_group}</span>" expected_html = "<a class=\"govuk-link\" href=\"/schemes/#{scheme.id}\">#{scheme.service_name}</a>\n<span class=\"govuk-visually-hidden\">Scheme</span>"
expect(scheme_cell(scheme)).to match(expected_html) expect(scheme_cell(scheme)).to match(expected_html)
end end
end end

4
spec/models/form/sales/pages/handover_date_spec.rb

@ -28,8 +28,6 @@ RSpec.describe Form::Sales::Pages::HandoverDate, type: :model do
end end
it "has the correct depends_on" do it "has the correct depends_on" do
expect(page.depends_on).to eq([{ expect(page.depends_on).to eq([{ "ownershipsch" => 1, "resale" => 2 }])
"ownershipsch" => 1,
}])
end end
end end

4
spec/models/form/sales/questions/deposit_amount_spec.rb

@ -46,4 +46,8 @@ RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do
it "has correct min" do it "has correct min" do
expect(question.min).to eq(0) expect(question.min).to eq(0)
end end
it "has correct max" do
expect(question.max).to eq(9_999_999)
end
end end

2
spec/models/form/sales/questions/mortgage_amount_spec.rb

@ -32,7 +32,7 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do
end end
it "has the correct hint" do it "has the correct hint" do
expect(question.hint_text).to be_nil expect(question.hint_text).to eq("Enter the amount of mortgage agreed with the mortgage lender. Exclude any deposits or cash payments. Numeric in pounds. Rounded to the nearest pound.")
end end
it "has correct width" do it "has correct width" do

21
spec/models/validations/sales/household_validations_spec.rb

@ -3,43 +3,46 @@ require "rails_helper"
RSpec.describe Validations::Sales::HouseholdValidations do RSpec.describe Validations::Sales::HouseholdValidations do
subject(:household_validator) { validator_class.new } subject(:household_validator) { validator_class.new }
let(:record) { FactoryBot.build(:sales_log) }
let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } } let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } }
describe "#validate_number_of_other_people_living_in_the_property" do describe "#validate_number_of_other_people_living_in_the_property" do
context "when within permitted bounds" do context "when within permitted bounds" do
let(:record) { build(:sales_log, hholdcount: 2) }
it "does not add an error" do it "does not add an error" do
record.hholdcount = 2
household_validator.validate_number_of_other_people_living_in_the_property(record) household_validator.validate_number_of_other_people_living_in_the_property(record)
expect(record.errors).not_to be_present expect(record.errors[:hholdcount]).not_to be_present
end end
end end
context "when blank" do context "when blank" do
let(:record) { build(:sales_log, hholdcount: nil) }
it "does not add an error" do it "does not add an error" do
record.hholdcount = nil
household_validator.validate_number_of_other_people_living_in_the_property(record) household_validator.validate_number_of_other_people_living_in_the_property(record)
expect(record.errors).not_to be_present expect(record.errors[:hholdcount]).not_to be_present
end end
end end
context "when below lower bound" do context "when below lower bound" do
let(:record) { build(:sales_log, hholdcount: -1) }
it "adds an error" do it "adds an error" do
record.hholdcount = -1
household_validator.validate_number_of_other_people_living_in_the_property(record) household_validator.validate_number_of_other_people_living_in_the_property(record)
expect(record.errors).to be_present expect(record.errors[:hholdcount]).to be_present
end end
end end
context "when higher than upper bound" do context "when higher than upper bound" do
let(:record) { build(:sales_log, hholdcount: 5) }
it "adds an error" do it "adds an error" do
record.hholdcount = 5
household_validator.validate_number_of_other_people_living_in_the_property(record) household_validator.validate_number_of_other_people_living_in_the_property(record)
expect(record.errors).to be_present expect(record.errors[:hholdcount]).to be_present
end end
end end
end end

49
spec/models/validations/sales/sale_information_validations_spec.rb

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Validations::Sales::SaleInformationValidations do
subject(:sale_information_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::Sales::SaleInformationValidations } }
describe "#validate_deposit_range" do
context "when within permitted bounds" do
let(:record) { build(:sales_log, deposit: 0) }
it "does not add an error" do
sale_information_validator.validate_deposit_range(record)
expect(record.errors[:deposit]).not_to be_present
end
end
context "when blank" do
let(:record) { build(:sales_log, deposit: nil) }
it "does not add an error" do
sale_information_validator.validate_deposit_range(record)
expect(record.errors[:deposit]).not_to be_present
end
end
context "when below lower bound" do
let(:record) { build(:sales_log, deposit: -1) }
it "adds an error" do
sale_information_validator.validate_deposit_range(record)
expect(record.errors[:deposit]).to be_present
end
end
context "when higher than upper bound" do
let(:record) { build(:sales_log, deposit: 1_000_000) }
it "adds an error" do
sale_information_validator.validate_deposit_range(record)
expect(record.errors[:deposit]).to be_present
end
end
end
end

2
spec/requests/form_controller_spec.rb

@ -658,7 +658,7 @@ RSpec.describe FormController, type: :request do
let(:referrer) { "/lettings-logs/#{completed_lettings_log.id}/net-income-value-check?referrer=check_answers" } let(:referrer) { "/lettings-logs/#{completed_lettings_log.id}/net-income-value-check?referrer=check_answers" }
before do before do
completed_lettings_log.update!(ecstat1: 1, earnings: 130, hhmemb: 1) # we're not routing to that page, so it gets cleared?§ completed_lettings_log.update!(ecstat1: 1, earnings: 130, hhmemb: 1) # we're not routing to that page, so it gets cleared?
allow(completed_lettings_log).to receive(:net_income_soft_validation_triggered?).and_return(true) allow(completed_lettings_log).to receive(:net_income_soft_validation_triggered?).and_return(true)
allow(completed_lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day) allow(completed_lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
post "/lettings-logs/#{completed_lettings_log.id}/form", params: interrupt_params, headers: headers.merge({ "HTTP_REFERER" => referrer }) post "/lettings-logs/#{completed_lettings_log.id}/form", params: interrupt_params, headers: headers.merge({ "HTTP_REFERER" => referrer })

Loading…
Cancel
Save