Browse Source

tests: make tests pass with new startdate validation

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
6421e2443a
  1. 2
      app/models/location.rb
  2. 2
      spec/factories/location.rb
  3. 4
      spec/models/location_spec.rb
  4. 6
      spec/models/validations/date_validations_spec.rb
  5. 8
      spec/models/validations/setup_validations_spec.rb
  6. 6
      spec/requests/locations_controller_spec.rb
  7. 2
      spec/requests/schemes_controller_spec.rb

2
app/models/location.rb

@ -1,6 +1,6 @@
class Location < ApplicationRecord class Location < ApplicationRecord
validates :postcode, on: :postcode, presence: { message: I18n.t("validations.location.postcode_blank") } validates :postcode, on: :postcode, presence: { message: I18n.t("validations.location.postcode_blank") }
validate :validate_postcode, on: :postcode validate :validate_postcode, on: :postcode, if: Proc.new { |model| model.postcode.presence }
validates :location_admin_district, on: :location_admin_district, presence: { message: I18n.t("validations.location_admin_district") } validates :location_admin_district, on: :location_admin_district, presence: { message: I18n.t("validations.location_admin_district") }
validates :name, on: :name, presence: { message: I18n.t("validations.location.name") } validates :name, on: :name, presence: { message: I18n.t("validations.location.name") }
validates :units, on: :units, presence: { message: I18n.t("validations.location.units") } validates :units, on: :units, presence: { message: I18n.t("validations.location.units") }

2
spec/factories/location.rb

@ -7,7 +7,7 @@ FactoryBot.define do
mobility_type { %w[A M N W X].sample } mobility_type { %w[A M N W X].sample }
location_code { "E09000033" } location_code { "E09000033" }
location_admin_district { "Westminster" } location_admin_district { "Westminster" }
startdate { nil } startdate { Time.zone.local(2022, 4, 1) }
confirmed { true } confirmed { true }
scheme scheme
trait :export do trait :export do

4
spec/models/location_spec.rb

@ -46,7 +46,7 @@ RSpec.describe Location, type: :model do
let(:location) { FactoryBot.build(:location) } let(:location) { FactoryBot.build(:location) }
it "does add an error when the local authority is invalid" do it "does add an error when the local authority is invalid" do
location.location_admin_district = "Select an option" location.location_admin_district = nil
location.valid?(:location_admin_district) location.valid?(:location_admin_district)
expect(location.errors.count).to eq(1) expect(location.errors.count).to eq(1)
end end
@ -153,7 +153,7 @@ RSpec.describe Location, type: :model do
context "when filtering by active locations" do context "when filtering by active locations" do
it "returns only locations that started today or earlier and have been confirmed" do it "returns only locations that started today or earlier and have been confirmed" do
expect(described_class.active.count).to eq(2) expect(described_class.active.count).to eq(1)
end end
end end
end end

6
spec/models/validations/date_validations_spec.rb

@ -86,7 +86,7 @@ RSpec.describe Validations::DateValidations do
context "with a deactivated location" do context "with a deactivated location" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:, startdate: nil) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
@ -111,7 +111,7 @@ RSpec.describe Validations::DateValidations do
context "with a location that is reactivating soon" do context "with a location that is reactivating soon" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:, startdate: nil) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
@ -136,7 +136,7 @@ RSpec.describe Validations::DateValidations do
context "with a location that has many reactivations soon" do context "with a location that has many reactivations soon" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:, startdate: nil) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)

8
spec/models/validations/setup_validations_spec.rb

@ -34,7 +34,7 @@ RSpec.describe Validations::SetupValidations do
describe "#validate_scheme" do describe "#validate_scheme" do
context "with a deactivated location" do context "with a deactivated location" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:, startdate: nil) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
@ -59,7 +59,7 @@ RSpec.describe Validations::SetupValidations do
context "with a location that is reactivating soon" do context "with a location that is reactivating soon" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:, startdate: nil) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
@ -156,7 +156,7 @@ RSpec.describe Validations::SetupValidations do
describe "#validate_location" do describe "#validate_location" do
context "with a deactivated location" do context "with a deactivated location" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:, startdate: nil) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
@ -181,7 +181,7 @@ RSpec.describe Validations::SetupValidations do
context "with a location that is reactivating soon" do context "with a location that is reactivating soon" do
let(:scheme) { create(:scheme) } let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:, startdate: nil) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)

6
spec/requests/locations_controller_spec.rb

@ -1354,7 +1354,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" 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!(:location) { FactoryBot.create(:location, scheme:, startdate: nil, created_at: Time.zone.local(2022, 4, 1)) } let!(:location) { FactoryBot.create(:location, scheme:, created_at: Time.zone.local(2022, 4, 1)) }
let(:deactivation_date) { Time.utc(2022, 10, 10) } let(:deactivation_date) { Time.utc(2022, 10, 10) }
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) } let(:startdate) { Time.utc(2022, 10, 11) }
@ -1563,7 +1563,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" 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!(:location) { FactoryBot.create(:location, scheme:, startdate: nil) } let!(:location) { FactoryBot.create(:location, scheme:) }
let(:add_deactivations) { location.location_deactivation_periods << location_deactivation_period } let(:add_deactivations) { location.location_deactivation_periods << location_deactivation_period }
before do before do
@ -1641,7 +1641,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" 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!(:location) { FactoryBot.create(:location, scheme:, startdate: nil) } let!(:location) { FactoryBot.create(:location, scheme:) }
let(:deactivation_date) { Time.zone.local(2022, 4, 1) } let(:deactivation_date) { Time.zone.local(2022, 4, 1) }
let(:startdate) { Time.utc(2022, 10, 11) } let(:startdate) { Time.utc(2022, 10, 11) }

2
spec/requests/schemes_controller_spec.rb

@ -978,7 +978,7 @@ RSpec.describe SchemesController, type: :request do
expect(scheme_to_update.reload.confirmed?).to eq(true) expect(scheme_to_update.reload.confirmed?).to eq(true)
end end
it "marks all the scheme locations as confirmed" do it "marks all the scheme locations as confirmed given they are complete" do
expect(scheme_to_update.locations.count > 0).to eq(true) expect(scheme_to_update.locations.count > 0).to eq(true)
scheme_to_update.locations.each do |location| scheme_to_update.locations.each do |location|
expect(location.confirmed?).to eq(true) expect(location.confirmed?).to eq(true)

Loading…
Cancel
Save