diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index 801560b91..c29ae5d86 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -21,11 +21,4 @@ module TabNavHelper role = "#{user.role.to_s.humanize}" [user.organisation.name, role].join("\n") end - - def tab_items(user) - [ - { name: t("Details"), url: details_organisation_path(user.organisation) }, - { name: t("Users"), url: users_organisation_path(user.organisation) }, - ] - end end diff --git a/app/models/form/sales/questions/mortgage_length.rb b/app/models/form/sales/questions/mortgage_length.rb index 317489763..56a358f01 100644 --- a/app/models/form/sales/questions/mortgage_length.rb +++ b/app/models/form/sales/questions/mortgage_length.rb @@ -8,5 +8,6 @@ class Form::Sales::Questions::MortgageLength < ::Form::Question @min = 0 @width = 5 @suffix = " years" + @hint_text = "You should round up to the nearest year. Value should not exceed 60 years." end end diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index ff996962c..c70a8d57d 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -7,18 +7,14 @@ module Validations::Sales::SaleInformationValidations end end - def validate_exchange_and_completion_date(record) + def validate_exchange_date(record) return unless record.exdate && record.saledate - if record.exdate > record.saledate - record.errors.add :exdate, I18n.t("validations.sale_information.completion_exchange.exchange_before_completion") - record.errors.add :saledate, I18n.t("validations.sale_information.completion_exchange.completion_after_exchange") - end + record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_before_saledate")) if record.exdate > record.saledate - if record.exdate < record.saledate - 1.year - record.errors.add :exdate, I18n.t("validations.sale_information.completion_exchange.exchange_after_one_year_before_completion") - record.errors.add :saledate, I18n.t("validations.sale_information.completion_exchange.completion_before_one_year_after_exchange") - end + return if (record.saledate.to_date - record.exdate.to_date).to_i / 365 < 1 + + record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_less_than_1_year_from_saledate")) end def validate_previous_property_unit_type(record) diff --git a/config/environments/development.rb b/config/environments/development.rb index 24155edfa..6261c29c8 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -73,7 +73,7 @@ Rails.application.configure do config.active_record.verbose_query_logs = true # Raises error for missing translations. - # config.i18n.raise_on_missing_translations = true + config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true diff --git a/config/environments/test.rb b/config/environments/test.rb index dca19f3d1..1c399b19d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -57,7 +57,7 @@ Rails.application.configure do config.active_support.disallowed_deprecation_warnings = [] # Raises error for missing translations. - # config.i18n.raise_on_missing_translations = true + config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true diff --git a/config/locales/en.yml b/config/locales/en.yml index 3064a9171..fc398232f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -415,6 +415,11 @@ en: deactivation: during_deactivated_period: "The location is already deactivated during this date, please enter a different date" sale_information: + exdate: + must_be_before_saledate: + Contract exchange date must be less than 1 year before completion date + must_be_less_than_1_year_from_saledate: + Contract exchange date must be less than 1 year before completion date previous_property_beds: property_type_bedsit: "Bedsit bedroom maximum 1" previous_property_type: diff --git a/spec/helpers/tab_nav_helper_spec.rb b/spec/helpers/tab_nav_helper_spec.rb index b2273aa11..7b4efc5eb 100644 --- a/spec/helpers/tab_nav_helper_spec.rb +++ b/spec/helpers/tab_nav_helper_spec.rb @@ -34,26 +34,4 @@ RSpec.describe TabNavHelper do expect(scheme_cell(scheme)).to match(expected_html) end end - - describe "#tab_items" do - context "when user is a data_coordinator" do - let(:user) { FactoryBot.build(:user, :data_coordinator, organisation:) } - - it "returns details and user tabs" do - result = tab_items(user).map { |i| i[:name] } - expect(result.count).to eq(2) - expect(result.first).to match("Details") - expect(result.second).to match("Users") - end - end - - context "when user is a data_provider" do - it "returns details and user tabs" do - result = tab_items(user).map { |i| i[:name] } - expect(result.count).to eq(2) - expect(result.first).to match("Details") - expect(result.second).to match("Users") - end - end - end end diff --git a/spec/models/form/sales/questions/mortgage_length_spec.rb b/spec/models/form/sales/questions/mortgage_length_spec.rb index 519289607..e96a05174 100644 --- a/spec/models/form/sales/questions/mortgage_length_spec.rb +++ b/spec/models/form/sales/questions/mortgage_length_spec.rb @@ -32,7 +32,9 @@ RSpec.describe Form::Sales::Questions::MortgageLength, type: :model do end it "has the correct hint" do - expect(question.hint_text).to be_nil + expect(question.hint_text).to eq( + "You should round up to the nearest year. Value should not exceed 60 years.", + ) end it "has correct width" do diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 885ebc3dc..409972040 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -67,14 +67,14 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end - describe "#validate_exchange_and_completion_date" do + describe "#validate_exchange_date" do context "when exdate blank" do let(:record) { build(:sales_log, exdate: nil) } it "does not add an error" do - sale_information_validator.validate_exchange_and_completion_date(record) + sale_information_validator.validate_exchange_date(record) - expect(record.errors).not_to be_present + expect(record.errors[:exdate]).not_to be_present end end @@ -82,9 +82,9 @@ RSpec.describe Validations::Sales::SaleInformationValidations do let(:record) { build(:sales_log, saledate: nil) } it "does not add an error" do - sale_information_validator.validate_exchange_and_completion_date(record) + sale_information_validator.validate_exchange_date(record) - expect(record.errors).not_to be_present + expect(record.errors[:exdate]).not_to be_present end end @@ -92,30 +92,31 @@ RSpec.describe Validations::Sales::SaleInformationValidations do let(:record) { build(:sales_log, exdate: nil, saledate: nil) } it "does not add an error" do - sale_information_validator.validate_exchange_and_completion_date(record) + sale_information_validator.validate_exchange_date(record) - expect(record.errors).not_to be_present + expect(record.errors[:exdate]).not_to be_present end end - context "when exdate less than a year before saledate" do + context "when exdate before saledate" do let(:record) { build(:sales_log, exdate: 2.months.ago, saledate: 1.month.ago) } it "does not add the error" do - sale_information_validator.validate_exchange_and_completion_date(record) + sale_information_validator.validate_exchange_date(record) - expect(record.errors).not_to be_present + expect(record.errors[:exdate]).not_to be_present end end - context "when exdate more than a year before saledate" do + context "when exdate more than 1 year before saledate" do let(:record) { build(:sales_log, exdate: 2.years.ago, saledate: 1.month.ago) } - it "adds error" do - sale_information_validator.validate_exchange_and_completion_date(record) + it "does not add the error" do + sale_information_validator.validate_exchange_date(record) - expect(record.errors[:exdate]).to include(I18n.t("validations.sale_information.completion_exchange.exchange_after_one_year_before_completion")) - expect(record.errors[:saledate]).to include(I18n.t("validations.sale_information.completion_exchange.completion_before_one_year_after_exchange")) + expect(record.errors[:exdate]).to eq( + ["Contract exchange date must be less than 1 year before completion date"], + ) end end @@ -123,10 +124,11 @@ RSpec.describe Validations::Sales::SaleInformationValidations do let(:record) { build(:sales_log, exdate: 1.month.ago, saledate: 2.months.ago) } it "adds error" do - sale_information_validator.validate_exchange_and_completion_date(record) + sale_information_validator.validate_exchange_date(record) - expect(record.errors[:exdate]).to include(I18n.t("validations.sale_information.completion_exchange.exchange_before_completion")) - expect(record.errors[:saledate]).to include(I18n.t("validations.sale_information.completion_exchange.completion_after_exchange")) + expect(record.errors[:exdate]).to eq( + ["Contract exchange date must be less than 1 year before completion date"], + ) end end @@ -134,9 +136,9 @@ RSpec.describe Validations::Sales::SaleInformationValidations do let(:record) { build(:sales_log, exdate: Time.zone.parse("2023-07-01"), saledate: Time.zone.parse("2023-07-01")) } it "does not add an error" do - sale_information_validator.validate_exchange_and_completion_date(record) + sale_information_validator.validate_exchange_date(record) - expect(record.errors).not_to be_present + expect(record.errors[:exdate]).not_to be_present end end end