Browse Source

Use managing_organisation for rent period validations (#1176)

CLDC-846-demographic-gender-validation
kosiakkatrina 2 years ago committed by GitHub
parent
commit
be73a2be5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/validations/financial_validations.rb
  2. 6
      spec/models/validations/financial_validations_spec.rb

6
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

6
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"])

Loading…
Cancel
Save