From 2e395d3e02f1125b0c1d28a63529c4dcd2ddb3af Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Thu, 6 Jun 2024 11:47:28 +0100 Subject: [PATCH] Specify orgs on sh logs when needed for tests --- .../update_schemes_and_locations_from_csv_spec.rb | 10 +++++----- spec/models/lettings_log_spec.rb | 11 +++++------ spec/requests/locations_controller_spec.rb | 6 +++--- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb b/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb index ba87cc15a..0d61b08f1 100644 --- a/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb +++ b/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb @@ -336,11 +336,11 @@ RSpec.describe "bulk_update" do updated_at: Time.zone.local(2022, 3, 1), scheme:) end - let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location: locations[0], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } - let!(:lettings_log_2) { FactoryBot.create(:lettings_log, :sh, location: locations[1], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } - let!(:lettings_log_3) { FactoryBot.create(:lettings_log, :sh, location: locations[2], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } - let!(:lettings_log_4) { FactoryBot.create(:lettings_log, :sh, location: locations[0], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } - let!(:lettings_log_5) { FactoryBot.create(:lettings_log, :sh, location: locations[0], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } + let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, owning_organisation: scheme.owning_organisation, location: locations[0], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } + let!(:lettings_log_2) { FactoryBot.create(:lettings_log, :sh, owning_organisation: scheme.owning_organisation, location: locations[1], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } + let!(:lettings_log_3) { FactoryBot.create(:lettings_log, :sh, owning_organisation: scheme.owning_organisation, location: locations[2], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } + let!(:lettings_log_4) { FactoryBot.create(:lettings_log, :sh, owning_organisation: scheme.owning_organisation, location: locations[0], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } + let!(:lettings_log_5) { FactoryBot.create(:lettings_log, :sh, owning_organisation: scheme.owning_organisation, location: locations[0], scheme:, values_updated_at: nil, startdate: Time.zone.local(2023, 4, 4)) } before do allow(storage_service).to receive(:get_file_io) diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index d79eab06f..37a8b734a 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -494,7 +494,7 @@ RSpec.describe LettingsLog do end context "and a scheme with a single log is selected" do - let(:scheme) { create(:scheme) } + let(:scheme) { create(:scheme, owning_organisation:) } let!(:location) { create(:location, scheme:) } before do @@ -567,7 +567,7 @@ RSpec.describe LettingsLog do end context "and not renewal" do - let(:scheme) { create(:scheme) } + let(:scheme) { create(:scheme, owning_organisation:) } let(:location) { create(:location, scheme:, postcode: "M11AE", type_of_unit: 1, mobility_type: "W") } let(:supported_housing_lettings_log) do @@ -1743,7 +1743,7 @@ RSpec.describe LettingsLog do end context "when there is a duplicate supported housing log" do - let(:scheme) { create(:scheme) } + let(:scheme) { create(:scheme, owning_organisation: organisation) } let(:location) { create(:location, scheme:) } let(:location_2) { create(:location, scheme:) } let!(:supported_housing_log) { create(:lettings_log, :duplicate, needstype: 2, location:, scheme:, owning_organisation: organisation) } @@ -1770,9 +1770,8 @@ RSpec.describe LettingsLog do end it "does not return logs not associated with the user if user is given" do - user = create(:user) - supported_housing_log.update!(assigned_to: user, owning_organisation: user.organisation) - duplicate_supported_housing_log.update!(owning_organisation: user.organisation) + user = create(:user, organisation:) + supported_housing_log.update!(assigned_to: user) duplicate_sets = described_class.duplicate_sets(user.id) expect(duplicate_sets.count).to eq(1) expect(duplicate_sets.first).to contain_exactly(supported_housing_log.id, duplicate_supported_housing_log.id) diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 7ab97efd3..b42176967 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1582,8 +1582,8 @@ RSpec.describe LocationsController, type: :request do before do allow(LocationOrSchemeDeactivationMailer).to receive(:send_deactivation_mail).and_call_original - create(:lettings_log, :sh, location:, scheme:, startdate:, assigned_to: user_a) - create_list(:lettings_log, 3, :sh, location:, scheme:, startdate:, assigned_to: user_b) + create(:lettings_log, :sh, owning_organisation: scheme.owning_organisation, location:, scheme:, startdate:, assigned_to: user_a) + create_list(:lettings_log, 3, :sh, owning_organisation: scheme.owning_organisation, location:, scheme:, startdate:, assigned_to: user_b) Timecop.freeze(Time.utc(2022, 10, 10)) sign_in user @@ -1915,7 +1915,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a support user" do let(:user) { create(:user, :support) } - let(:scheme) { create(:scheme) } + let(:scheme) { create(:scheme, owning_organisation: user.organisation) } let(:location) { create(:location, scheme:) } let(:add_deactivations) { location.location_deactivation_periods << location_deactivation_period }