Browse Source

feat: fix tests

pull/1456/head
natdeanlewissoftwire 3 years ago
parent
commit
20326fd55b
  1. 1
      spec/helpers/schemes_helper_spec.rb
  2. 1
      spec/models/scheme_spec.rb
  3. 2
      spec/models/validations/date_validations_spec.rb
  4. 2
      spec/models/validations/setup_validations_spec.rb
  5. 7
      spec/requests/schemes_controller_spec.rb

1
spec/helpers/schemes_helper_spec.rb

@ -106,6 +106,7 @@ RSpec.describe SchemesHelper do
intended_stay: "P", intended_stay: "P",
created_at: Time.zone.local(2022, 4, 1)) created_at: Time.zone.local(2022, 4, 1))
end end
let!(:location) { FactoryBot.create(:location, scheme:) }
let!(:scheme_where_managing_organisation_is_owning_organisation) { FactoryBot.create(:scheme, arrangement_type: "D") } let!(:scheme_where_managing_organisation_is_owning_organisation) { FactoryBot.create(:scheme, arrangement_type: "D") }
let(:support_user) { FactoryBot.create(:user, :support) } let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) } let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) }

1
spec/models/scheme_spec.rb

@ -94,6 +94,7 @@ RSpec.describe Scheme, type: :model do
describe "status" do describe "status" do
let(:scheme) { FactoryBot.build(:scheme) } let(:scheme) { FactoryBot.build(:scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
Timecop.freeze(2022, 6, 7) Timecop.freeze(2022, 6, 7)

2
spec/models/validations/date_validations_spec.rb

@ -171,6 +171,7 @@ RSpec.describe Validations::DateValidations do
context "with a scheme that is reactivating soon" do context "with a scheme that is reactivating soon" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
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, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
@ -195,6 +196,7 @@ RSpec.describe Validations::DateValidations do
context "with a scheme that has many reactivations soon" do context "with a scheme that has many reactivations soon" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
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, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)

2
spec/models/validations/setup_validations_spec.rb

@ -186,6 +186,7 @@ RSpec.describe Validations::SetupValidations do
context "with a scheme that is reactivating soon" do context "with a scheme that is reactivating soon" do
let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) } let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
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, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
@ -210,6 +211,7 @@ RSpec.describe Validations::SetupValidations do
context "with a scheme that has many reactivations soon" do context "with a scheme that has many reactivations soon" do
let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) } let(:scheme) { create(:scheme, created_at: Time.zone.local(2022, 4, 1)) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
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, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)

7
spec/requests/schemes_controller_spec.rb

@ -7,6 +7,12 @@ RSpec.describe SchemesController, type: :request do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5) } let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
before do
schemes.each do |scheme|
FactoryBot.create(:location, scheme:)
end
end
describe "#index" do describe "#index" do
context "when not signed in" do context "when not signed in" do
it "redirects to the sign in page" do it "redirects to the sign in page" do
@ -258,6 +264,7 @@ RSpec.describe SchemesController, type: :request do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period } let(:add_deactivations) { scheme.scheme_deactivation_periods << scheme_deactivation_period }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
Timecop.freeze(Time.utc(2022, 10, 10)) Timecop.freeze(Time.utc(2022, 10, 10))

Loading…
Cancel
Save