Browse Source

Add availability to the locations table

pull/976/head
Kat 3 years ago
parent
commit
9fcb766233
  1. 5
      app/models/location.rb
  2. 3
      spec/features/schemes_spec.rb
  3. 10
      spec/models/location_spec.rb

5
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

3
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

10
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

Loading…
Cancel
Save