Browse Source

Use current collection start date if created at is later than that

pull/1007/head
Kat 4 years ago
parent
commit
79c1544663
  1. 2
      app/models/location.rb
  2. 9
      spec/helpers/locations_helper_spec.rb

2
app/models/location.rb

@ -372,7 +372,7 @@ class Location < ApplicationRecord
end end
def available_from def available_from
startdate || created_at startdate || [created_at, FormHandler.instance.current_collection_start_date].min
end end
def status def status

9
spec/helpers/locations_helper_spec.rb

@ -48,7 +48,7 @@ RSpec.describe LocationsHelper do
end end
describe "display_location_attributes" do 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 it "returns correct display attributes" do
attributes = [ attributes = [
@ -74,6 +74,13 @@ RSpec.describe LocationsHelper do
expect(availability_attribute).to eq("Active from #{location.created_at.to_formatted_s(:govuk_date)}") expect(availability_attribute).to eq("Active from #{location.created_at.to_formatted_s(:govuk_date)}")
end 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 end
context "with previous deactivations" do context "with previous deactivations" do

Loading…
Cancel
Save