Browse Source

LaSaleRange validations bug (#1481)

pull/1511/head
Jack 2 years ago committed by GitHub
parent
commit
07043f59b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/la_sale_range.rb
  2. 4
      app/models/sales_log.rb
  3. 6
      app/models/validations/sales/soft_validations.rb
  4. 7
      app/models/validations/soft_validations.rb
  5. 26
      spec/models/lettings_log_spec.rb
  6. 26
      spec/models/sales_log_spec.rb

1
app/models/la_sale_range.rb

@ -1,2 +1,3 @@
class LaSaleRange < ApplicationRecord class LaSaleRange < ApplicationRecord
MAX_BEDS = 4
end end

4
app/models/sales_log.rb

@ -353,4 +353,8 @@ class SalesLog < Log
mortgage_amount = mortgage || 0 mortgage_amount = mortgage || 0
mortgage_amount + deposit + grant_amount mortgage_amount + deposit + grant_amount
end end
def beds_for_la_sale_range
beds.nil? ? nil : [beds, LaSaleRange::MAX_BEDS].min
end
end end

6
app/models/validations/sales/soft_validations.rb

@ -126,6 +126,10 @@ module Validations::Sales::SoftValidations
private private
def sale_range def sale_range
LaSaleRange.find_by(start_year: collection_start_year, la:, bedrooms: beds) LaSaleRange.find_by(
start_year: collection_start_year,
la:,
bedrooms: beds_for_la_sale_range,
)
end end
end end

7
app/models/validations/soft_validations.rb

@ -28,7 +28,12 @@ module Validations::SoftValidations
def rent_in_soft_min_range? def rent_in_soft_min_range?
return unless brent && weekly_value(brent) && startdate return unless brent && weekly_value(brent) && startdate
rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds: beds_for_la_rent_range, lettype: get_lettype) rent_range = LaRentRange.find_by(
start_year: collection_start_year,
la:,
beds: beds_for_la_rent_range,
lettype: get_lettype,
)
rent_range.present? && weekly_value(brent).between?(rent_range.hard_min, rent_range.soft_min) rent_range.present? && weekly_value(brent).between?(rent_range.hard_min, rent_range.soft_min)
end end

26
spec/models/lettings_log_spec.rb

@ -3086,5 +3086,31 @@ RSpec.describe LettingsLog do
end end
end end
end end
describe "#beds_for_la_rent_range" do
context "when beds nil" do
let(:lettings_log) { build(:lettings_log, beds: nil) }
it "returns nil" do
expect(lettings_log.beds_for_la_rent_range).to be_nil
end
end
context "when beds <= 4" do
let(:lettings_log) { build(:lettings_log, beds: 4) }
it "returns number of beds" do
expect(lettings_log.beds_for_la_rent_range).to eq(4)
end
end
context "when beds > 4" do
let(:lettings_log) { build(:lettings_log, beds: 40) }
it "returns max number of beds" do
expect(lettings_log.beds_for_la_rent_range).to eq(4)
end
end
end
end end
# rubocop:enable RSpec/AnyInstance # rubocop:enable RSpec/AnyInstance

26
spec/models/sales_log_spec.rb

@ -579,5 +579,31 @@ RSpec.describe SalesLog, type: :model do
end end
end end
end end
describe "#beds_for_la_sale_range" do
context "when beds nil" do
let(:sales_log) { build(:sales_log, beds: nil) }
it "returns nil" do
expect(sales_log.beds_for_la_sale_range).to be_nil
end
end
context "when beds <= 4" do
let(:sales_log) { build(:sales_log, beds: 4) }
it "returns number of beds" do
expect(sales_log.beds_for_la_sale_range).to eq(4)
end
end
context "when beds > 4" do
let(:sales_log) { build(:sales_log, beds: 40) }
it "returns max number of beds" do
expect(sales_log.beds_for_la_sale_range).to eq(4)
end
end
end
end end
# rubocop:enable RSpec/AnyInstance # rubocop:enable RSpec/AnyInstance

Loading…
Cancel
Save