diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index e55b5ca4f..f145f9e7c 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -58,7 +58,8 @@ RSpec.describe "Lettings Log Features" do end context "when the signed is user is a Support user" do - let(:support_user) { create(:user, :support, last_sign_in_at: Time.zone.now, organisation: create(:organisation, name: "User org")) } + let(:organisation) { create(:organisation, name: "User org") } + let(:support_user) { create(:user, :support, last_sign_in_at: Time.zone.now, organisation:) } let(:devise_notify_mailer) { DeviseNotifyMailer.new } let(:notify_client) { instance_double(Notifications::Client) } let(:mfa_template_id) { User::MFA_TEMPLATE_ID } @@ -196,7 +197,8 @@ RSpec.describe "Lettings Log Features" do end context "when the signed is user is not a Support user" do - let(:user) { create(:user, :data_coordinator, name: "User name", organisation: create(:organisation, name: "User org")) } + let(:organisation) { create(:organisation, name: "User org") } + let(:user) { create(:user, :data_coordinator, name: "User name", organisation:) } let(:devise_notify_mailer) { DeviseNotifyMailer.new } let(:notify_client) { instance_double(Notifications::Client) } diff --git a/spec/models/form/lettings/questions/managing_organisation_spec.rb b/spec/models/form/lettings/questions/managing_organisation_spec.rb index 99f19b25f..9d289d455 100644 --- a/spec/models/form/lettings/questions/managing_organisation_spec.rb +++ b/spec/models/form/lettings/questions/managing_organisation_spec.rb @@ -53,11 +53,16 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do end context "when user is not support" do - let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, name: "User org")) } + let(:user_org) { create(:organisation, name: "User org") } + let(:user) { create(:user, :data_coordinator, organisation: user_org) } - let(:log) { create(:lettings_log, managing_organisation: create(:organisation, name: "Managing org 1")) } - let!(:org_rel1) { create(:organisation_relationship, parent_organisation: user.organisation, child_organisation: create(:organisation, name: "Managing org 2")) } - let!(:org_rel2) { create(:organisation_relationship, parent_organisation: user.organisation, child_organisation: create(:organisation, name: "Managing org 3")) } + let(:managing_org1) { create(:organisation, name: "Managing org 1") } + let(:managing_org2) { create(:organisation, name: "Managing org 2") } + let(:managing_org3) { create(:organisation, name: "Managing org 3") } + + let(:log) { create(:lettings_log, managing_organisation: managing_org1) } + let!(:org_rel1) { create(:organisation_relationship, parent_organisation: user.organisation, child_organisation: managing_org2) } + let!(:org_rel2) { create(:organisation_relationship, parent_organisation: user.organisation, child_organisation: managing_org3) } let(:options) do { @@ -77,9 +82,14 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do context "when user is support" do let(:user) { create(:user, :support) } let(:log_owning_org) { create(:organisation, name: "Owning org") } - let(:log) { create(:lettings_log, owning_organisation: log_owning_org, managing_organisation: create(:organisation, name: "Managing org 1"), created_by: nil) } - let!(:org_rel1) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 2")) } - let!(:org_rel2) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 3")) } + + let(:managing_org1) { create(:organisation, name: "Managing org 1") } + let(:managing_org2) { create(:organisation, name: "Managing org 2") } + let(:managing_org3) { create(:organisation, name: "Managing org 3") } + + let(:log) { create(:lettings_log, owning_organisation: log_owning_org, managing_organisation: managing_org1, created_by: nil) } + let!(:org_rel1) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: managing_org2) } + let!(:org_rel2) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: managing_org3) } context "when org owns stock" do let(:options) do diff --git a/spec/models/form/lettings/questions/stock_owner_spec.rb b/spec/models/form/lettings/questions/stock_owner_spec.rb index ea97a7e41..41aebed89 100644 --- a/spec/models/form/lettings/questions/stock_owner_spec.rb +++ b/spec/models/form/lettings/questions/stock_owner_spec.rb @@ -43,7 +43,8 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do end context "when user is not support" do - let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, name: "User org")) } + let(:user_org) { create(:organisation, name: "User org") } + let(:user) { create(:user, :data_coordinator, organisation: user_org) } let(:owning_org_1) { create(:organisation, name: "Owning org 1") } let(:owning_org_2) { create(:organisation, name: "Owning org 2") } diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 9107004bd..dc009a16d 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -146,7 +146,8 @@ RSpec.describe LettingsLogsController, type: :request do context "when creating a new log" do context "when the user is support" do - let(:support_user) { FactoryBot.create(:user, :support, organisation: FactoryBot.create(:organisation)) } + let(:organisation) { FactoryBot.create(:organisation) } + let(:support_user) { FactoryBot.create(:user, :support, organisation:) } before do allow(support_user).to receive(:need_two_factor_authentication?).and_return(false) @@ -164,7 +165,8 @@ RSpec.describe LettingsLogsController, type: :request do context "when the user is not support" do context "when the user's org holds stock" do - let(:user) { FactoryBot.create(:user, :data_coordinator, organisation: FactoryBot.create(:organisation, name: "User org", holds_own_stock: true)) } + let(:organisation) { FactoryBot.create(:organisation, name: "User org", holds_own_stock: true) } + let(:user) { FactoryBot.create(:user, :data_coordinator, organisation:) } before do RequestHelper.stub_http_requests @@ -181,7 +183,8 @@ RSpec.describe LettingsLogsController, type: :request do end context "when the user's org doesn't hold stock" do - let(:user) { FactoryBot.create(:user, :data_coordinator, organisation: FactoryBot.create(:organisation, name: "User org", holds_own_stock: false)) } + let(:organisation) { FactoryBot.create(:organisation, name: "User org", holds_own_stock: false) } + let(:user) { FactoryBot.create(:user, :data_coordinator, organisation:) } before do RequestHelper.stub_http_requests