Browse Source

Ignore unmapped rent period labels (#1082)

- It's possible that we import rent periods for an organisation that we haven't yet defined on the new service
- In this instance an organisation as `rent_period` of 10, which correspondsto 'Weekly for 53' in the previous service
- Until we decide how to manage that rent period we should safely generate the rent labels
pull/1086/head
James Rose 2 years ago committed by GitHub
parent
commit
8b9af1f850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/organisation.rb
  2. 5
      spec/models/organisation_spec.rb

4
app/models/organisation.rb

@ -60,8 +60,8 @@ class Organisation < ApplicationRecord
end
def rent_period_labels
labels = rent_periods.map { |period| RentPeriod.rent_period_mappings[period.to_s]["value"] }
labels.presence || %w[All]
labels = rent_periods.map { |period| RentPeriod.rent_period_mappings.dig(period.to_s, "value") }
labels.compact.presence || %w[All]
end
def data_protection_confirmed?

5
spec/models/organisation_spec.rb

@ -124,11 +124,14 @@ RSpec.describe Organisation, type: :model do
before do
FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 2)
FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 3)
# Unmapped and ignored by `rent_period_labels`
FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 10)
allow(RentPeriod).to receive(:rent_period_mappings).and_return(rent_period_mappings)
end
it "has rent periods associated" do
expect(organisation.rent_periods).to eq([2, 3])
expect(organisation.rent_periods).to eq([2, 3, 10])
end
it "maps the rent periods to display values" do

Loading…
Cancel
Save