diff --git a/app/models/location.rb b/app/models/location.rb index 2a1dd5c7f..a4ad10801 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,6 +1,6 @@ class Location < ApplicationRecord 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 :name, on: :name, presence: { message: I18n.t("validations.location.name") } validates :units, on: :units, presence: { message: I18n.t("validations.location.units") } diff --git a/spec/factories/location.rb b/spec/factories/location.rb index 870140cd5..75b4380f5 100644 --- a/spec/factories/location.rb +++ b/spec/factories/location.rb @@ -7,7 +7,7 @@ FactoryBot.define do mobility_type { %w[A M N W X].sample } location_code { "E09000033" } location_admin_district { "Westminster" } - startdate { nil } + startdate { Time.zone.local(2022, 4, 1) } confirmed { true } scheme trait :export do diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 1e1756a21..c6167e612 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -46,7 +46,7 @@ RSpec.describe Location, type: :model do let(:location) { FactoryBot.build(:location) } 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) expect(location.errors.count).to eq(1) end @@ -153,7 +153,7 @@ RSpec.describe Location, type: :model do context "when filtering by active locations" 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 diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 87351b9dd..12a90f639 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -86,7 +86,7 @@ RSpec.describe Validations::DateValidations do context "with a deactivated location" do let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:, startdate: nil) } + let(:location) { create(:location, scheme:) } before do 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 let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:, startdate: nil) } + let(:location) { create(:location, scheme:) } before do 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 let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:, startdate: nil) } + let(:location) { create(:location, scheme:) } before do create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index fa95757c4..ebc71d48b 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -34,7 +34,7 @@ RSpec.describe Validations::SetupValidations do describe "#validate_scheme" do context "with a deactivated location" do let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:, startdate: nil) } + let(:location) { create(:location, scheme:) } before do 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 let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:, startdate: nil) } + let(:location) { create(:location, scheme:) } before do 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 context "with a deactivated location" do let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:, startdate: nil) } + let(:location) { create(:location, scheme:) } before do 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 let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:, startdate: nil) } + let(:location) { create(:location, scheme:) } before do create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index fef738427..3996e8f41 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/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 let(:user) { FactoryBot.create(:user, :data_coordinator) } 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!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } 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 let(:user) { FactoryBot.create(:user, :data_coordinator) } 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 } before do @@ -1641,7 +1641,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } 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(:startdate) { Time.utc(2022, 10, 11) } diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index c605d584f..da7b3e517 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/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) 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) scheme_to_update.locations.each do |location| expect(location.confirmed?).to eq(true)