From 58f4431dd7f8d035750a26da8eaa12ecde86f7ac Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 22 Apr 2022 10:48:29 +0100 Subject: [PATCH] Default to dislpaying all --- app/models/organisation.rb | 6 ++++-- spec/models/organisation_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/organisation.rb b/app/models/organisation.rb index b55f371bd..e3e7f05c2 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -42,7 +42,8 @@ class Organisation < ApplicationRecord end def local_authority_names - local_authorities.map { |ons_code| LocalAuthority.ons_code_mappings[ons_code] } + names = local_authorities.map { |ons_code| LocalAuthority.ons_code_mappings[ons_code] } + names.present? ? names : ["All"] end def rent_periods @@ -50,7 +51,8 @@ class Organisation < ApplicationRecord end def rent_period_labels - rent_periods.map { |period| RentPeriod.rent_period_mappings[period.to_s]["value"] } + labels = rent_periods.map { |period| RentPeriod.rent_period_mappings[period.to_s]["value"] } + labels.present? ? labels : ["All"] end def display_attributes diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 1a64145b1..f94782b1d 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -57,6 +57,12 @@ RSpec.describe Organisation, type: :model do end end + context "when the organisation has not specified which local authorities it operates in" do + it "displays `all`" do + expect(organisation.local_authority_names).to eq(%w[All]) + end + end + context "when the organisation only uses specific rent periods" do let(:rent_period_mappings) do { "2" => { "value" => "Weekly for 52 weeks" }, "3" => { "value" => "Every 2 weeks" } } @@ -77,6 +83,12 @@ RSpec.describe Organisation, type: :model do end end + context "when the organisation has not specified which rent periods it uses" do + it "displays `all`" do + expect(organisation.rent_period_labels).to eq(%w[All]) + end + end + context "with case logs" do let(:other_organisation) { FactoryBot.create(:organisation) } let!(:owned_case_log) do