diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb index 88b824b80..d65c7c635 100644 --- a/spec/helpers/schemes_helper_spec.rb +++ b/spec/helpers/schemes_helper_spec.rb @@ -106,11 +106,14 @@ RSpec.describe SchemesHelper do intended_stay: "P", created_at: Time.zone.local(2022, 4, 1)) end - let!(:location) { FactoryBot.create(:location, scheme:) } let!(:scheme_where_managing_organisation_is_owning_organisation) { FactoryBot.create(:scheme, arrangement_type: "D") } let(:support_user) { FactoryBot.create(:user, :support) } let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) } + before do + FactoryBot.create(:location, scheme:) + end + it "returns correct display attributes for a support user" do attributes = [ { name: "Scheme code", value: "S#{scheme.id}" }, diff --git a/spec/models/form/lettings/questions/scheme_id_spec.rb b/spec/models/form/lettings/questions/scheme_id_spec.rb index 3289db4b9..6d2f2e767 100644 --- a/spec/models/form/lettings/questions/scheme_id_spec.rb +++ b/spec/models/form/lettings/questions/scheme_id_spec.rb @@ -51,7 +51,9 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do end context "when a scheme with at least 1 location exists" do - let!(:location) { FactoryBot.create(:location, scheme:) } + before do + FactoryBot.create(:location, scheme:) + end it "has the correct answer_options based on the schemes the user's organisation owns or manages" do expected_answer = { "" => "Select an option", scheme.id.to_s => scheme } @@ -82,7 +84,9 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do end context "when the question is answered" do - let!(:location) { FactoryBot.create(:location, scheme:) } + before do + FactoryBot.create(:location, scheme:) + end it "returns scheme as selected answer" do lettings_log.update!(scheme:) diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb index f6daf6fe7..db824d7cd 100644 --- a/spec/models/scheme_spec.rb +++ b/spec/models/scheme_spec.rb @@ -94,9 +94,9 @@ RSpec.describe Scheme, type: :model do describe "status" do let(:scheme) { FactoryBot.build(:scheme) } - let!(:location) { FactoryBot.create(:location, scheme:) } before do + FactoryBot.create(:location, scheme:) Timecop.freeze(2022, 6, 7) end diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 1211b7ef7..3ac6232a0 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -171,9 +171,9 @@ RSpec.describe Validations::DateValidations do context "with a scheme that is reactivating soon" do let(:scheme) { create(:scheme) } - let!(:location) { FactoryBot.create(:location, scheme:) } before do + FactoryBot.create(:location, scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) scheme.reload end @@ -196,9 +196,9 @@ RSpec.describe Validations::DateValidations do context "with a scheme that has many reactivations soon" do let(:scheme) { create(:scheme) } - let!(:location) { FactoryBot.create(:location, scheme:) } before do + FactoryBot.create(:location, scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index c1c9c27c9..98756af96 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -186,9 +186,8 @@ RSpec.describe Validations::SetupValidations do context "with a scheme that is reactivating soon" do let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) } - let!(:location) { FactoryBot.create(:location, scheme:) } - before do + FactoryBot.create(:location, scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) scheme.reload end @@ -211,9 +210,9 @@ RSpec.describe Validations::SetupValidations do context "with a scheme that has many reactivations soon" do let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) } - let!(:location) { FactoryBot.create(:location, scheme:) } before do + FactoryBot.create(:location, scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index af4a83560..fb9150940 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -264,9 +264,9 @@ RSpec.describe SchemesController, type: :request do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period } - let!(:location) { FactoryBot.create(:location, scheme:) } before do + FactoryBot.create(:location, scheme:) Timecop.freeze(Time.utc(2022, 10, 10)) sign_in user add_deactivations