Browse Source

reset rent values when rent validation triggers

pull/1078/head
Kat 4 years ago
parent
commit
6e1ef998de
  1. 9
      app/models/lettings_log.rb
  2. 72
      spec/models/lettings_log_spec.rb

9
app/models/lettings_log.rb

@ -18,6 +18,7 @@ class LettingsLog < Log
include Validations::SoftValidations include Validations::SoftValidations
include DerivedVariables::LettingsLogVariables include DerivedVariables::LettingsLogVariables
include Validations::DateValidations include Validations::DateValidations
include Validations::FinancialValidations
has_paper_trail has_paper_trail
@ -548,6 +549,14 @@ private
validate_property_major_repairs(self) validate_property_major_repairs(self)
self.mrcdate = nil if errors[:mrcdate].present? self.mrcdate = nil if errors[:mrcdate].present?
validate_rent_range(self)
if errors[:brent].present?
self.brent = nil
self.scharge = nil
self.pscharge = nil
self.supcharg = nil
end
errors.clear errors.clear
end end

72
spec/models/lettings_log_spec.rb

@ -2005,6 +2005,8 @@ RSpec.describe LettingsLog do
end end
context "when the log is unresolved" do context "when the log is unresolved" do
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: created_by_user.organisation) }
let(:location) { FactoryBot.create(:location, location_code: "E07000223", scheme:) }
let(:lettings_log) do let(:lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
@ -2014,10 +2016,33 @@ RSpec.describe LettingsLog do
startdate: Time.zone.tomorrow, startdate: Time.zone.tomorrow,
voiddate: Time.zone.today, voiddate: Time.zone.today,
mrcdate: Time.zone.today, mrcdate: Time.zone.today,
rent_type: 2,
needstype: 2,
period: 1,
beds: 1,
brent: 7.17,
scharge: 1,
pscharge: 1,
supcharg: 1,
created_by: created_by_user,
unresolved: true, unresolved: true,
) )
end end
before do
LaRentRange.create!(
ranges_rent_id: "1",
la: "E07000223",
beds: 0,
lettype: 8,
soft_min: 12.41,
soft_max: 89.54,
hard_min: 10.87,
hard_max: 100.99,
start_year: lettings_log.startdate.year,
)
end
context "and the new startdate triggers void date validation" do context "and the new startdate triggers void date validation" do
it "clears void date value" do it "clears void date value" do
lettings_log.update!(startdate: Time.zone.yesterday) lettings_log.update!(startdate: Time.zone.yesterday)
@ -2035,9 +2060,23 @@ RSpec.describe LettingsLog do
expect(lettings_log.mrcdate).to eq(nil) expect(lettings_log.mrcdate).to eq(nil)
end end
end end
context "and the new location triggers the rent range validation" do
it "clears rent values" do
lettings_log.update!(location:, scheme:)
lettings_log.reload
expect(lettings_log.location).to eq(location)
expect(lettings_log.brent).to eq(nil)
expect(lettings_log.scharge).to eq(nil)
expect(lettings_log.pscharge).to eq(nil)
expect(lettings_log.supcharg).to eq(nil)
end
end
end end
context "when the log is resolved" do context "when the log is resolved" do
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: created_by_user.organisation) }
let(:location) { FactoryBot.create(:location, location_code: "E07000223", scheme:) }
let(:lettings_log) do let(:lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
@ -2047,10 +2086,33 @@ RSpec.describe LettingsLog do
startdate: Time.zone.tomorrow, startdate: Time.zone.tomorrow,
voiddate: Time.zone.today, voiddate: Time.zone.today,
mrcdate: Time.zone.today, mrcdate: Time.zone.today,
rent_type: 2,
needstype: 2,
period: 1,
beds: 1,
brent: 7.17,
scharge: 1,
pscharge: 1,
supcharg: 1,
created_by: created_by_user,
unresolved: nil, unresolved: nil,
) )
end end
before do
LaRentRange.create!(
ranges_rent_id: "1",
la: "E07000223",
beds: 0,
lettype: 8,
soft_min: 12.41,
soft_max: 89.54,
hard_min: 10.87,
hard_max: 100.99,
start_year: lettings_log.startdate.year,
)
end
context "and the new startdate triggers void date validation" do context "and the new startdate triggers void date validation" do
it "doesn't clear void date value" do it "doesn't clear void date value" do
expect { lettings_log.update!(startdate: Time.zone.yesterday) }.to raise_error(ActiveRecord::RecordInvalid, /Enter a void date that is before the tenancy start date/) expect { lettings_log.update!(startdate: Time.zone.yesterday) }.to raise_error(ActiveRecord::RecordInvalid, /Enter a void date that is before the tenancy start date/)
@ -2066,6 +2128,16 @@ RSpec.describe LettingsLog do
expect(lettings_log.mrcdate).to eq(Time.zone.today) expect(lettings_log.mrcdate).to eq(Time.zone.today)
end end
end end
context "and the new location triggers brent validation" do
it "doesn't clear rent values" do
expect { lettings_log.update!(location:, scheme:) }.to raise_error(ActiveRecord::RecordInvalid, /Rent is below the absolute minimum expected/)
expect(lettings_log.brent).to eq(7.17)
expect(lettings_log.scharge).to eq(1)
expect(lettings_log.pscharge).to eq(1)
expect(lettings_log.supcharg).to eq(1)
end
end
end end
end end

Loading…
Cancel
Save