Browse Source

test: don't create vars inside other vars (for tests edited/created in this branch)

fix-remove-attr-accessors-from-questions-in-cldc-1723
Sam Seed 2 years ago
parent
commit
01c5d0876e
  1. 6
      spec/features/lettings_log_spec.rb
  2. 24
      spec/models/form/lettings/questions/managing_organisation_spec.rb
  3. 3
      spec/models/form/lettings/questions/stock_owner_spec.rb
  4. 9
      spec/requests/lettings_logs_controller_spec.rb

6
spec/features/lettings_log_spec.rb

@ -58,7 +58,8 @@ RSpec.describe "Lettings Log Features" do
end end
context "when the signed is user is a Support user" do 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(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:notify_client) { instance_double(Notifications::Client) } let(:notify_client) { instance_double(Notifications::Client) }
let(:mfa_template_id) { User::MFA_TEMPLATE_ID } let(:mfa_template_id) { User::MFA_TEMPLATE_ID }
@ -196,7 +197,8 @@ RSpec.describe "Lettings Log Features" do
end end
context "when the signed is user is not a Support user" do 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(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:notify_client) { instance_double(Notifications::Client) } let(:notify_client) { instance_double(Notifications::Client) }

24
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -53,11 +53,16 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end end
context "when user is not support" do 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(:managing_org1) { 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(:managing_org2) { 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_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 let(:options) do
{ {
@ -77,9 +82,14 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
context "when user is support" do context "when user is support" do
let(:user) { create(:user, :support) } let(:user) { create(:user, :support) }
let(:log_owning_org) { create(:organisation, name: "Owning org") } 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(:managing_org1) { create(:organisation, name: "Managing org 1") }
let!(:org_rel2) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 3")) } 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 context "when org owns stock" do
let(:options) do let(:options) do

3
spec/models/form/lettings/questions/stock_owner_spec.rb

@ -43,7 +43,8 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
end end
context "when user is not support" do 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_1) { create(:organisation, name: "Owning org 1") }
let(:owning_org_2) { create(:organisation, name: "Owning org 2") } let(:owning_org_2) { create(:organisation, name: "Owning org 2") }

9
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 creating a new log" do
context "when the user is support" 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 before do
allow(support_user).to receive(:need_two_factor_authentication?).and_return(false) 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 is not support" do
context "when the user's org holds stock" 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 before do
RequestHelper.stub_http_requests RequestHelper.stub_http_requests
@ -181,7 +183,8 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "when the user's org doesn't hold stock" do 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 before do
RequestHelper.stub_http_requests RequestHelper.stub_http_requests

Loading…
Cancel
Save