From a1681d0a7f28c72eb874b04d9551fa884a97b10d Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 24 Jan 2023 17:43:46 +0000 Subject: [PATCH] feat: more saledate -> exdate fixing --- .../sales/sale_information_validations.rb | 2 +- .../validations/sales/soft_validations.rb | 6 ++-- .../sale_information_validations_spec.rb | 34 +++++++++---------- .../sales/soft_validations_spec.rb | 32 ++++++++--------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 492bfc713..8e1e52885 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/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 diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 45c50cc1e..d1f9a096a 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/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? diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index fafe2786a..34a4d1495 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/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 diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index 34f49d847..b7f2c11fb 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/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