From be73a2be5c8b31aa82992d0c06e9ea447066bbe3 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 16 Jan 2023 09:07:22 +0000 Subject: [PATCH] Use managing_organisation for rent period validations (#1176) --- app/models/validations/financial_validations.rb | 6 +++--- spec/models/validations/financial_validations_spec.rb | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 87c506b4d..a5430bbea 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -98,11 +98,11 @@ module Validations::FinancialValidations end def validate_rent_period(record) - if record.owning_organisation.present? && record.owning_organisation.rent_periods.present? && - record.period && !record.owning_organisation.rent_periods.include?(record.period) + if record.managing_organisation.present? && record.managing_organisation.rent_periods.present? && + record.period && !record.managing_organisation.rent_periods.include?(record.period) record.errors.add :period, I18n.t( "validations.financial.rent_period.invalid_for_org", - org_name: record.owning_organisation.name, + org_name: record.managing_organisation.name, rent_period: record.form.get_question("period", record).label_from_value(record.period).downcase, ) end diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index edd41e26f..ae7875e08 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -126,14 +126,16 @@ RSpec.describe Validations::FinancialValidations do describe "rent period validations" do let(:organisation) { FactoryBot.create(:organisation) } - let(:record) { FactoryBot.create(:lettings_log, owning_organisation: organisation) } + let(:user) { FactoryBot.create(:user) } + let(:record) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation, managing_organisation: organisation, created_by: user) } before do + FactoryBot.create(:organisation_relationship, parent_organisation: user.organisation, child_organisation: organisation) FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 2) end context "when the organisation only uses specific rent periods" do - it "validates that the selected rent period is used by the organisation" do + it "validates that the selected rent period is used by the managing organisation" do record.period = 3 financial_validator.validate_rent_period(record) expect(record.errors["period"])