Browse Source

feat: more saledate -> exdate fixing

pull/1225/head
natdeanlewissoftwire 2 years ago
parent
commit
a1681d0a7f
  1. 2
      app/models/validations/sales/sale_information_validations.rb
  2. 6
      app/models/validations/sales/soft_validations.rb
  3. 34
      spec/models/validations/sales/sale_information_validations_spec.rb
  4. 32
      spec/models/validations/sales/soft_validations_spec.rb

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

@ -7,7 +7,7 @@ module Validations::Sales::SaleInformationValidations
end
end
def validate_pratical_completion_date_before_saledate(record)
def validate_pratical_completion_date_before_exdate(record)
return if record.exdate.blank? || record.hodate.blank?
unless record.exdate > record.hodate

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

@ -37,10 +37,10 @@ module Validations::Sales::SoftValidations
deposit > savings * 4 / 3
end
def hodate_3_years_or_more_saledate?
return unless hodate && saledate
def hodate_3_years_or_more_exdate?
return unless hodate && exdate
((saledate.to_date - hodate.to_date).to_i / 365) >= 3
((exdate.to_date - hodate.to_date).to_i / 365) >= 3
end
def purchase_price_out_of_expected_range?

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

@ -47,62 +47,62 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
describe "#validate_pratical_completion_date_before_saledate" do
describe "#validate_pratical_completion_date_before_exdate" 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_pratical_completion_date_before_exdate(record)
expect(record.errors).not_to be_present
end
end
context "when saledate blank" do
let(:record) { build(:sales_log, saledate: nil) }
context "when exdate blank" do
let(:record) { build(:sales_log, exdate: nil) }
it "does not add an error" do
sale_information_validator.validate_pratical_completion_date_before_saledate(record)
sale_information_validator.validate_pratical_completion_date_before_exdate(record)
expect(record.errors).not_to be_present
end
end
context "when saledate and hodate blank" do
let(:record) { build(:sales_log, hodate: nil, saledate: nil) }
context "when exdate and hodate blank" do
let(:record) { build(:sales_log, hodate: nil, exdate: nil) }
it "does not add an error" do
sale_information_validator.validate_pratical_completion_date_before_saledate(record)
sale_information_validator.validate_pratical_completion_date_before_exdate(record)
expect(record.errors).not_to be_present
end
end
context "when hodate before saledate" do
let(:record) { build(:sales_log, hodate: 2.months.ago, saledate: 1.month.ago) }
context "when hodate before exdate" do
let(:record) { build(:sales_log, hodate: 2.months.ago, exdate: 1.month.ago) }
it "does not add the error" do
sale_information_validator.validate_pratical_completion_date_before_saledate(record)
sale_information_validator.validate_pratical_completion_date_before_exdate(record)
expect(record.errors).not_to be_present
end
end
context "when hodate after saledate" do
let(:record) { build(:sales_log, hodate: 1.month.ago, saledate: 2.months.ago) }
context "when hodate after exdate" do
let(:record) { build(:sales_log, hodate: 1.month.ago, exdate: 2.months.ago) }
it "adds error" do
sale_information_validator.validate_pratical_completion_date_before_saledate(record)
sale_information_validator.validate_pratical_completion_date_before_exdate(record)
expect(record.errors[:hodate]).to be_present
end
end
context "when hodate == saledate" do
let(:record) { build(:sales_log, hodate: Time.zone.parse("2023-07-01"), saledate: Time.zone.parse("2023-07-01")) }
context "when hodate == exdate" do
let(:record) { build(:sales_log, hodate: Time.zone.parse("2023-07-01"), exdate: 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_pratical_completion_date_before_exdate(record)
expect(record.errors[:hodate]).to be_present
end

32
spec/models/validations/sales/soft_validations_spec.rb

@ -256,40 +256,40 @@ RSpec.describe Validations::Sales::SoftValidations do
end
end
describe "hodate_more_than_3_years_before_saledate" do
describe "hodate_more_than_3_years_before_exdate" do
it "when hodate not set" do
record.saledate = Time.zone.now
record.exdate = Time.zone.now
record.hodate = nil
expect(record).not_to be_hodate_3_years_or_more_saledate
expect(record).not_to be_hodate_3_years_or_more_exdate
end
it "when saledate not set" do
record.saledate = nil
it "when exdate not set" do
record.exdate = nil
record.hodate = Time.zone.now
expect(record).not_to be_hodate_3_years_or_more_saledate
expect(record).not_to be_hodate_3_years_or_more_exdate
end
it "when saledate and hodate not set" do
record.saledate = nil
it "when exdate and hodate not set" do
record.exdate = nil
record.hodate = nil
expect(record).not_to be_hodate_3_years_or_more_saledate
expect(record).not_to be_hodate_3_years_or_more_exdate
end
it "when 3 years or more before saledate" do
record.saledate = Time.zone.now
record.hodate = record.saledate - 4.years
it "when 3 years or more before exdate" do
record.exdate = Time.zone.now
record.hodate = record.exdate - 4.years
expect(record).to be_hodate_3_years_or_more_saledate
expect(record).to be_hodate_3_years_or_more_exdate
end
it "when less than 3 years before saledate" do
record.saledate = Time.zone.now
it "when less than 3 years before exdate" do
record.exdate = Time.zone.now
record.hodate = 2.months.ago
expect(record).not_to be_hodate_3_years_or_more_saledate
expect(record).not_to be_hodate_3_years_or_more_exdate
end
end

Loading…
Cancel
Save