From aef8e9bb726285f05298bab36f74cb0256800165 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:49:05 +0100 Subject: [PATCH] Update tests to check rent periods are in order --- spec/models/organisation_spec.rb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 2cd3351d5..671541045 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -111,45 +111,52 @@ RSpec.describe Organisation, type: :model do context "with associated rent periods" do let(:organisation) { create(:organisation) } let(:period_1_label) { "Every minute" } + let(:period_2_label) { "Every decade" } + let(:period_3_label) { "Every century" } + let(:period_4_label) { "Every millennium" } let(:fake_rent_periods) do { "1" => { "value" => period_1_label }, - "2" => { "value" => "Every decade" }, + "2" => { "value" => period_2_label }, + "3" => { "value" => period_3_label }, + "4" => { "value" => period_4_label }, } end before do - create(:organisation_rent_period, organisation:, rent_period: 1) + [4,2,1].each do |rent_period| + create(:organisation_rent_period, organisation:, rent_period:) + end allow(RentPeriod).to receive(:rent_period_mappings).and_return(fake_rent_periods) end context "when the org does not use all rent periods" do it "#rent_periods returns the correct ids" do - expect(organisation.rent_periods).to eq [1] + expect(organisation.rent_periods).to eq [4, 2, 1] end - it "#rent_period_labels returns the correct labels" do - expect(organisation.rent_period_labels).to eq [period_1_label] + it "#rent_period_labels returns the correct labels in order" do + expect(organisation.rent_period_labels).to eq [period_1_label, period_2_label, period_4_label] end context "and has organisation rent periods associated for rent periods that no longer appear in the form" do before do - create(:organisation_rent_period, organisation:, rent_period: 3) + create(:organisation_rent_period, organisation:, rent_period: 6) end it "#rent_period_labels returns the correct labels" do - expect(organisation.rent_period_labels).to eq [period_1_label] + expect(organisation.rent_period_labels).to eq [period_1_label, period_2_label, period_4_label] end end end context "when the org uses all rent periods" do before do - create(:organisation_rent_period, organisation:, rent_period: 2) + create(:organisation_rent_period, organisation:, rent_period: 3) end it "#rent_periods returns the correct ids" do - expect(organisation.rent_periods).to eq [1, 2] + expect(organisation.rent_periods).to eq [4, 2, 1, 3] end it "#rent_period_labels returns All" do @@ -158,7 +165,7 @@ RSpec.describe Organisation, type: :model do context "and has organisation rent periods associated for rent periods that no longer appear in the form" do before do - create(:organisation_rent_period, organisation:, rent_period: 3) + create(:organisation_rent_period, organisation:, rent_period: 6) end it "#rent_period_labels returns All" do