diff --git a/app/models/location.rb b/app/models/location.rb index e4c6311fc..1b50f7aba 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -372,7 +372,7 @@ class Location < ApplicationRecord end def available_from - startdate || created_at + startdate || [created_at, FormHandler.instance.current_collection_start_date].min end def status diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index cdc63fda6..6ef8b06d8 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -48,7 +48,7 @@ RSpec.describe LocationsHelper do end describe "display_location_attributes" do - let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 4, 1)) } + let(:location) { FactoryBot.build(:location, created_at: Time.zone.local(2022, 3, 16), startdate: Time.zone.local(2022, 4, 1)) } it "returns correct display attributes" do attributes = [ @@ -74,6 +74,13 @@ RSpec.describe LocationsHelper do expect(availability_attribute).to eq("Active from #{location.created_at.to_formatted_s(:govuk_date)}") end + + it "displays current collection start date as availability date if created_at is later than collection start date" do + location.update!(startdate: nil, created_at: Time.zone.local(2022, 4, 16)) + availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] + + expect(availability_attribute).to eq("Active from 1 April 2022") + end end context "with previous deactivations" do