From 6d49be285882522de93084bd5f0b643ff401a6c8 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 22 Nov 2023 13:50:48 +0000 Subject: [PATCH] CLDC-2849 Display correct location code (#2043) * Display correct location code * Simplify formatted_local_authority_timeline --- app/helpers/locations_helper.rb | 12 ++++++------ spec/features/schemes_spec.rb | 4 ++-- spec/helpers/locations_helper_spec.rb | 6 +++--- spec/views/locations/show.html.erb_spec.rb | 1 + 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 6a76e8943..f718e9576 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -28,11 +28,11 @@ module LocationsHelper { name: "Postcode", value: location.postcode, attribute: "postcode" }, { name: "Location name", value: location.name, attribute: "name" }, { name: "Status", value: location.status, attribute: "status" }, - { name: "Local authority", value: formatted_local_authority_timeline(location, "name"), attribute: "local_authority" }, + { name: "Local authority", value: formatted_local_authority_timeline(location), attribute: "local_authority" }, { name: "Number of units", value: location.units, attribute: "units" }, { name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" }, { name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" }, - { name: "Location code", value: formatted_local_authority_timeline(location, "code"), attribute: "location_code" }, + { name: "Location code", value: location.id, attribute: "id" }, { name: "Availability", value: location_availability(location), attribute: "availability" }, ] end @@ -41,7 +41,7 @@ module LocationsHelper [ { name: "Postcode", value: location.postcode, attribute: "postcode" }, { name: "Location name", value: location.name, attribute: "name" }, - { name: "Local authority", value: formatted_local_authority_timeline(location, "name"), attribute: "local_authority" }, + { name: "Local authority", value: formatted_local_authority_timeline(location), attribute: "local_authority" }, { name: "Number of units", value: location.units, attribute: "units" }, { name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" }, { name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" }, @@ -121,14 +121,14 @@ private [inner.deactivation_date, inner.reactivation_date].all? { |date| date.between?(outer.deactivation_date, outer.reactivation_date) } end - def formatted_local_authority_timeline(location, field) + def formatted_local_authority_timeline(location) sorted_linked_authorities = location.linked_local_authorities.sort_by(&:start_date) - return sorted_linked_authorities.first[field] if sorted_linked_authorities.count == 1 + return sorted_linked_authorities.first["name"] if sorted_linked_authorities.count == 1 sorted_linked_authorities.map { |linked_local_authority| formatted_start_date = linked_local_authority.start_date.year == 2021 ? "until" : "#{linked_local_authority.start_date&.to_formatted_s(:govuk_date)} -" formatted_end_date = linked_local_authority.end_date&.to_formatted_s(:govuk_date) || "present" - "#{linked_local_authority[field]} (#{formatted_start_date} #{formatted_end_date})" + "#{linked_local_authority['name']} (#{formatted_start_date} #{formatted_end_date})" }.join("\n") end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 5d57b31e6..f9f0fff7f 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -817,7 +817,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content(deactivated_location.units) expect(page).to have_content(deactivated_location.type_of_unit) expect(page).to have_content(deactivated_location.mobility_type) - expect(page).to have_content(deactivated_location.location_code) + expect(page).to have_content(deactivated_location.id) expect(page).to have_content("Active from 4 April 2022 to 3 June 2022 Deactivated on 4 June 2022") expect(page).to have_content("Deactivated") end @@ -856,7 +856,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content(location.units) 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(location.id) expect(page).to have_content("Active from 4 April 2022") expect(page).to have_content("Active") end diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index b86194918..976939acc 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -146,7 +146,7 @@ RSpec.describe LocationsHelper do { attribute: "units", name: "Number of units", value: location.units }, { attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit }, { attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type }, - { attribute: "location_code", name: "Location code", value: location.location_code }, + { attribute: "id", name: "Location code", value: location.id }, { attribute: "availability", name: "Availability", value: "Active from 1 April 2022" }, ] @@ -168,7 +168,7 @@ RSpec.describe LocationsHelper do { attribute: "units", name: "Number of units", value: location.units }, { attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit }, { attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type }, - { attribute: "location_code", name: "Location code", value: "E07000030 (until 31 March 2023)\nE06000063 (1 April 2023 - present)" }, + { attribute: "id", name: "Location code", value: location.id }, { attribute: "availability", name: "Availability", value: "Active from 1 April 2022" }, ] @@ -191,7 +191,7 @@ RSpec.describe LocationsHelper do { attribute: "units", name: "Number of units", value: location.units }, { attribute: "type_of_unit", name: "Most common unit", value: location.type_of_unit }, { attribute: "mobility_standards", name: "Mobility standards", value: location.mobility_type }, - { attribute: "location_code", name: "Location code", value: "" }, + { attribute: "id", name: "Location code", value: location.id }, { attribute: "availability", name: "Availability", value: "Active from 1 April 2022" }, ] diff --git a/spec/views/locations/show.html.erb_spec.rb b/spec/views/locations/show.html.erb_spec.rb index 65c6c07e2..4164e6baa 100644 --- a/spec/views/locations/show.html.erb_spec.rb +++ b/spec/views/locations/show.html.erb_spec.rb @@ -29,6 +29,7 @@ RSpec.describe "locations/show.html.erb" do let(:location) do instance_double( Location, + id: 5, name: "some location", postcode: "EC1N 2TD", linked_local_authorities: [],