- <% if !@page.id.include?("value_check") && if request.query_parameters["referrer"] != "check_answers" %>
+ <% if !@page.interruption_screen? && if request.query_parameters["referrer"] != "check_answers" %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", send(@log.form.next_page_redirect_path(@page, @log, current_user), @log) %>
<% else %>
From d67e4710c8ff85b3f52c398062ff5573f6d6581e Mon Sep 17 00:00:00 2001
From: natdeanlewissoftwire
<94526761+natdeanlewissoftwire@users.noreply.github.com>
Date: Thu, 26 Jan 2023 12:21:12 +0000
Subject: [PATCH 07/12] CLDC-861 Add length of stay validations (#1218)
* faet: add validation and tests
* refactor: linting
* feat: respond to PR comments
---
.../sales/sale_information_validations.rb | 15 +++-
config/locales/en.yml | 3 +
.../sale_information_validations_spec.rb | 68 +++++++++++++++++--
3 files changed, 78 insertions(+), 8 deletions(-)
diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb
index c70a8d57d..be0295f2c 100644
--- a/app/models/validations/sales/sale_information_validations.rb
+++ b/app/models/validations/sales/sale_information_validations.rb
@@ -1,5 +1,5 @@
module Validations::Sales::SaleInformationValidations
- def validate_pratical_completion_date_before_saledate(record)
+ def validate_practical_completion_date_before_saledate(record)
return if record.saledate.blank? || record.hodate.blank?
unless record.saledate > record.hodate
@@ -7,6 +7,19 @@ module Validations::Sales::SaleInformationValidations
end
end
+ def validate_years_living_in_property_before_purchase(record)
+ return unless record.proplen && record.proplen.nonzero?
+
+ case record.type
+ when 18
+ record.errors.add :type, I18n.t("validations.sale_information.proplen.social_homebuy")
+ record.errors.add :proplen, I18n.t("validations.sale_information.proplen.social_homebuy")
+ when 28, 29
+ record.errors.add :type, I18n.t("validations.sale_information.proplen.rent_to_buy")
+ record.errors.add :proplen, I18n.t("validations.sale_information.proplen.rent_to_buy")
+ end
+ end
+
def validate_exchange_date(record)
return unless record.exdate && record.saledate
diff --git a/config/locales/en.yml b/config/locales/en.yml
index cdad12a52..c988d2dd9 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -413,6 +413,9 @@ en:
deactivation:
during_deactivated_period: "The location is already deactivated during this date, please enter a different date"
sale_information:
+ proplen:
+ social_homebuy: "Social HomeBuy buyers should not have lived here before"
+ rent_to_buy: "Rent to Buy buyers should not have lived here before"
exdate:
must_be_before_saledate:
Contract exchange date must be less than 1 year before completion date
diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb
index 409972040..fb3aea06c 100644
--- a/spec/models/validations/sales/sale_information_validations_spec.rb
+++ b/spec/models/validations/sales/sale_information_validations_spec.rb
@@ -5,12 +5,12 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
let(:validator_class) { Class.new { include Validations::Sales::SaleInformationValidations } }
- describe "#validate_pratical_completion_date_before_saledate" do
+ describe "#validate_practical_completion_date_before_saledate" do
context "when hodate blank" do
let(:record) { build(:sales_log, hodate: nil) }
it "does not add an error" do
- sale_information_validator.validate_pratical_completion_date_before_saledate(record)
+ sale_information_validator.validate_practical_completion_date_before_saledate(record)
expect(record.errors).not_to be_present
end
@@ -20,7 +20,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
let(:record) { build(:sales_log, saledate: nil) }
it "does not add an error" do
- sale_information_validator.validate_pratical_completion_date_before_saledate(record)
+ sale_information_validator.validate_practical_completion_date_before_saledate(record)
expect(record.errors).not_to be_present
end
@@ -30,7 +30,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
let(:record) { build(:sales_log, hodate: nil, saledate: nil) }
it "does not add an error" do
- sale_information_validator.validate_pratical_completion_date_before_saledate(record)
+ sale_information_validator.validate_practical_completion_date_before_saledate(record)
expect(record.errors).not_to be_present
end
@@ -40,7 +40,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
let(:record) { build(:sales_log, hodate: 2.months.ago, saledate: 1.month.ago) }
it "does not add the error" do
- sale_information_validator.validate_pratical_completion_date_before_saledate(record)
+ sale_information_validator.validate_practical_completion_date_before_saledate(record)
expect(record.errors).not_to be_present
end
@@ -50,7 +50,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
let(:record) { build(:sales_log, hodate: 1.month.ago, saledate: 2.months.ago) }
it "adds error" do
- sale_information_validator.validate_pratical_completion_date_before_saledate(record)
+ sale_information_validator.validate_practical_completion_date_before_saledate(record)
expect(record.errors[:hodate]).to be_present
end
@@ -60,7 +60,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
let(:record) { build(:sales_log, hodate: Time.zone.parse("2023-07-01"), saledate: Time.zone.parse("2023-07-01")) }
it "does not add an error" do
- sale_information_validator.validate_pratical_completion_date_before_saledate(record)
+ sale_information_validator.validate_practical_completion_date_before_saledate(record)
expect(record.errors[:hodate]).to be_present
end
@@ -164,4 +164,58 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
end
+
+ describe "#validate_years_living_in_property_before_purchase" do
+ context "when proplen blank" do
+ let(:record) { build(:sales_log, proplen: nil) }
+
+ it "does not add an error" do
+ sale_information_validator.validate_years_living_in_property_before_purchase(record)
+
+ expect(record.errors).not_to be_present
+ end
+ end
+
+ context "when type blank" do
+ let(:record) { build(:sales_log, type: nil) }
+
+ it "does not add an error" do
+ sale_information_validator.validate_years_living_in_property_before_purchase(record)
+
+ expect(record.errors).not_to be_present
+ end
+ end
+
+ context "when proplen 0" do
+ let(:record) { build(:sales_log, proplen: 0) }
+
+ it "does not add an error" do
+ sale_information_validator.validate_years_living_in_property_before_purchase(record)
+
+ expect(record.errors).not_to be_present
+ end
+ end
+
+ context "when type Rent to Buy and proplen > 0" do
+ let(:record) { build(:sales_log, proplen: 1, type: 28) }
+
+ it "adds an error" do
+ sale_information_validator.validate_years_living_in_property_before_purchase(record)
+
+ expect(record.errors[:type]).to include(I18n.t("validations.sale_information.proplen.rent_to_buy"))
+ expect(record.errors[:proplen]).to include(I18n.t("validations.sale_information.proplen.rent_to_buy"))
+ end
+ end
+
+ context "when type Social HomeBuy and proplen > 0" do
+ let(:record) { build(:sales_log, proplen: 1, type: 18) }
+
+ it "adds an error" do
+ sale_information_validator.validate_years_living_in_property_before_purchase(record)
+
+ expect(record.errors[:type]).to include(I18n.t("validations.sale_information.proplen.social_homebuy"))
+ expect(record.errors[:proplen]).to include(I18n.t("validations.sale_information.proplen.social_homebuy"))
+ end
+ end
+ end
end
From a4fbb99a3f92df8fde80ceaf196464664df686ff Mon Sep 17 00:00:00 2001
From: natdeanlewissoftwire
<94526761+natdeanlewissoftwire@users.noreply.github.com>
Date: Thu, 26 Jan 2023 14:39:13 +0000
Subject: [PATCH 08/12] CLDC-1583 Add extra borrowing validation (#1201)
* feat: add condition-less soft validation and update db
* feat: add validation condition and update tests
* feat: update validation
* feat: update validation
* feat: add tests
* db: update
* test: update
* refactor: linting
* test: update
* feat: update text, remove separate redundant function, add value check page everywhere
* feat: leave value check at end
* test: update
* feat: add value check everywhere
* tests: update
* db:update
* feat: only appear at end
* test: update
* feat: add soft validation everywhere smoothly
* test: update
---
.../pages/extra_borrowing_value_check.rb | 21 +++++
.../questions/extra_borrowing_value_check.rb | 23 +++++
.../discounted_ownership_scheme.rb | 4 +
.../sales/household_validations.rb | 4 -
.../validations/sales/soft_validations.rb | 6 ++
config/locales/en.yml | 2 +
...dd_extra_borrowing_value_check_to_sales.rb | 7 ++
db/schema.rb | 5 +-
db/seeds.rb | 2 +-
.../discounted_ownership_scheme_spec.rb | 4 +
spec/models/form_handler_spec.rb | 4 +-
.../sales/soft_validations_spec.rb | 83 +++++++++++++++++--
12 files changed, 148 insertions(+), 17 deletions(-)
create mode 100644 app/models/form/sales/pages/extra_borrowing_value_check.rb
create mode 100644 app/models/form/sales/questions/extra_borrowing_value_check.rb
create mode 100644 db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb
diff --git a/app/models/form/sales/pages/extra_borrowing_value_check.rb b/app/models/form/sales/pages/extra_borrowing_value_check.rb
new file mode 100644
index 000000000..18f975b8d
--- /dev/null
+++ b/app/models/form/sales/pages/extra_borrowing_value_check.rb
@@ -0,0 +1,21 @@
+class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page
+ def initialize(id, hsh, subsection)
+ super
+ @depends_on = [
+ {
+ "extra_borrowing_expected_but_not_reported?" => true,
+ },
+ ]
+ @title_text = {
+ "translation" => "soft_validations.extra_borrowing.title",
+ }
+ @informative_text = {
+ }
+ end
+
+ def questions
+ @questions ||= [
+ Form::Sales::Questions::ExtraBorrowingValueCheck.new(nil, nil, self),
+ ]
+ end
+end
diff --git a/app/models/form/sales/questions/extra_borrowing_value_check.rb b/app/models/form/sales/questions/extra_borrowing_value_check.rb
new file mode 100644
index 000000000..0f12ce110
--- /dev/null
+++ b/app/models/form/sales/questions/extra_borrowing_value_check.rb
@@ -0,0 +1,23 @@
+class Form::Sales::Questions::ExtraBorrowingValueCheck < ::Form::Question
+ def initialize(id, hsh, page)
+ super(id, hsh, page)
+ @id = "extrabor_value_check"
+ @check_answer_label = "Extra borrowing confirmation"
+ @type = "interruption_screen"
+ @answer_options = {
+ "0" => { "value" => "Yes" },
+ "1" => { "value" => "No" },
+ }
+ @hidden_in_check_answers = {
+ "depends_on" => [
+ {
+ "extrabor_value_check" => 0,
+ },
+ {
+ "extrabor_value_check" => 1,
+ },
+ ],
+ }
+ @header = "Are you sure there is no extra borrowing?"
+ end
+end
diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb
index b527cd7d4..3b994d931 100644
--- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb
+++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb
@@ -10,15 +10,19 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
@pages ||= [
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self),
Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self),
+ Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_price_value_check", nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
+ Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_mortgage_value_check", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self),
Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_discounted_ownership", nil, self),
+ Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self),
+ Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_deposit_value_check", nil, self),
Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self),
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self),
]
diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb
index 42846273c..8c03d9db9 100644
--- a/app/models/validations/sales/household_validations.rb
+++ b/app/models/validations/sales/household_validations.rb
@@ -109,10 +109,6 @@ private
economic_status == 7
end
- def person_economic_status_refused?(economic_status)
- economic_status == 10
- end
-
def person_is_child?(relationship)
relationship == "C"
end
diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb
index 19c2a13ec..e39b5e9d9 100644
--- a/app/models/validations/sales/soft_validations.rb
+++ b/app/models/validations/sales/soft_validations.rb
@@ -37,6 +37,12 @@ module Validations::Sales::SoftValidations
deposit > savings * 4 / 3
end
+ def extra_borrowing_expected_but_not_reported?
+ return unless extrabor && mortgage && deposit && value && discount
+
+ extrabor != 1 && mortgage + deposit > value - value * discount / 100
+ end
+
def hodate_3_years_or_more_saledate?
return unless hodate && saledate
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c988d2dd9..0be594420 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -448,6 +448,8 @@ en:
max:
title: "You told us this person is %{age} or over and not retired"
hint_text: "The minimum expected retirement age for %{gender} in England is %{age}."
+ extra_borrowing:
+ title: "The mortgage and deposit are higher than the purchase minus the discount"
pregnancy:
title: "You told us somebody in the household is pregnant"
no_females: "You also told us there are no female tenants living at the property."
diff --git a/db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb b/db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb
new file mode 100644
index 000000000..ce4e79718
--- /dev/null
+++ b/db/migrate/20230118170602_add_extra_borrowing_value_check_to_sales.rb
@@ -0,0 +1,7 @@
+class AddExtraBorrowingValueCheckToSales < ActiveRecord::Migration[7.0]
+ def change
+ change_table :sales_logs, bulk: true do |t|
+ t.column :extrabor_value_check, :integer
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 91c6bed37..e97d4a5ac 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do
+ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -502,8 +502,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do
t.integer "hhtype"
t.integer "hodate_check"
t.bigint "bulk_upload_id"
- t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.integer "retirement_value_check"
+ t.integer "extrabor_value_check"
+ t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"
diff --git a/db/seeds.rb b/db/seeds.rb
index 8dea68d80..6a4098f9b 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -160,7 +160,7 @@ unless Rails.env.test?
saledate: Date.new(1, 1, 1),
purchid: "1",
ownershipsch: 2,
- type: 8,
+ type: 9,
jointpur: 1,
jointmore: 1,
)
diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
index 632ba85bc..44896a0f9 100644
--- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
+++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
@@ -16,15 +16,19 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
%w[
living_before_purchase_discounted_ownership
about_price_rtb
+ extra_borrowing_price_value_check
about_price_not_rtb
purchase_price_discounted_ownership
mortgage_used_discounted_ownership
mortgage_amount_discounted_ownership
+ extra_borrowing_mortgage_value_check
mortgage_lender_discounted_ownership
mortgage_lender_other_discounted_ownership
mortgage_length_discounted_ownership
extra_borrowing_discounted_ownership
+ extra_borrowing_value_check
about_deposit_discounted_ownership
+ extra_borrowing_deposit_value_check
discounted_ownership_deposit_value_check
leasehold_charges_discounted_ownership
],
diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb
index 965e79690..8f9a88f7f 100644
--- a/spec/models/form_handler_spec.rb
+++ b/spec/models/form_handler_spec.rb
@@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(183)
+ expect(form.pages.count).to eq(187)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(183)
+ expect(form.pages.count).to eq(187)
expect(form.name).to eq("2021_2022_sales")
end
end
diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb
index 34f49d847..17bd87d96 100644
--- a/spec/models/validations/sales/soft_validations_spec.rb
+++ b/spec/models/validations/sales/soft_validations_spec.rb
@@ -128,7 +128,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
- it "returns true if only income1 is used for morgage and it is less than 1/5 of the morgage" do
+ it "returns true if only income1 is used for mortgage and it is less than 1/5 of the mortgage" do
record.inc1mort = 1
record.income1 = 10_000
record.mortgage = 51_000
@@ -137,7 +137,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
- it "returns false if only income1 is used for morgage and it is more than 1/5 of the morgage" do
+ it "returns false if only income1 is used for mortgage and it is more than 1/5 of the mortgage" do
record.inc1mort = 1
record.income1 = 10_000
record.mortgage = 44_000
@@ -146,7 +146,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
- it "returns true if only income2 is used for morgage and it is less than 1/5 of the morgage" do
+ it "returns true if only income2 is used for mortgage and it is less than 1/5 of the mortgage" do
record.inc1mort = 2
record.inc2mort = 1
record.income2 = 10_000
@@ -155,7 +155,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
- it "returns false if only income2 is used for morgage and it is more than 1/5 of the morgage" do
+ it "returns false if only income2 is used for mortgage and it is more than 1/5 of the mortgage" do
record.inc1mort = 2
record.inc2mort = 1
record.income2 = 10_000
@@ -164,7 +164,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
- it "returns true if income1 and income2 are used for morgage and their sum is less than 1/5 of the morgage" do
+ it "returns true if income1 and income2 are used for mortgage and their sum is less than 1/5 of the mortgage" do
record.inc1mort = 1
record.inc2mort = 1
record.income1 = 10_000
@@ -174,7 +174,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
- it "returns false if income1 and income2 are used for morgage and their sum is more than 1/5 of the morgage" do
+ it "returns false if income1 and income2 are used for mortgage and their sum is more than 1/5 of the mortgage" do
record.inc1mort = 1
record.inc2mort = 1
record.income1 = 8_000
@@ -184,7 +184,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
- it "returns true if neither of the incomes are used for morgage and the morgage is more than 0" do
+ it "returns true if neither of the incomes are used for mortgage and the mortgage is more than 0" do
record.inc1mort = 2
record.inc2mort = 2
record.mortgage = 124_000
@@ -192,7 +192,7 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_mortgage_over_soft_max
end
- it "returns true if neither of the incomes are used for morgage and the morgage is 0" do
+ it "returns false if neither of the incomes are used for mortgage and the mortgage is 0" do
record.inc1mort = 2
record.inc2mort = 2
record.mortgage = 0
@@ -200,6 +200,73 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max
end
end
+
+ context "when validating extra borrowing" do
+ it "returns false if extrabor not present" do
+ record.mortgage = 50_000
+ record.deposit = 40_000
+ record.value = 100_000
+ record.discount = 11
+ expect(record)
+ .not_to be_extra_borrowing_expected_but_not_reported
+ end
+
+ it "returns false if mortgage not present" do
+ record.extrabor = 2
+ record.deposit = 40_000
+ record.value = 100_000
+ record.discount = 11
+ expect(record)
+ .not_to be_extra_borrowing_expected_but_not_reported
+ end
+
+ it "returns false if deposit not present" do
+ record.extrabor = 2
+ record.mortgage = 50_000
+ record.value = 100_000
+ record.discount = 11
+ expect(record)
+ .not_to be_extra_borrowing_expected_but_not_reported
+ end
+
+ it "returns false if value not present" do
+ record.extrabor = 2
+ record.mortgage = 50_000
+ record.deposit = 40_000
+ record.discount = 11
+ expect(record)
+ .not_to be_extra_borrowing_expected_but_not_reported
+ end
+
+ it "returns false if discount not present" do
+ record.extrabor = 2
+ record.mortgage = 50_000
+ record.deposit = 40_000
+ record.value = 100_000
+ expect(record)
+ .not_to be_extra_borrowing_expected_but_not_reported
+ end
+
+ it "returns false if extra borrowing expected and reported" do
+ record.extrabor = 1
+ record.mortgage = 50_000
+ record.deposit = 40_000
+ record.value = 100_000
+ record.discount = 11
+ expect(record)
+ .not_to be_extra_borrowing_expected_but_not_reported
+ end
+
+ it "returns true if extra borrowing expected but not reported" do
+ record.extrabor = 2
+ record.mortgage = 50_000
+ record.deposit = 40_000
+ record.value = 100_000
+ record.discount = 11
+ expect(record)
+ .to be_extra_borrowing_expected_but_not_reported
+ end
+ end
end
describe "savings amount validations" do
From 4e15a119b9408ec32d27604e9cd4ef343eb04319 Mon Sep 17 00:00:00 2001
From: natdeanlewissoftwire
<94526761+natdeanlewissoftwire@users.noreply.github.com>
Date: Thu, 26 Jan 2023 15:46:48 +0000
Subject: [PATCH 09/12] CLDC-1765 Remove managing organisation for sales log
from ui and backend (#1169)
* feat: remove sales log managing_organisation_id
* feat: move shared managing org behaviour from general log to lettings log, update tests
* refator: linting
* revert change to create
* feat: tech review comments
* db:update
* tests: respond to comment
* feat: revert change to avoid nil issue
* test: update
* feat: add validation and update db
* feat: revert last commit
* db:update
* refactor: use safe navigation and lettings?
* refactor: move safe navigator and add shared org_params to log
---
app/components/log_summary_component.html.erb | 12 +++---
app/controllers/lettings_logs_controller.rb | 6 +++
app/controllers/logs_controller.rb | 1 -
app/models/lettings_log.rb | 14 +++++++
app/models/log.rb | 14 -------
app/models/organisation.rb | 1 -
app/models/sales_log.rb | 9 +++++
app/models/user.rb | 1 -
app/services/filter_service.rb | 10 ++++-
...anaging_organisation_id_from_sales_logs.rb | 13 +++++++
db/schema.rb | 14 +++----
spec/components/log_summary_component_spec.rb | 39 ++++++++++++++-----
spec/factories/sales_log.rb | 1 -
.../check_answers_page_lettings_logs_spec.rb | 2 +-
.../check_answers_page_sales_logs_spec.rb | 4 +-
spec/features/organisation_spec.rb | 2 +-
spec/models/lettings_log_spec.rb | 6 ---
spec/models/organisation_spec.rb | 2 +-
spec/models/sales_log_spec.rb | 19 +++------
.../requests/organisations_controller_spec.rb | 4 +-
spec/requests/sales_logs_controller_spec.rb | 19 ++-------
21 files changed, 109 insertions(+), 84 deletions(-)
create mode 100644 db/migrate/20230110094518_remove_managing_organisation_id_from_sales_logs.rb
diff --git a/app/components/log_summary_component.html.erb b/app/components/log_summary_component.html.erb
index 9c251b6b4..a59c78c64 100644
--- a/app/components/log_summary_component.html.erb
+++ b/app/components/log_summary_component.html.erb
@@ -25,7 +25,7 @@
<% end %>
- <% if log.is_a?(LettingsLog) && (log.needstype? or log.startdate?) %>
+ <% if log.lettings? && (log.needstype? or log.startdate?) %>
<% if log.needstype? %>
<%= log.is_general_needs? ? "General needs" : "Supported housing" %>
@@ -37,18 +37,20 @@
<% end %>
<% if current_user.support? || current_user.organisation.has_managing_agents? %>
- <% if log.owning_organisation or log.managing_organisation %>
-
+
+ <% if log.owning_organisation %>
- Owned by
- <%= log.owning_organisation&.name %>
+ <% end %>
+ <% if log.lettings? && log.managing_organisation %>
- Managed by
- <%= log.managing_organisation&.name %>
-
- <% end %>
+ <% end %>
+
<% end %>
diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb
index 40560fca8..e7d233f87 100644
--- a/app/controllers/lettings_logs_controller.rb
+++ b/app/controllers/lettings_logs_controller.rb
@@ -101,6 +101,12 @@ class LettingsLogsController < LogsController
end
end
+ def org_params
+ super.merge(
+ { "managing_organisation_id" => current_user.organisation.id },
+ )
+ end
+
private
def permitted_log_params
diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb
index 083d40178..603608241 100644
--- a/app/controllers/logs_controller.rb
+++ b/app/controllers/logs_controller.rb
@@ -63,7 +63,6 @@ private
owning_organisation_id = current_user.organisation.holds_own_stock? ? current_user.organisation.id : nil
{
"owning_organisation_id" => owning_organisation_id,
- "managing_organisation_id" => current_user.organisation.id,
"created_by_id" => current_user.id,
}
end
diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb
index 04b4b4ec9..66f622270 100644
--- a/app/models/lettings_log.rb
+++ b/app/models/lettings_log.rb
@@ -35,6 +35,7 @@ class LettingsLog < Log
belongs_to :scheme, optional: true
belongs_to :location, optional: true
+ belongs_to :managing_organisation, class_name: "Organisation", optional: true
scope :filter_by_year, ->(year) { where(startdate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") }
@@ -50,6 +51,7 @@ class LettingsLog < Log
}
scope :filter_by_before_startdate, ->(date) { where("lettings_logs.startdate >= ?", date) }
scope :unresolved, -> { where(unresolved: true) }
+ scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze
@@ -495,6 +497,18 @@ class LettingsLog < Log
update(unresolved: false)
end
+ def managing_organisation_provider_type
+ managing_organisation&.provider_type
+ end
+
+ def reset_created_by!
+ return unless updated_by&.support?
+ return if owning_organisation.blank? || managing_organisation.blank? || created_by.blank?
+ return if created_by&.organisation == managing_organisation || created_by&.organisation == owning_organisation
+
+ update!(created_by: nil)
+ end
+
private
def reset_derived_questions
diff --git a/app/models/log.rb b/app/models/log.rb
index d10211577..3217251b1 100644
--- a/app/models/log.rb
+++ b/app/models/log.rb
@@ -2,7 +2,6 @@ class Log < ApplicationRecord
self.abstract_class = true
belongs_to :owning_organisation, class_name: "Organisation", optional: true
- belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true
belongs_to :updated_by, class_name: "User", optional: true
belongs_to :bulk_upload, optional: true
@@ -12,7 +11,6 @@ class Log < ApplicationRecord
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
enum status: STATUS
- scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :filter_by_status, ->(status, _user = nil) { where status: }
scope :filter_by_years, lambda { |years, _user = nil|
first_year = years.shift
@@ -44,10 +42,6 @@ class Log < ApplicationRecord
ethnic_group == 17
end
- def managing_organisation_provider_type
- managing_organisation&.provider_type
- end
-
def collection_period_open?
form.end_date > Time.zone.today
end
@@ -114,14 +108,6 @@ private
reset_created_by!
end
- def reset_created_by!
- return unless updated_by&.support?
- return if owning_organisation.blank? || managing_organisation.blank? || created_by.blank?
- return if created_by&.organisation == managing_organisation || created_by&.organisation == owning_organisation
-
- update!(created_by: nil)
- end
-
PIO = PostcodeService.new
def process_previous_postcode_changes!
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index 8e68500a4..69e4134d8 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -3,7 +3,6 @@ class Organisation < ApplicationRecord
has_many :owned_lettings_logs, class_name: "LettingsLog", foreign_key: "owning_organisation_id", dependent: :delete_all
has_many :managed_lettings_logs, class_name: "LettingsLog", foreign_key: "managing_organisation_id"
has_many :owned_sales_logs, class_name: "SalesLog", foreign_key: "owning_organisation_id", dependent: :delete_all
- has_many :managed_sales_logs, class_name: "SalesLog", foreign_key: "managing_organisation_id"
has_many :data_protection_confirmations
has_many :organisation_rent_periods
has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id", dependent: :delete_all
diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb
index 45bd9f729..aa3eb1c09 100644
--- a/app/models/sales_log.rb
+++ b/app/models/sales_log.rb
@@ -32,6 +32,7 @@ class SalesLog < Log
scope :filter_by_year, ->(year) { where(saledate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :search_by, ->(param) { filter_by_id(param) }
+ scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) }
OPTIONAL_FIELDS = %w[purchid].freeze
RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze
@@ -184,6 +185,14 @@ class SalesLog < Log
process_postcode(postcode_full, "pcodenk", "is_la_inferred", "la")
end
+ def reset_created_by!
+ return unless updated_by&.support?
+ return if owning_organisation.blank? || created_by.blank?
+ return if created_by&.organisation == owning_organisation
+
+ update!(created_by: nil)
+ end
+
def retirement_age_for_person(person_num)
gender = public_send("sex#{person_num}".to_sym)
return unless gender
diff --git a/app/models/user.rb b/app/models/user.rb
index 66e3e806f..04a545584 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -10,7 +10,6 @@ class User < ApplicationRecord
has_many :owned_lettings_logs, through: :organisation
has_many :managed_lettings_logs, through: :organisation
has_many :owned_sales_logs, through: :organisation
- has_many :managed_sales_logs, through: :organisation
has_many :legacy_users
has_many :bulk_uploads
diff --git a/app/services/filter_service.rb b/app/services/filter_service.rb
index 8fe1030de..4ef3a582c 100644
--- a/app/services/filter_service.rb
+++ b/app/services/filter_service.rb
@@ -17,6 +17,14 @@ class FilterService
logs = logs.public_send("filter_by_#{category}", values, user)
end
logs = logs.order(created_at: :desc)
- user.support? ? logs.all.includes(:owning_organisation, :managing_organisation) : logs
+ if user.support?
+ if logs.first&.lettings?
+ logs.all.includes(:owning_organisation, :managing_organisation)
+ else
+ logs.all.includes(:owning_organisation)
+ end
+ else
+ logs
+ end
end
end
diff --git a/db/migrate/20230110094518_remove_managing_organisation_id_from_sales_logs.rb b/db/migrate/20230110094518_remove_managing_organisation_id_from_sales_logs.rb
new file mode 100644
index 000000000..b2aa71d76
--- /dev/null
+++ b/db/migrate/20230110094518_remove_managing_organisation_id_from_sales_logs.rb
@@ -0,0 +1,13 @@
+class RemoveManagingOrganisationIdFromSalesLogs < ActiveRecord::Migration[7.0]
+ def up
+ change_table :sales_logs, bulk: true do |t|
+ t.remove :managing_organisation_id
+ end
+ end
+
+ def down
+ change_table :sales_logs, bulk: true do |t|
+ t.column :managing_organisation_id, :bigint
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e97d4a5ac..55cb24599 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -367,7 +367,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "owning_organisation_id"
- t.bigint "managing_organisation_id"
t.bigint "created_by_id"
t.string "purchid"
t.integer "type"
@@ -490,23 +489,22 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
t.integer "mortgagelender"
t.string "mortgagelenderother"
t.integer "mortlen"
- t.string "pcode1"
- t.string "pcode2"
- t.integer "pcodenk"
- t.string "postcode_full"
- t.boolean "is_la_inferred"
t.integer "extrabor"
t.integer "hhmemb"
t.integer "totadult"
t.integer "totchild"
t.integer "hhtype"
- t.integer "hodate_check"
+ t.string "pcode1"
+ t.string "pcode2"
+ t.integer "pcodenk"
+ t.string "postcode_full"
+ t.boolean "is_la_inferred"
t.bigint "bulk_upload_id"
t.integer "retirement_value_check"
+ t.integer "hodate_check"
t.integer "extrabor_value_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
- t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"
t.index ["updated_by_id"], name: "index_sales_logs_on_updated_by_id"
end
diff --git a/spec/components/log_summary_component_spec.rb b/spec/components/log_summary_component_spec.rb
index 78d5a73ad..f8edfb948 100644
--- a/spec/components/log_summary_component_spec.rb
+++ b/spec/components/log_summary_component_spec.rb
@@ -5,15 +5,16 @@ RSpec.describe LogSummaryComponent, type: :component do
let(:coordinator_user) { FactoryBot.create(:user) }
let(:propcode) { "P3647" }
let(:tenancycode) { "T62863" }
- let(:log) { FactoryBot.create(:lettings_log, needstype: 1, startdate: Time.utc(2022, 1, 1), tenancycode:, propcode:) }
+ let(:lettings_log) { FactoryBot.create(:lettings_log, needstype: 1, startdate: Time.utc(2022, 1, 1), tenancycode:, propcode:) }
+ let(:sales_log) { FactoryBot.create(:sales_log) }
- context "when rendering log for a support user" do
+ context "when rendering lettings log for a support user" do
it "show the log summary with organisational relationships" do
- result = render_inline(described_class.new(current_user: support_user, log:))
+ result = render_inline(described_class.new(current_user: support_user, log: lettings_log))
- expect(result).to have_link(log.id.to_s)
- expect(result).to have_text(log.tenancycode)
- expect(result).to have_text(log.propcode)
+ expect(result).to have_link(lettings_log.id.to_s)
+ expect(result).to have_text(lettings_log.tenancycode)
+ expect(result).to have_text(lettings_log.propcode)
expect(result).to have_text("General needs")
expect(result).to have_text("Tenancy starts 1 January 2022")
expect(result).to have_text("Created 8 February 2022")
@@ -23,12 +24,30 @@ RSpec.describe LogSummaryComponent, type: :component do
end
end
- context "when rendering log for a data coordinator user" do
+ context "when rendering lettings log for a data coordinator user" do
it "show the log summary" do
- result = render_inline(described_class.new(current_user: coordinator_user, log:))
+ result = render_inline(described_class.new(current_user: coordinator_user, log: lettings_log))
- expect(result).not_to have_content("Owned by\n DLUHC")
- expect(result).not_to have_content("Managed by\n DLUHC")
+ expect(result).not_to have_content("Owned by")
+ expect(result).not_to have_content("Managed by")
+ end
+ end
+
+ context "when rendering sales log for a support user" do
+ it "show the log summary with organisational relationships" do
+ result = render_inline(described_class.new(current_user: support_user, log: sales_log))
+
+ expect(result).to have_content("Owned by\n DLUHC")
+ expect(result).not_to have_content("Managed by")
+ end
+ end
+
+ context "when rendering sales log for a data coordinator user" do
+ it "show the log summary" do
+ result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log))
+
+ expect(result).not_to have_content("Owned by")
+ expect(result).not_to have_content("Managed by")
end
end
end
diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb
index fb0461d99..003b11144 100644
--- a/spec/factories/sales_log.rb
+++ b/spec/factories/sales_log.rb
@@ -2,7 +2,6 @@ FactoryBot.define do
factory :sales_log do
created_by { FactoryBot.create(:user) }
owning_organisation { created_by.organisation }
- managing_organisation { created_by.organisation }
created_at { Time.utc(2022, 2, 8, 16, 52, 15) }
updated_at { Time.utc(2022, 2, 8, 16, 52, 15) }
trait :in_progress do
diff --git a/spec/features/form/check_answers_page_lettings_logs_spec.rb b/spec/features/form/check_answers_page_lettings_logs_spec.rb
index f8f0b8064..9062e1abc 100644
--- a/spec/features/form/check_answers_page_lettings_logs_spec.rb
+++ b/spec/features/form/check_answers_page_lettings_logs_spec.rb
@@ -143,7 +143,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
end
context "when the user is checking their answers for the household characteristics subsection" do
- it "they see a seperate summary card for each member of the household" do
+ it "they see a separate summary card for each member of the household" do
visit("/lettings-logs/#{completed_lettings_log.id}/#{subsection}/check-answers")
assert_selector ".x-govuk-summary-card__title", text: "Lead tenant", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 1
diff --git a/spec/features/form/check_answers_page_sales_logs_spec.rb b/spec/features/form/check_answers_page_sales_logs_spec.rb
index 9d1f33d64..2c6dc050d 100644
--- a/spec/features/form/check_answers_page_sales_logs_spec.rb
+++ b/spec/features/form/check_answers_page_sales_logs_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe "Sales Log Check Answers Page" do
context "when the user is checking their answers for the household characteristics subsection" do
context "and the log is for a joint purchase" do
- it "they see a seperate summary card for each member of the household" do
+ it "they see a separate summary card for each member of the household" do
visit("/sales-logs/#{completed_sales_log_joint_purchase.id}/#{subsection}/check-answers")
assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 1
@@ -49,7 +49,7 @@ RSpec.describe "Sales Log Check Answers Page" do
end
context "and the log is for a non-joint purchase" do
- it "they see a seperate summary card for each member of the household" do
+ it "they see a separate summary card for each member of the household" do
visit("/sales-logs/#{completed_sales_log_non_joint_purchase.id}/#{subsection}/check-answers")
assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 0
diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb
index 9d2478d9f..bc6aa243a 100644
--- a/spec/features/organisation_spec.rb
+++ b/spec/features/organisation_spec.rb
@@ -215,7 +215,7 @@ RSpec.describe "User Features" do
let(:number_of_sales_logs) { SalesLog.count }
before do
- FactoryBot.create_list(:sales_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id)
+ FactoryBot.create_list(:sales_log, 4, owning_organisation_id: organisation.id)
visit("/organisations/#{org_id}/sales-logs")
end
diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb
index 8a4325880..c8cdc466e 100644
--- a/spec/models/lettings_log_spec.rb
+++ b/spec/models/lettings_log_spec.rb
@@ -2392,12 +2392,6 @@ RSpec.describe LettingsLog do
FactoryBot.create(:lettings_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2, created_by: nil)
end
- it "filters by given organisation id" do
- expect(described_class.filter_by_organisation([organisation_1.id]).count).to eq(3)
- expect(described_class.filter_by_organisation([organisation_1.id, organisation_2.id]).count).to eq(4)
- expect(described_class.filter_by_organisation([organisation_3.id]).count).to eq(0)
- end
-
it "filters by given organisation" do
expect(described_class.filter_by_organisation([organisation_1]).count).to eq(3)
expect(described_class.filter_by_organisation([organisation_1, organisation_2]).count).to eq(4)
diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb
index 6d402fa80..0b69fd504 100644
--- a/spec/models/organisation_spec.rb
+++ b/spec/models/organisation_spec.rb
@@ -196,7 +196,7 @@ RSpec.describe Organisation, type: :model do
let!(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now, organisation:) }
let!(:scheme_to_delete) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:log_to_delete) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation) }
- let!(:sales_log_to_delete) { FactoryBot.create(:sales_log, owning_organisation: user.organisation, managing_organisation: user.organisation) }
+ let!(:sales_log_to_delete) { FactoryBot.create(:sales_log, owning_organisation: user.organisation) }
context "when organisation is deleted" do
it "child relationships ie logs, schemes and users are deleted too - application" do
diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb
index 3720dba56..ccfff433f 100644
--- a/spec/models/sales_log_spec.rb
+++ b/spec/models/sales_log_spec.rb
@@ -93,21 +93,14 @@ RSpec.describe SalesLog, type: :model do
let(:organisation_3) { create(:organisation) }
before do
- create(:sales_log, :in_progress, owning_organisation: organisation_1, managing_organisation: organisation_1)
- create(:sales_log, :completed, owning_organisation: organisation_1, managing_organisation: organisation_2)
- create(:sales_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_1)
- create(:sales_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2)
- end
-
- it "filters by given organisation id" do
- expect(described_class.filter_by_organisation([organisation_1.id]).count).to eq(3)
- expect(described_class.filter_by_organisation([organisation_1.id, organisation_2.id]).count).to eq(4)
- expect(described_class.filter_by_organisation([organisation_3.id]).count).to eq(0)
+ create(:sales_log, :in_progress, owning_organisation: organisation_1)
+ create(:sales_log, :completed, owning_organisation: organisation_1)
+ create(:sales_log, :completed, owning_organisation: organisation_2)
end
it "filters by given organisation" do
- expect(described_class.filter_by_organisation([organisation_1]).count).to eq(3)
- expect(described_class.filter_by_organisation([organisation_1, organisation_2]).count).to eq(4)
+ expect(described_class.filter_by_organisation([organisation_1]).count).to eq(2)
+ expect(described_class.filter_by_organisation([organisation_1, organisation_2]).count).to eq(3)
expect(described_class.filter_by_organisation([organisation_3]).count).to eq(0)
end
end
@@ -165,7 +158,6 @@ RSpec.describe SalesLog, type: :model do
FactoryBot.create(
:sales_log,
:completed,
- managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
pcodenk: 0,
@@ -297,7 +289,6 @@ RSpec.describe SalesLog, type: :model do
let!(:address_sales_log) do
described_class.create({
- managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
ppcodenk: 1,
diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb
index ab5dcb6af..f63dcf54e 100644
--- a/spec/requests/organisations_controller_spec.rb
+++ b/spec/requests/organisations_controller_spec.rb
@@ -734,8 +734,8 @@ RSpec.describe OrganisationsController, type: :request do
let(:number_of_org2_sales_logs) { 4 }
before do
- FactoryBot.create_list(:sales_log, number_of_org1_sales_logs, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id)
- FactoryBot.create_list(:sales_log, number_of_org2_sales_logs, owning_organisation_id: unauthorised_organisation.id, managing_organisation_id: unauthorised_organisation.id)
+ FactoryBot.create_list(:sales_log, number_of_org1_sales_logs, owning_organisation_id: organisation.id)
+ FactoryBot.create_list(:sales_log, number_of_org2_sales_logs, owning_organisation_id: unauthorised_organisation.id)
get "/organisations/#{organisation.id}/sales-logs", headers:, params: {}
end
diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb
index 65b3f94ef..f8690a71b 100644
--- a/spec/requests/sales_logs_controller_spec.rb
+++ b/spec/requests/sales_logs_controller_spec.rb
@@ -3,7 +3,6 @@ require "rails_helper"
RSpec.describe SalesLogsController, type: :request do
let(:user) { FactoryBot.create(:user) }
let(:owning_organisation) { user.organisation }
- let(:managing_organisation) { owning_organisation }
let(:api_username) { "test_user" }
let(:api_password) { "test_password" }
let(:basic_credentials) do
@@ -14,7 +13,6 @@ RSpec.describe SalesLogsController, type: :request do
let(:params) do
{
"owning_organisation_id": owning_organisation.id,
- "managing_organisation_id": managing_organisation.id,
"created_by_id": user.id,
}
end
@@ -51,7 +49,6 @@ RSpec.describe SalesLogsController, type: :request do
it "creates a sales log with the values passed" do
json_response = JSON.parse(response.body)
expect(json_response["owning_organisation_id"]).to eq(owning_organisation.id)
- expect(json_response["managing_organisation_id"]).to eq(managing_organisation.id)
expect(json_response["created_by_id"]).to eq(user.id)
end
@@ -94,14 +91,12 @@ RSpec.describe SalesLogsController, type: :request do
FactoryBot.create(
:sales_log,
owning_organisation: organisation,
- managing_organisation: organisation,
)
end
let!(:unauthorized_sales_log) do
FactoryBot.create(
:sales_log,
owning_organisation: other_organisation,
- managing_organisation: other_organisation,
)
end
@@ -119,7 +114,7 @@ RSpec.describe SalesLogsController, type: :request do
it "does have organisation values" do
get "/sales-logs", headers: headers, params: {}
expect(page).to have_content("Owned by")
- expect(page).to have_content("Managed by")
+ expect(page).not_to have_content("Managed by")
end
it "shows sales logs for all organisations" do
@@ -146,13 +141,11 @@ RSpec.describe SalesLogsController, type: :request do
let!(:not_started_sales_log) do
FactoryBot.create(:sales_log,
owning_organisation: organisation,
- managing_organisation: organisation,
created_by: user)
end
let!(:completed_sales_log) do
FactoryBot.create(:sales_log, :completed,
owning_organisation: organisation_2,
- managing_organisation: organisation,
created_by: user_2)
end
@@ -189,14 +182,12 @@ RSpec.describe SalesLogsController, type: :request do
let!(:sales_log_2021) do
FactoryBot.create(:sales_log, :in_progress,
owning_organisation: organisation,
- saledate: Time.zone.local(2022, 3, 1),
- managing_organisation: organisation)
+ saledate: Time.zone.local(2022, 3, 1))
end
let!(:sales_log_2022) do
sales_log = FactoryBot.build(:sales_log, :completed,
owning_organisation: organisation,
- saledate: Time.zone.local(2022, 12, 1),
- managing_organisation: organisation)
+ saledate: Time.zone.local(2022, 12, 1))
sales_log.save!(validate: false)
sales_log
end
@@ -227,14 +218,12 @@ RSpec.describe SalesLogsController, type: :request do
FactoryBot.create(:sales_log, :completed,
owning_organisation: organisation,
saledate: Time.zone.local(2022, 3, 1),
- managing_organisation: organisation,
created_by: user)
end
let!(:sales_log_2022) do
FactoryBot.create(:sales_log,
owning_organisation: organisation,
saledate: Time.zone.local(2022, 12, 1),
- managing_organisation: organisation,
created_by: user)
end
@@ -362,7 +351,7 @@ RSpec.describe SalesLogsController, type: :request do
context "when there are more than 20 logs" do
before do
- FactoryBot.create_list(:sales_log, 25, owning_organisation: organisation, managing_organisation: organisation)
+ FactoryBot.create_list(:sales_log, 25, owning_organisation: organisation)
end
context "when on the first page" do
From 4659a3efcf240fc9a6904e1c8ebfc46f409c42e1 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Thu, 26 Jan 2023 16:49:33 +0000
Subject: [PATCH 10/12] CLDC-1899 Add discounted ownership value validation
(#1229)
* Add validation for discounted ownership value
* Fix tests
* Update validations to work with different routing
* update error message
---
.../sales/sale_information_validations.rb | 16 ++
config/locales/en.yml | 1 +
spec/factories/sales_log.rb | 4 +-
.../sale_information_validations_spec.rb | 153 ++++++++++++++++++
4 files changed, 172 insertions(+), 2 deletions(-)
diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb
index be0295f2c..c42c42ccc 100644
--- a/app/models/validations/sales/sale_information_validations.rb
+++ b/app/models/validations/sales/sale_information_validations.rb
@@ -38,4 +38,20 @@ module Validations::Sales::SaleInformationValidations
record.errors.add :fromprop, I18n.t("validations.sale_information.previous_property_type.property_type_bedsit")
end
end
+
+ def validate_discounted_ownership_value(record)
+ return unless record.value && record.deposit && record.ownershipsch
+ return unless record.mortgage || record.mortgageused == 2
+ return unless record.discount || record.grant || record.type == 29
+
+ discount_amount = record.discount ? record.value * record.discount / 100 : 0
+ grant_amount = record.grant || 0
+ mortgage_amount = record.mortgage || 0
+ value_with_discount = (record.value - discount_amount)
+ if mortgage_amount + record.deposit + grant_amount != value_with_discount && record.discounted_ownership_sale?
+ %i[mortgage deposit grant value discount ownershipsch].each do |field|
+ record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: sprintf("%.2f", value_with_discount))
+ end
+ end
+ end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 0be594420..3dd612e8e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -425,6 +425,7 @@ en:
property_type_bedsit: "Bedsit bedroom maximum 1"
previous_property_type:
property_type_bedsit: "A bedsit can not have more than 1 bedroom"
+ discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}"
soft_validations:
net_income:
diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb
index 003b11144..f83d102d3 100644
--- a/spec/factories/sales_log.rb
+++ b/spec/factories/sales_log.rb
@@ -70,10 +70,10 @@ FactoryBot.define do
ecstat5 { 2 }
ecstat6 { 1 }
disabled { 1 }
- deposit { 10_000 }
+ deposit { 80_000 }
cashdis { 1_000 }
value { 110_000 }
- grant { 1_000 }
+ grant { 10_000 }
proplen { 10 }
pregyrha { 1 }
pregla { 1 }
diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb
index fb3aea06c..d2921e8f0 100644
--- a/spec/models/validations/sales/sale_information_validations_spec.rb
+++ b/spec/models/validations/sales/sale_information_validations_spec.rb
@@ -218,4 +218,157 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
end
+
+ describe "#validate_discounted_ownership_value" do
+ context "when grant is routed to" do
+ let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, ownershipsch: 2, type: 8) }
+
+ context "and not provided" do
+ before do
+ record.grant = nil
+ end
+
+ it "does not add an error" do
+ sale_information_validator.validate_discounted_ownership_value(record)
+
+ expect(record.errors).to be_empty
+ end
+ end
+
+ context "and is provided" do
+ it "adds an error if mortgage, deposit and grant total does not equal market value" do
+ record.grant = 3_000
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors[:mortgage]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:deposit]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:grant]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:value]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:discount]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ end
+
+ it "does not add an error if mortgage, deposit and grant total equals market value" do
+ record.grant = 15_000
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors).to be_empty
+ end
+ end
+ end
+
+ context "when discount is routed to" do
+ let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, ownershipsch: 2, type: 9) }
+
+ context "and not provided" do
+ before do
+ record.discount = nil
+ end
+
+ it "does not add an error" do
+ sale_information_validator.validate_discounted_ownership_value(record)
+
+ expect(record.errors).to be_empty
+ end
+ end
+
+ context "and is provided" do
+ it "adds an error if mortgage and deposit total does not equal market value - discount" do
+ record.discount = 10
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors[:mortgage]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "27000.00"))
+ expect(record.errors[:deposit]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "27000.00"))
+ expect(record.errors[:grant]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "27000.00"))
+ expect(record.errors[:value]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "27000.00"))
+ expect(record.errors[:discount]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "27000.00"))
+ end
+
+ it "does not add an error if mortgage and deposit total equals market value - discount" do
+ record.discount = 50
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors).to be_empty
+ end
+ end
+ end
+
+ context "when neither discount nor grant is routed to" do
+ let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, value: 30_000, ownershipsch: 2, type: 29) }
+
+ it "adds an error if mortgage and deposit total does not equal market value" do
+ record.deposit = 2_000
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors[:mortgage]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:deposit]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:grant]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:value]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ expect(record.errors[:discount]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "30000.00"))
+ end
+
+ it "does not add an error if mortgage and deposit total equals market value" do
+ record.deposit = 20_000
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors).to be_empty
+ end
+ end
+
+ context "when mortgage is routed to" do
+ let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2) }
+
+ context "and not provided" do
+ before do
+ record.mortgage = nil
+ end
+
+ it "does not add an error" do
+ sale_information_validator.validate_discounted_ownership_value(record)
+
+ expect(record.errors).to be_empty
+ end
+ end
+
+ context "and is provided" do
+ it "adds an error if mortgage, grant and deposit total does not equal market value - discount" do
+ record.mortgage = 10
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors[:mortgage]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:deposit]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:grant]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:value]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:discount]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ end
+
+ it "does not add an error if mortgage, grant and deposit total equals market value - discount" do
+ record.mortgage = 10_000
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors).to be_empty
+ end
+ end
+ end
+
+ context "when mortgage is not routed to" do
+ let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2) }
+
+ it "adds an error if grant and deposit total does not equal market value - discount" do
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors[:mortgage]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:deposit]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:grant]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:value]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ expect(record.errors[:discount]).to include(I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: "18000.00"))
+ end
+
+ it "does not add an error if mortgage, grant and deposit total equals market value - discount" do
+ record.grant = 13_000
+ sale_information_validator.validate_discounted_ownership_value(record)
+ expect(record.errors).to be_empty
+ end
+ end
+
+ context "when owhership is not discounted" do
+ let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 1) }
+
+ it "does not add an error" do
+ sale_information_validator.validate_discounted_ownership_value(record)
+
+ expect(record.errors).to be_empty
+ end
+ end
+ end
end
From 0f17eab3fedf1b4cc7d650481c0d473d9716572d Mon Sep 17 00:00:00 2001
From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com>
Date: Thu, 26 Jan 2023 17:22:41 +0000
Subject: [PATCH 11/12] CLDC 882 add validation against grant (#1220)
* fix rebase conflicts
* fix rebase conflicts
* fix rebase conflicts
* implement soft validation of grant value
* fix rebase conflicts
* fix rebase conflicts
* fix rebase conflicts
* fix rebase conflicts
* fix final test from added page
* update test after rebase
---
.../form/sales/pages/grant_value_check.rb | 18 +++++++++++++++
app/models/form/sales/questions/grant.rb | 1 +
.../form/sales/questions/grant_value_check.rb | 23 +++++++++++++++++++
.../discounted_ownership_scheme.rb | 1 +
.../validations/sales/soft_validations.rb | 6 +++++
...0741_add_grant_value_check_to_sales_log.rb | 5 ++++
db/schema.rb | 6 +++--
.../discounted_ownership_scheme_spec.rb | 1 +
spec/models/form_handler_spec.rb | 4 ++--
.../sales/soft_validations_spec.rb | 20 ++++++++++++++++
10 files changed, 81 insertions(+), 4 deletions(-)
create mode 100644 app/models/form/sales/pages/grant_value_check.rb
create mode 100644 app/models/form/sales/questions/grant_value_check.rb
create mode 100644 db/migrate/20230123160741_add_grant_value_check_to_sales_log.rb
diff --git a/app/models/form/sales/pages/grant_value_check.rb b/app/models/form/sales/pages/grant_value_check.rb
new file mode 100644
index 000000000..a739a1654
--- /dev/null
+++ b/app/models/form/sales/pages/grant_value_check.rb
@@ -0,0 +1,18 @@
+class Form::Sales::Pages::GrantValueCheck < ::Form::Page
+ def initialize(id, hsh, subsection)
+ super
+ @id = "grant_value_check"
+ @depends_on = [
+ {
+ "grant_outside_common_range?" => true,
+ },
+ ]
+ @informative_text = {}
+ end
+
+ def questions
+ @questions ||= [
+ Form::Sales::Questions::GrantValueCheck.new(nil, nil, self),
+ ]
+ end
+end
diff --git a/app/models/form/sales/questions/grant.rb b/app/models/form/sales/questions/grant.rb
index 181e2281d..beef93c58 100644
--- a/app/models/form/sales/questions/grant.rb
+++ b/app/models/form/sales/questions/grant.rb
@@ -6,6 +6,7 @@ class Form::Sales::Questions::Grant < ::Form::Question
@header = "What was the amount of any loan, grant, discount or subsidy given?"
@type = "numeric"
@min = 0
+ @max = 999_999
@width = 5
@prefix = "£"
@hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)"
diff --git a/app/models/form/sales/questions/grant_value_check.rb b/app/models/form/sales/questions/grant_value_check.rb
new file mode 100644
index 000000000..a7efdbaee
--- /dev/null
+++ b/app/models/form/sales/questions/grant_value_check.rb
@@ -0,0 +1,23 @@
+class Form::Sales::Questions::GrantValueCheck < ::Form::Question
+ def initialize(id, hsh, page)
+ super
+ @id = "grant_value_check"
+ @check_answer_label = "Grant value confirmation"
+ @header = "Are you sure? Grants are usually £9,000 - £16,000"
+ @type = "interruption_screen"
+ @answer_options = {
+ "0" => { "value" => "Yes" },
+ "1" => { "value" => "No" },
+ }
+ @hidden_in_check_answers = {
+ "depends_on" => [
+ {
+ "grant_value_check" => 0,
+ },
+ {
+ "grant_value_check" => 1,
+ },
+ ],
+ }
+ end
+end
diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb
index 3b994d931..2ab47e729 100644
--- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb
+++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb
@@ -12,6 +12,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self),
Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_price_value_check", nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
+ Form::Sales::Pages::GrantValueCheck.new(nil, nil, self),
Form::Sales::Pages::PurchasePrice.new("purchase_price_discounted_ownership", nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb
index e39b5e9d9..742e505a5 100644
--- a/app/models/validations/sales/soft_validations.rb
+++ b/app/models/validations/sales/soft_validations.rb
@@ -48,4 +48,10 @@ module Validations::Sales::SoftValidations
((saledate.to_date - hodate.to_date).to_i / 365) >= 3
end
+
+ def grant_outside_common_range?
+ return unless grant
+
+ !grant.between?(9_000, 16_000)
+ end
end
diff --git a/db/migrate/20230123160741_add_grant_value_check_to_sales_log.rb b/db/migrate/20230123160741_add_grant_value_check_to_sales_log.rb
new file mode 100644
index 000000000..9a9cfb8ea
--- /dev/null
+++ b/db/migrate/20230123160741_add_grant_value_check_to_sales_log.rb
@@ -0,0 +1,5 @@
+class AddGrantValueCheckToSalesLog < ActiveRecord::Migration[7.0]
+ def change
+ add_column :sales_logs, :grant_value_check, :integer
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 55cb24599..8722ec6a4 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
+ActiveRecord::Schema[7.0].define(version: 2023_01_23_160741) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -486,9 +486,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
t.integer "hoyear"
t.integer "fromprop"
t.integer "socprevten"
+ t.integer "mortlen"
t.integer "mortgagelender"
t.string "mortgagelenderother"
- t.integer "mortlen"
t.integer "extrabor"
t.integer "hhmemb"
t.integer "totadult"
@@ -501,6 +501,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_18_170602) do
t.boolean "is_la_inferred"
t.bigint "bulk_upload_id"
t.integer "retirement_value_check"
+ t.integer "deposit_and_mortgage_value_check"
+ t.integer "grant_value_check"
t.integer "hodate_check"
t.integer "extrabor_value_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
index 44896a0f9..7df741091 100644
--- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
+++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
@@ -18,6 +18,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
about_price_rtb
extra_borrowing_price_value_check
about_price_not_rtb
+ grant_value_check
purchase_price_discounted_ownership
mortgage_used_discounted_ownership
mortgage_amount_discounted_ownership
diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb
index 8f9a88f7f..c7bfdc85b 100644
--- a/spec/models/form_handler_spec.rb
+++ b/spec/models/form_handler_spec.rb
@@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(187)
+ expect(form.pages.count).to eq(188)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(187)
+ expect(form.pages.count).to eq(188)
expect(form.name).to eq("2021_2022_sales")
end
end
diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb
index 17bd87d96..da0ab8ed9 100644
--- a/spec/models/validations/sales/soft_validations_spec.rb
+++ b/spec/models/validations/sales/soft_validations_spec.rb
@@ -396,4 +396,24 @@ RSpec.describe Validations::Sales::SoftValidations do
expect(record).not_to be_wheelchair_when_not_disabled
end
end
+
+ describe "#grant_outside_common_range?" do
+ it "returns true if grant is below 9000" do
+ record.grant = 1_000
+
+ expect(record).to be_grant_outside_common_range
+ end
+
+ it "returns true if grant is above 16000" do
+ record.grant = 100_000
+
+ expect(record).to be_grant_outside_common_range
+ end
+
+ it "returns false if grant is within expected range" do
+ record.grant = 10_000
+
+ expect(record).not_to be_grant_outside_common_range
+ end
+ end
end
From 740f4cbdd429ee2a955510bbcdd4a256c319e200 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Fri, 27 Jan 2023 08:09:08 +0000
Subject: [PATCH 12/12] CLDC-1843 Hide download csv link for sales logs (#1230)
* Hide download csv link for sales logs
* refactor
---
app/views/logs/_log_list.html.erb | 4 +++-
spec/requests/lettings_logs_controller_spec.rb | 1 +
spec/requests/organisations_controller_spec.rb | 5 +++--
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/app/views/logs/_log_list.html.erb b/app/views/logs/_log_list.html.erb
index 702cd7d1f..1aeaa03f2 100644
--- a/app/views/logs/_log_list.html.erb
+++ b/app/views/logs/_log_list.html.erb
@@ -1,6 +1,8 @@