diff --git a/app/models/location.rb b/app/models/location.rb index da959069b..96a9da9da 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -368,6 +368,7 @@ class Location < ApplicationRecord { name: "Common type of unit", value: type_of_unit }, { name: "Mobility type", value: mobility_type }, { name: "Code", value: location_code }, + { name: "Availability", value: "Available from #{available_from.to_formatted_s(:govuk_date)}" }, ] end @@ -397,4 +398,8 @@ private self.location_admin_district = result[:location_admin_district] end end + + def available_from + startdate || created_at + end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 18d4be6ed..8a0805a9e 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -692,7 +692,7 @@ RSpec.describe "Schemes scheme Features" do context "when I click to see individual scheme" do let(:scheme) { schemes.first } - let!(:location) { FactoryBot.create(:location, scheme:) } + let!(:location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) } before do click_link(scheme.service_name) @@ -766,6 +766,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.mobility_type) expect(page).to have_content(location.location_code) + expect(page).to have_content("Available from 4 April 2022") end it "only allows to edit the location name" do diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index e87867cd5..10f60ca5d 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -113,7 +113,7 @@ RSpec.describe Location, type: :model do end describe "#display_attributes" do - let(:location) { FactoryBot.build(:location) } + let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 8, 8)) } it "returns correct display attributes" do attributes = [ @@ -124,9 +124,17 @@ RSpec.describe Location, type: :model do { name: "Common type of unit", value: location.type_of_unit }, { name: "Mobility type", value: location.mobility_type }, { name: "Code", value: location.location_code }, + { name: "Availability", value: "Available from 8 August 2022" }, ] expect(location.display_attributes).to eq(attributes) end + + it "displays created_at as availability date if startdate is not present" do + location.update!(startdate: nil) + availability_attribute = location.display_attributes.find { |x| x[:name] == "Availability" }[:value] + + expect(availability_attribute).to eq("Available from #{location.created_at.to_formatted_s(:govuk_date)}") + end end end