Browse Source

Update model/validations tests

pull/2432/head
Kat 2 years ago
parent
commit
b6c922956b
  1. 9
      spec/models/validations/date_validations_spec.rb
  2. 90
      spec/models/validations/household_validations_spec.rb
  3. 42
      spec/models/validations/sales/financial_validations_spec.rb
  4. 97
      spec/models/validations/sales/household_validations_spec.rb
  5. 85
      spec/models/validations/sales/sale_information_validations_spec.rb
  6. 46
      spec/models/validations/sales/setup_validations_spec.rb
  7. 60
      spec/models/validations/setup_validations_spec.rb
  8. 79
      spec/models/validations/soft_validations_spec.rb

9
spec/models/validations/date_validations_spec.rb

@ -9,15 +9,6 @@ RSpec.describe Validations::DateValidations do
let(:scheme_no_end_date) { create(:scheme, end_date: nil) } let(:scheme_no_end_date) { create(:scheme, end_date: nil) }
describe "tenancy start date" do describe "tenancy start date" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
it "must be a valid date" do it "must be a valid date" do
record.startdate = Time.zone.local(0, 7, 1) record.startdate = Time.zone.local(0, 7, 1)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)

90
spec/models/validations/household_validations_spec.rb

@ -4,16 +4,8 @@ RSpec.describe Validations::HouseholdValidations do
subject(:household_validator) { validator_class.new } subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::HouseholdValidations } } let(:validator_class) { Class.new { include Validations::HouseholdValidations } }
let(:log_date) { Time.zone.now } let(:startdate) { Time.zone.now }
let(:record) { FactoryBot.create(:lettings_log, :setup_completed, startdate: log_date) } let(:record) { FactoryBot.build(:lettings_log, :setup_completed, startdate:) }
before do
Timecop.freeze(log_date + 1)
end
after do
Timecop.return
end
describe "reasonable preference validations" do describe "reasonable preference validations" do
context "when reasonable preference is not given" do context "when reasonable preference is not given" do
@ -59,7 +51,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "when form year is before 2024" do context "when form year is before 2024" do
let(:log_date) { Time.zone.local(2024, 1, 1) } let(:startdate) { Time.zone.local(2024, 1, 1) }
it "does not validate the content of reasonother for phrases indicating homelessness" do it "does not validate the content of reasonother for phrases indicating homelessness" do
record.reason = 20 record.reason = 20
@ -70,7 +62,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "when form year is >= 2024" do context "when form year is >= 2024" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:startdate) { Time.zone.local(2024, 4, 1) }
context "when checking the content of reasonother" do context "when checking the content of reasonother" do
it "validates that the reason doesn't match phrase indicating homelessness" do it "validates that the reason doesn't match phrase indicating homelessness" do
@ -277,7 +269,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
describe "#validate_partner_count" do describe "#validate_partner_count" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:startdate) { Time.zone.local(2023, 4, 1) }
it "validates that only 1 partner exists" do it "validates that only 1 partner exists" do
record.relat2 = "P" record.relat2 = "P"
@ -300,17 +292,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "#validate_person_age_matches_relationship" do describe "#validate_person_age_matches_relationship" do
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:startdate) { Time.zone.local(2023, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when the household contains a person under 16" do context "when the household contains a person under 16" do
it "validates that person must be a child of the tenant" do it "validates that person must be a child of the tenant" do
@ -334,17 +316,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:startdate) { Time.zone.local(2024, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "does not add an error is person under 16 is a partner" do it "does not add an error is person under 16 is a partner" do
record.age2 = 14 record.age2 = 14
@ -366,17 +338,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "#validate_person_age_matches_economic_status" do describe "#validate_person_age_matches_economic_status" do
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:startdate) { Time.zone.local(2023, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when the household contains a person under 16" do context "when the household contains a person under 16" do
it "validates that person's economic status must be Child" do it "validates that person's economic status must be Child" do
@ -411,17 +373,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:startdate) { Time.zone.local(2024, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "does not run the validation" do it "does not run the validation" do
record.age2 = 14 record.age2 = 14
@ -437,17 +389,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "#validate_person_age_and_relationship_matches_economic_status" do describe "#validate_person_age_and_relationship_matches_economic_status" do
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:startdate) { Time.zone.local(2023, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when the household contains a tenant’s child between the ages of 16 and 19" do context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "validates that person's economic status must be full time student or refused" do it "validates that person's economic status must be full time student or refused" do
@ -519,17 +461,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:startdate) { Time.zone.local(2024, 4, 1) }
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "when the household contains a tenant’s child between the ages of 16 and 19" do context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "does not add an error" do it "does not add an error" do

42
spec/models/validations/sales/financial_validations_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
let(:validator_class) { Class.new { include Validations::Sales::FinancialValidations } } let(:validator_class) { Class.new { include Validations::Sales::FinancialValidations } }
describe "income validations for shared ownership" do describe "income validations for shared ownership" do
let(:record) { FactoryBot.create(:sales_log, ownershipsch: 1) } let(:record) { FactoryBot.build(:sales_log, ownershipsch: 1) }
context "when buying in a non london borough" do context "when buying in a non london borough" do
before do before do
@ -150,7 +150,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_mortgage" do describe "#validate_mortgage" do
let(:record) { FactoryBot.create(:sales_log) } let(:record) { FactoryBot.build(:sales_log) }
it "adds an error is the mortgage is zero" do it "adds an error is the mortgage is zero" do
record.mortgageused = 1 record.mortgageused = 1
@ -168,7 +168,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_percentage_bought_not_greater_than_percentage_owned" do describe "#validate_percentage_bought_not_greater_than_percentage_owned" do
let(:record) { FactoryBot.create(:sales_log) } let(:record) { FactoryBot.build(:sales_log) }
it "does not add an error if the percentage bought is less than the percentage owned" do it "does not add an error if the percentage bought is less than the percentage owned" do
record.stairbought = 20 record.stairbought = 20
@ -202,7 +202,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_percentage_bought_not_equal_percentage_owned" do describe "#validate_percentage_bought_not_equal_percentage_owned" do
let(:record) { FactoryBot.create(:sales_log) } let(:record) { FactoryBot.build(:sales_log) }
context "with 24/25 logs" do context "with 24/25 logs" do
before do before do
@ -249,7 +249,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_monthly_leasehold_charges" do describe "#validate_monthly_leasehold_charges" do
let(:record) { FactoryBot.create(:sales_log) } let(:record) { FactoryBot.build(:sales_log) }
it "does not add an error if monthly leasehold charges are positive" do it "does not add an error if monthly leasehold charges are positive" do
record.mscharge = 2345 record.mscharge = 2345
@ -265,7 +265,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_percentage_bought_at_least_threshold" do describe "#validate_percentage_bought_at_least_threshold" do
let(:record) { FactoryBot.create(:sales_log) } let(:record) { FactoryBot.build(:sales_log) }
it "adds an error to stairbought and type if the percentage bought is less than the threshold (which is 1% by default, but higher for some shared ownership types)" do it "adds an error to stairbought and type if the percentage bought is less than the threshold (which is 1% by default, but higher for some shared ownership types)" do
record.stairbought = 9 record.stairbought = 9
@ -307,7 +307,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_child_income" do describe "#validate_child_income" do
let(:record) { FactoryBot.create(:sales_log) } let(:record) { FactoryBot.build(:sales_log) }
context "when buyer 2 is not a child" do context "when buyer 2 is not a child" do
before do before do
@ -352,17 +352,10 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_equity_in_range_for_year_and_type" do describe "#validate_equity_in_range_for_year_and_type" do
let(:record) { FactoryBot.create(:sales_log, saledate: now) } let(:record) { FactoryBot.build(:sales_log, saledate:) }
around do |example|
Timecop.freeze(now) do
example.run
end
Timecop.return
end
context "with a log in the 22/23 collection year" do context "with a log in the 22/23 collection year" do
let(:now) { Time.zone.local(2023, 1, 1) } let(:saledate) { Time.zone.local(2023, 1, 1) }
it "adds an error for type 2, equity below min with the correct percentage" do it "adds an error for type 2, equity below min with the correct percentage" do
record.type = 2 record.type = 2
@ -397,7 +390,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
context "with a log in 23/24 collection year" do context "with a log in 23/24 collection year" do
let(:now) { Time.zone.local(2024, 1, 1) } let(:saledate) { Time.zone.local(2024, 1, 1) }
it "adds an error for type 2, equity below min with the correct percentage" do it "adds an error for type 2, equity below min with the correct percentage" do
record.type = 2 record.type = 2
@ -433,19 +426,10 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
describe "#validate_equity_less_than_staircase_difference" do describe "#validate_equity_less_than_staircase_difference" do
let(:record) { FactoryBot.create(:sales_log, saledate: now) } let(:record) { FactoryBot.build(:sales_log, saledate:) }
around do |example|
Timecop.freeze(now) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
context "with a log in the 23/24 collection year" do context "with a log in the 23/24 collection year" do
let(:now) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
it "does not add an error" do it "does not add an error" do
record.stairbought = 2 record.stairbought = 2
@ -457,7 +441,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
context "with a log in 24/25 collection year" do context "with a log in 24/25 collection year" do
let(:now) { Time.zone.local(2024, 4, 1) } let(:saledate) { Time.zone.local(2024, 4, 1) }
it "adds errors if equity is more than stairowned - stairbought for joint purchase" do it "adds errors if equity is more than stairowned - stairbought for joint purchase" do
record.stairbought = 2 record.stairbought = 2

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

@ -4,8 +4,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do
subject(:household_validator) { validator_class.new } subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } } let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } }
let(:record) { build(:sales_log, saledate: log_date) } let(:record) { build(:sales_log, saledate:) }
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
describe "#validate_partner_count" do describe "#validate_partner_count" do
it "validates that only 1 partner exists" do it "validates that only 1 partner exists" do
@ -28,18 +28,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
describe "#validate_person_age_matches_relationship" do describe "#validate_person_age_matches_relationship" do
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
context "when the household contains a person under 16" do context "when the household contains a person under 16" do
it "expects that person is a child of the tenant" do it "expects that person is a child of the tenant" do
@ -73,7 +63,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:saledate) { Time.zone.local(2024, 4, 1) }
it "does not add error if person under 16 is a partner" do it "does not add error if person under 16 is a partner" do
record.age2 = 14 record.age2 = 14
@ -94,18 +84,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
describe "#validate_person_age_matches_economic_status" do describe "#validate_person_age_matches_economic_status" do
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
it "validates that person's economic status must be Child" do it "validates that person's economic status must be Child" do
record.age2 = 14 record.age2 = 14
@ -137,7 +117,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:saledate) { Time.zone.local(2024, 4, 1) }
it "does not run the validation" do it "does not run the validation" do
record.age2 = 14 record.age2 = 14
@ -152,18 +132,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
describe "#validate_child_12_years_younger" do describe "#validate_child_12_years_younger" do
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
it "validates the child is at least 12 years younger than buyer 1" do it "validates the child is at least 12 years younger than buyer 1" do
record.age1 = 30 record.age1 = 30
@ -190,7 +160,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:saledate) { Time.zone.local(2024, 4, 1) }
it "does not validate that child is at least 12 year younger than buyer" do it "does not validate that child is at least 12 year younger than buyer" do
record.age1 = 20 record.age1 = 20
@ -205,18 +175,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
describe "#validate_person_age_and_relationship_matches_economic_status" do describe "#validate_person_age_and_relationship_matches_economic_status" do
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
it "does not add an error for a person aged 16-19 who is a student but not a child of the buyer" do it "does not add an error for a person aged 16-19 who is a student but not a child of the buyer" do
record.age2 = 18 record.age2 = 18
@ -266,7 +226,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:saledate) { Time.zone.local(2024, 4, 1) }
context "when the household contains a tenant’s child between the ages of 16 and 19" do context "when the household contains a tenant’s child between the ages of 16 and 19" do
it "does not add an error" do it "does not add an error" do
@ -316,7 +276,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
describe "validating fields about buyers living in the property" do describe "validating fields about buyers living in the property" do
let(:sales_log) { FactoryBot.create(:sales_log, :outright_sale_setup_complete, saledate: log_date, noint: 1, companybuy: 2, buylivein:, jointpur:, jointmore:, buy1livein:) } let(:sales_log) { FactoryBot.create(:sales_log, :outright_sale_setup_complete, saledate:, noint: 1, companybuy: 2, buylivein:, jointpur:, jointmore:, buy1livein:) }
context "when buyers will live in the property and the sale is a joint purchase" do context "when buyers will live in the property and the sale is a joint purchase" do
let(:buylivein) { 1 } let(:buylivein) { 1 }
@ -349,7 +309,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
it "triggers a validation if buyer two will also not live in the property" do it "triggers a validation if buyer two will also not live in the property" do
sales_log.buy2livein = 2 sales_log.buy2livein = 2
@ -377,21 +337,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
describe "#validate_buyer1_previous_tenure" do describe "#validate_buyer1_previous_tenure" do
let(:record) { build(:sales_log) } let(:saledate) { Time.zone.local(2024, 4, 4) }
let(:record) { build(:sales_log, saledate:, ownershipsch: 2) }
let(:now) { Time.zone.local(2024, 4, 4) }
before do
Timecop.freeze(now)
Singleton.__init__(FormHandler)
record.ownershipsch = 2
record.saledate = now
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "adds an error when previous tenure is not valid" do it "adds an error when previous tenure is not valid" do
[3, 4, 5, 6, 7, 9, 0].each do |prevten| [3, 4, 5, 6, 7, 9, 0].each do |prevten|
@ -437,7 +384,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
context "with 23/24 logs" do context "with 23/24 logs" do
let(:now) { Time.zone.local(2023, 4, 4) } let(:saledate) { Time.zone.local(2023, 4, 4) }
it "does not add an error for outright sale" do it "does not add an error for outright sale" do
record.ownershipsch = 2 record.ownershipsch = 2
@ -452,18 +399,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
describe "#validate_buyer_not_child" do describe "#validate_buyer_not_child" do
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with 2023 logs" do context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
it "does not add an error if either buyer is a child" do it "does not add an error if either buyer is a child" do
record.jointpur = 1 record.jointpur = 1
@ -476,7 +413,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:saledate) { Time.zone.local(2024, 4, 1) }
it "validates buyer 1 isn't a child" do it "validates buyer 1 isn't a child" do
record.ecstat1 = 9 record.ecstat1 = 9

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

@ -725,17 +725,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
describe "#validate_stairbought" do describe "#validate_stairbought" do
let(:now) { Time.zone.local(2024, 4, 4) } let(:saledate) { Time.zone.local(2024, 4, 4) }
before do
Timecop.freeze(now)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
[ [
["Shared Ownership (new model lease)", 30, 90], ["Shared Ownership (new model lease)", 30, 90],
@ -748,7 +738,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
["Older Persons Shared Ownership", 24, 50], ["Older Persons Shared Ownership", 24, 50],
].each do |label, type, max| ].each do |label, type, max|
context "when ownership type is #{label}" do context "when ownership type is #{label}" do
let(:record) { build(:sales_log, ownershipsch: 1, type:, saledate: now) } let(:record) { build(:sales_log, ownershipsch: 1, type:, saledate:) }
it "does not add an error if stairbought is under #{max}%" do it "does not add an error if stairbought is under #{max}%" do
record.stairbought = max - 1 record.stairbought = max - 1
@ -781,8 +771,8 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end end
context "when the collection year is before 2024" do context "when the collection year is before 2024" do
let(:record) { build(:sales_log, ownershipsch: 1, type: 24, saledate: now, stairbought: 90) } let(:record) { build(:sales_log, ownershipsch: 1, type: 24, saledate:, stairbought: 90) }
let(:now) { Time.zone.local(2023, 4, 4) } let(:saledate) { Time.zone.local(2023, 4, 4) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_stairbought(record) sale_information_validator.validate_stairbought(record)
@ -793,15 +783,8 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
describe "#validate_discount_and_value" do describe "#validate_discount_and_value" do
let(:record) { FactoryBot.build(:sales_log, value: 200_000, discount: 50, ownershipsch: 2, type: 9, saledate: now) } let(:record) { FactoryBot.build(:sales_log, value: 200_000, discount: 50, ownershipsch: 2, type: 9, saledate:) }
let(:now) { Time.zone.local(2024, 4, 1) } let(:saledate) { Time.zone.local(2024, 4, 1) }
around do |example|
Timecop.freeze(now) do
example.run
end
Timecop.return
end
context "with a log in the 24/25 collection year" do context "with a log in the 24/25 collection year" do
context "when in London" do context "when in London" do
@ -870,19 +853,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
describe "#validate_non_staircasing_mortgage" do describe "#validate_non_staircasing_mortgage" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate:) }
around do |example|
Timecop.freeze(now) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
context "with a log in the 24/25 collection year" do context "with a log in the 24/25 collection year" do
let(:now) { Time.zone.local(2024, 4, 4) } let(:saledate) { Time.zone.local(2024, 4, 4) }
context "when MORTGAGE + DEPOSIT does not equal VALUE * EQUITY/100 " do context "when MORTGAGE + DEPOSIT does not equal VALUE * EQUITY/100 " do
context "and it is not a staircase transaction" do context "and it is not a staircase transaction" do
@ -952,7 +926,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when MORTGAGE + DEPOSIT equals VALUE * EQUITY/100" do context "when MORTGAGE + DEPOSIT equals VALUE * EQUITY/100" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record) sale_information_validator.validate_non_staircasing_mortgage(record)
@ -966,7 +940,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when MORTGAGE + DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do context "when MORTGAGE + DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 50_000, value: 120_001, equity: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 50_000, value: 120_001, equity: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record) sale_information_validator.validate_non_staircasing_mortgage(record)
@ -1052,7 +1026,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when DEPOSIT equals VALUE * EQUITY/100" do context "when DEPOSIT equals VALUE * EQUITY/100" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record) sale_information_validator.validate_non_staircasing_mortgage(record)
@ -1066,7 +1040,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do context "when DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_001, equity: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_001, equity: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record) sale_information_validator.validate_non_staircasing_mortgage(record)
@ -1082,8 +1056,8 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when it is a 2023 log" do context "when it is a 2023 log" do
let(:now) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_non_staircasing_mortgage(record) sale_information_validator.validate_non_staircasing_mortgage(record)
@ -1098,19 +1072,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
describe "#validate_staircasing_mortgage" do describe "#validate_staircasing_mortgage" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate:) }
around do |example|
Timecop.freeze(now) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
context "with a log in the 24/25 collection year" do context "with a log in the 24/25 collection year" do
let(:now) { Time.zone.local(2024, 4, 4) } let(:saledate) { Time.zone.local(2024, 4, 4) }
context "when MORTGAGE + DEPOSIT does not equal STAIRBOUGHT/100 * VALUE" do context "when MORTGAGE + DEPOSIT does not equal STAIRBOUGHT/100 * VALUE" do
context "and it is a staircase transaction" do context "and it is a staircase transaction" do
@ -1180,7 +1145,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when MORTGAGE + DEPOSIT equals STAIRBOUGHT/100 * VALUE" do context "when MORTGAGE + DEPOSIT equals STAIRBOUGHT/100 * VALUE" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_staircasing_mortgage(record) sale_information_validator.validate_staircasing_mortgage(record)
@ -1194,7 +1159,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when MORTGAGE + DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do context "when MORTGAGE + DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_staircasing_mortgage(record) sale_information_validator.validate_staircasing_mortgage(record)
@ -1209,8 +1174,8 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when it is a 2023 log" do context "when it is a 2023 log" do
let(:now) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_staircasing_mortgage(record) sale_information_validator.validate_staircasing_mortgage(record)
@ -1225,7 +1190,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
context "when mortgage is not used" do context "when mortgage is not used" do
context "with a log in the 24/25 collection year" do context "with a log in the 24/25 collection year" do
let(:now) { Time.zone.local(2024, 4, 4) } let(:saledate) { Time.zone.local(2024, 4, 4) }
before do before do
record.mortgageused = 2 record.mortgageused = 2
@ -1299,7 +1264,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when DEPOSIT equals STAIRBOUGHT/100 * VALUE" do context "when DEPOSIT equals STAIRBOUGHT/100 * VALUE" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_staircasing_mortgage(record) sale_information_validator.validate_staircasing_mortgage(record)
@ -1313,7 +1278,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do context "when DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do
let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_staircasing_mortgage(record) sale_information_validator.validate_staircasing_mortgage(record)
@ -1328,8 +1293,8 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when it is a 2023 log" do context "when it is a 2023 log" do
let(:now) { Time.zone.local(2023, 4, 1) } let(:saledate) { Time.zone.local(2023, 4, 1) }
let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate: now) } let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate:) }
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_staircasing_mortgage(record) sale_information_validator.validate_staircasing_mortgage(record)

46
spec/models/validations/sales/setup_validations_spec.rb

@ -7,15 +7,6 @@ RSpec.describe Validations::Sales::SetupValidations do
describe "#validate_saledate_collection_year" do describe "#validate_saledate_collection_year" do
context "with sales_in_crossover_period == false" do context "with sales_in_crossover_period == false" do
before do
Timecop.freeze(Time.zone.local(2023, 1, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
context "when saledate is blank" do context "when saledate is blank" do
let(:record) { build(:sales_log, saledate: nil) } let(:record) { build(:sales_log, saledate: nil) }
@ -26,9 +17,13 @@ RSpec.describe Validations::Sales::SetupValidations do
end end
end end
context "when saledate is in the 22/23 collection year" do context "when saledate is in the open collection year" do
let(:record) { build(:sales_log, saledate: Time.zone.local(2023, 1, 1)) } let(:record) { build(:sales_log, saledate: Time.zone.local(2023, 1, 1)) }
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 1, 10))
end
it "does not add an error" do it "does not add an error" do
setup_validator.validate_saledate_collection_year(record) setup_validator.validate_saledate_collection_year(record)
@ -36,9 +31,13 @@ RSpec.describe Validations::Sales::SetupValidations do
end end
end end
context "when saledate is before the 22/23 collection year" do context "when saledate is before the open collection year" do
let(:record) { build(:sales_log, saledate: Time.zone.local(2020, 1, 1)) } let(:record) { build(:sales_log, saledate: Time.zone.local(2020, 1, 1)) }
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 1, 10))
end
it "adds error" do it "adds error" do
setup_validator.validate_saledate_collection_year(record) setup_validator.validate_saledate_collection_year(record)
@ -46,9 +45,13 @@ RSpec.describe Validations::Sales::SetupValidations do
end end
end end
context "when saledate is after the 22/23 collection year" do context "when saledate is after the open collection year" do
let(:record) { build(:sales_log, saledate: Time.zone.local(2025, 4, 1)) } let(:record) { build(:sales_log, saledate: Time.zone.local(2025, 4, 1)) }
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 1, 10))
end
it "adds error" do it "adds error" do
setup_validator.validate_saledate_collection_year(record) setup_validator.validate_saledate_collection_year(record)
@ -58,14 +61,6 @@ RSpec.describe Validations::Sales::SetupValidations do
end end
context "with sales_in_crossover_period == true" do context "with sales_in_crossover_period == true" do
around do |example|
Timecop.freeze(Time.zone.local(2024, 5, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
end
context "when saledate is blank" do context "when saledate is blank" do
let(:record) { build(:sales_log, saledate: nil) } let(:record) { build(:sales_log, saledate: nil) }
@ -191,12 +186,6 @@ RSpec.describe Validations::Sales::SetupValidations do
let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org") } let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org") }
let(:merged_organisation) { create(:organisation, name: "Merged org") } let(:merged_organisation) { create(:organisation, name: "Merged org") }
around do |example|
Timecop.freeze(Time.zone.local(2023, 5, 1))
example.run
Timecop.return
end
before do before do
merged_organisation.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2)) merged_organisation.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2))
end end
@ -249,11 +238,8 @@ RSpec.describe Validations::Sales::SetupValidations do
let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org") } let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org") }
let(:merged_organisation) { create(:organisation, name: "Merged org") } let(:merged_organisation) { create(:organisation, name: "Merged org") }
around do |example| before do
Timecop.freeze(Time.zone.local(2023, 5, 1))
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation:) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation:)
example.run
Timecop.return
end end
context "and owning organisation is no longer active" do context "and owning organisation is no longer active" do

60
spec/models/validations/setup_validations_spec.rb

@ -143,7 +143,7 @@ RSpec.describe Validations::SetupValidations do
context "when attempted startdate is more than 14 days from the current date" do context "when attempted startdate is more than 14 days from the current date" do
before do before do
Timecop.freeze(2024, 3, 1) allow(Time).to receive(:now).and_return(Time.zone.local(2024, 3, 1))
end end
it "adds an error to startdate" do it "adds an error to startdate" do
@ -164,18 +164,13 @@ RSpec.describe Validations::SetupValidations do
end end
context "when organisations were merged" do context "when organisations were merged" do
around do |example|
Timecop.freeze(Time.zone.local(2023, 5, 1))
example.run
Timecop.return
end
let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 1, 30, 4, 5, 6), available_from: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") } let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 1, 30, 4, 5, 6), available_from: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") }
let(:absorbing_organisation_2) { create(:organisation, created_at: Time.zone.local(2023, 1, 30), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org 2") } let(:absorbing_organisation_2) { create(:organisation, created_at: Time.zone.local(2023, 1, 30), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org 2") }
let(:merged_organisation) { create(:organisation, name: "Merged org") } let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:merged_organisation_2) { create(:organisation, name: "Merged org 2") } let(:merged_organisation_2) { create(:organisation, name: "Merged org 2") }
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1))
merged_organisation.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2)) merged_organisation.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2))
merged_organisation_2.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2)) merged_organisation_2.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2))
end end
@ -431,9 +426,8 @@ RSpec.describe Validations::SetupValidations do
before do before do
create(:location, scheme:) create(:location, scheme:)
Timecop.freeze(Time.zone.local(2023, 11, 10)) scheme_deactivation_period = build(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), scheme:) scheme_deactivation_period.save!(validate: false)
Timecop.return
scheme.reload scheme.reload
end end
@ -461,9 +455,8 @@ RSpec.describe Validations::SetupValidations do
before do before do
create(:location, scheme:) create(:location, scheme:)
Timecop.freeze(Time.zone.local(2023, 11, 10)) scheme_deactivation_period = build(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) scheme_deactivation_period.save!(validate: false)
Timecop.return
scheme.reload scheme.reload
end end
@ -491,11 +484,12 @@ RSpec.describe Validations::SetupValidations do
before do before do
create(:location, scheme:) create(:location, scheme:)
Timecop.freeze(Time.zone.local(2023, 11, 10)) scheme_deactivation_period = build(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) scheme_deactivation_period_2 = build(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) scheme_deactivation_period_3 = build(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) scheme_deactivation_period.save!(validate: false)
Timecop.return scheme_deactivation_period_2.save!(validate: false)
scheme_deactivation_period_3.save!(validate: false)
scheme.reload scheme.reload
end end
@ -525,9 +519,8 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10)) location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) location_deactivation_period.save!(validate: false)
Timecop.return
location.reload location.reload
end end
@ -555,9 +548,8 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10)) location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) location_deactivation_period.save!(validate: false)
Timecop.return
location.reload location.reload
end end
@ -585,11 +577,12 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10)) location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) location_deactivation_period_2 = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) location_deactivation_period_3 = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:) location_deactivation_period.save!(validate: false)
Timecop.return location_deactivation_period_2.save!(validate: false)
location_deactivation_period_3.save!(validate: false)
location.reload location.reload
end end
@ -719,11 +712,10 @@ RSpec.describe Validations::SetupValidations do
let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1, 4, 5, 6), available_from: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") } let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1, 4, 5, 6), available_from: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") }
let(:merged_organisation) { create(:organisation, name: "Merged org") } let(:merged_organisation) { create(:organisation, name: "Merged org") }
around do |example| before do
Timecop.freeze(Time.zone.local(2023, 5, 1)) merged_organisation.merge_date = Time.zone.local(2023, 2, 2)
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation:) merged_organisation.absorbing_organisation = absorbing_organisation
example.run merged_organisation.save!(validate: false)
Timecop.return
end end
context "and owning organisation is no longer active" do context "and owning organisation is no longer active" do

79
spec/models/validations/soft_validations_spec.rb

@ -2,16 +2,7 @@ require "rails_helper"
RSpec.describe Validations::SoftValidations do RSpec.describe Validations::SoftValidations do
let(:organisation) { FactoryBot.create(:organisation, provider_type: "PRP") } let(:organisation) { FactoryBot.create(:organisation, provider_type: "PRP") }
let(:record) { FactoryBot.create(:lettings_log, owning_organisation: organisation) } let(:record) { FactoryBot.build(:lettings_log, owning_organisation: organisation) }
before do
Timecop.freeze(Time.zone.local(2021, 10, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
describe "rent min max validations" do describe "rent min max validations" do
before do before do
@ -32,7 +23,7 @@ RSpec.describe Validations::SoftValidations do
record.rent_type = 0 record.rent_type = 0
record.beds = 1 record.beds = 1
record.period = 1 record.period = 1
record.startdate = Time.zone.today record.startdate = Time.zone.local(2021, 10, 10)
end end
context "when validating soft min" do context "when validating soft min" do
@ -84,7 +75,8 @@ RSpec.describe Validations::SoftValidations do
describe "retirement soft validations" do describe "retirement soft validations" do
before do before do
record.update!(age1:, ecstat1:) record.age1 = age1
record.ecstat1 = ecstat1
end end
context "when the tenant is under the expected retirement age" do context "when the tenant is under the expected retirement age" do
@ -163,35 +155,57 @@ RSpec.describe Validations::SoftValidations do
describe "pregnancy soft validations" do describe "pregnancy soft validations" do
context "when there are no female tenants" do context "when there are no female tenants" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.update!(age1: 43, sex1: "M", preg_occ: 1, hhmemb: 1, age1_known: 0) record.age1 = 43
record.sex1 = "M"
record.preg_occ = 1
record.hhmemb = 1
record.age1_known = 0
expect(record.no_females_in_a_pregnant_household?).to be true expect(record.no_females_in_a_pregnant_household?).to be true
end end
end end
context "when there are no female tenants and age of other tenants is unknown" do context "when there are no female tenants and age of other tenants is unknown" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.update!(sex1: "M", preg_occ: 1, hhmemb: 1, age1_known: 1) record.sex1 = "M"
record.preg_occ = 1
record.hhmemb = 1
record.age1_known = 1
expect(record.no_females_in_a_pregnant_household?).to be true expect(record.no_females_in_a_pregnant_household?).to be true
end end
end end
context "when female tenants are under 16" do context "when female tenants are under 16" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.update!(age2: 14, sex2: "F", preg_occ: 1, hhmemb: 2, details_known_2: 0, age2_known: 0, age1: 18, sex1: "M", age1_known: 0) record.age2 = 14
record.sex2 = "F"
record.preg_occ = 1
record.hhmemb = 2
record.details_known_2 = 0
record.age2_known = 0
record.age1 = 18
record.sex1 = "M"
record.age1_known = 0
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true
end end
end end
context "when female tenants are over 50" do context "when female tenants are over 50" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.update!(age1: 54, sex1: "F", preg_occ: 1, hhmemb: 1, age1_known: 0) record.age1 = 54
record.sex1 = "F"
record.preg_occ = 1
record.hhmemb = 1
record.age1_known = 0
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true
end end
end end
context "when female tenants are outside of soft validation ranges" do context "when female tenants are outside of soft validation ranges" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.update!(age1: 44, sex1: "F", preg_occ: 1, hhmemb: 1) record.age1 = 44
record.sex1 = "F"
record.preg_occ = 1
record.hhmemb = 1
expect(record.no_females_in_a_pregnant_household?).to be false expect(record.no_females_in_a_pregnant_household?).to be false
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false
end end
@ -199,7 +213,8 @@ RSpec.describe Validations::SoftValidations do
context "when the information about the tenants is not given" do context "when the information about the tenants is not given" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.update!(preg_occ: 1, hhmemb: 2) record.preg_occ = 1
record.hhmemb = 2
expect(record.no_females_in_a_pregnant_household?).to be false expect(record.no_females_in_a_pregnant_household?).to be false
expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false
end end
@ -207,48 +222,36 @@ RSpec.describe Validations::SoftValidations do
end end
describe "major repairs date soft validations" do describe "major repairs date soft validations" do
before do
Timecop.freeze(Time.zone.local(2022, 2, 1))
end
after do
Timecop.unfreeze
end
context "when the major repairs date is within 10 years of the tenancy start date" do context "when the major repairs date is within 10 years of the tenancy start date" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2013, 2, 1)) record.startdate = Time.zone.local(2022, 2, 1)
record.mrcdate = Time.zone.local(2013, 2, 1)
expect(record.major_repairs_date_in_soft_range?).to be true expect(record.major_repairs_date_in_soft_range?).to be true
end end
end end
context "when the major repairs date is less than 2 years before the tenancy start date" do context "when the major repairs date is less than 2 years before the tenancy start date" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2021, 2, 1)) record.startdate = Time.zone.local(2022, 2, 1)
record.mrcdate = Time.zone.local(2021, 2, 1)
expect(record.major_repairs_date_in_soft_range?).to be false expect(record.major_repairs_date_in_soft_range?).to be false
end end
end end
end end
describe "void date soft validations" do describe "void date soft validations" do
before do
Timecop.freeze(Time.zone.local(2022, 2, 1))
end
after do
Timecop.unfreeze
end
context "when the void date is within 10 years of the tenancy start date" do context "when the void date is within 10 years of the tenancy start date" do
it "shows the interruption screen" do it "shows the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), voiddate: Time.zone.local(2013, 2, 1)) record.startdate = Time.zone.local(2022, 2, 1)
record.voiddate = Time.zone.local(2013, 2, 1)
expect(record.voiddate_in_soft_range?).to be true expect(record.voiddate_in_soft_range?).to be true
end end
end end
context "when the void date is less than 2 years before the tenancy start date" do context "when the void date is less than 2 years before the tenancy start date" do
it "does not show the interruption screen" do it "does not show the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), voiddate: Time.zone.local(2021, 2, 1)) record.startdate = Time.zone.local(2022, 2, 1)
record.voiddate = Time.zone.local(2021, 2, 1)
expect(record.voiddate_in_soft_range?).to be false expect(record.voiddate_in_soft_range?).to be false
end end
end end

Loading…
Cancel
Save