diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb
index e0fe9d18c..e21a4724e 100644
--- a/app/helpers/locations_helper.rb
+++ b/app/helpers/locations_helper.rb
@@ -22,4 +22,18 @@ module LocationsHelper
resource.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) }
end
+
+ def display_attributes(location)
+ [
+ { name: "Postcode", value: location.postcode },
+ { name: "Local authority", value: location.location_admin_district },
+ { name: "Location name", value: location.name, edit: true },
+ { name: "Total number of units at this location", value: location.units },
+ { 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 #{location.available_from.to_formatted_s(:govuk_date)}" },
+ { name: "Status", value: location.status },
+ ]
+ end
end
diff --git a/app/models/location.rb b/app/models/location.rb
index 9abae85e1..0fdc24a8e 100644
--- a/app/models/location.rb
+++ b/app/models/location.rb
@@ -359,20 +359,6 @@ class Location < ApplicationRecord
enum type_of_unit: TYPE_OF_UNIT
- def display_attributes
- [
- { name: "Postcode", value: postcode },
- { name: "Local authority", value: location_admin_district },
- { name: "Location name", value: name, edit: true },
- { name: "Total number of units at this location", value: units },
- { 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)}" },
- { name: "Status", value: status },
- ]
- end
-
def postcode=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
@@ -381,6 +367,14 @@ class Location < ApplicationRecord
end
end
+ def available_from
+ startdate || created_at
+ end
+
+ def status
+ "active"
+ end
+
private
PIO = PostcodeService.new
@@ -399,12 +393,4 @@ private
self.location_admin_district = result[:location_admin_district]
end
end
-
- def available_from
- startdate || created_at
- end
-
- def status
- "active"
- end
end
diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb
index 7ef4ed56c..42843c755 100644
--- a/app/views/locations/show.html.erb
+++ b/app/views/locations/show.html.erb
@@ -13,7 +13,7 @@
<%= govuk_summary_list do |summary_list| %>
- <% @location.display_attributes.each do |attr| %>
+ <% display_attributes(@location).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value { attr[:name].eql?("Status") ? status_tag(attr[:value]) : details_html(attr) } %>
diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb
index 402772dec..9a4550912 100644
--- a/spec/helpers/locations_helper_spec.rb
+++ b/spec/helpers/locations_helper_spec.rb
@@ -46,4 +46,31 @@ RSpec.describe LocationsHelper do
expect(selection_options(%w[example])).to eq([OpenStruct.new(id: "example", name: "Example")])
end
end
+
+ describe "display_attributes" do
+ let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 8, 8)) }
+
+ it "returns correct display attributes" do
+ attributes = [
+ { name: "Postcode", value: location.postcode },
+ { name: "Local authority", value: location.location_admin_district },
+ { name: "Location name", value: location.name, edit: true },
+ { name: "Total number of units at this location", value: location.units },
+ { 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" },
+ { name: "Status", value: "active" },
+ ]
+
+ expect(display_attributes(location)).to eq(attributes)
+ end
+
+ it "displays created_at as availability date if startdate is not present" do
+ location.update!(startdate: nil)
+ availability_attribute = display_attributes(location).find { |x| x[:name] == "Availability" }[:value]
+
+ expect(availability_attribute).to eq("Available from #{location.created_at.to_formatted_s(:govuk_date)}")
+ end
+ end
end
diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb
index 5c332fd61..856575932 100644
--- a/spec/models/location_spec.rb
+++ b/spec/models/location_spec.rb
@@ -111,31 +111,4 @@ RSpec.describe Location, type: :model do
end
end
end
-
- describe "#display_attributes" do
- let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 8, 8)) }
-
- it "returns correct display attributes" do
- attributes = [
- { name: "Postcode", value: location.postcode },
- { name: "Local authority", value: location.location_admin_district },
- { name: "Location name", value: location.name, edit: true },
- { name: "Total number of units at this location", value: location.units },
- { 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" },
- { name: "Status", value: "active" },
- ]
-
- 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