From 947f7e1afedd0b760526d9d4c427e3a70cb51290 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 6 Dec 2022 10:37:06 +0000 Subject: [PATCH] refactor: simplify display attributes helpers and update tests --- app/helpers/locations_helper.rb | 8 ++++---- app/views/locations/check_answers.html.erb | 6 +++--- spec/helpers/locations_helper_spec.rb | 2 +- spec/requests/locations_controller_spec.rb | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 6715865d2..2007e6ee4 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -32,7 +32,7 @@ module LocationsHelper { name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" }, { name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" }, { name: "Code", value: location.location_code, attribute: "location_code" }, - { name: "Availability", value: location_availability(location), attribute: "startdate" }, + { name: "Availability", value: location_availability(location), attribute: "availability" }, ] if FeatureToggle.location_toggle_enabled? @@ -50,7 +50,7 @@ module LocationsHelper { 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: "Availability", value: location&.startdate&.to_formatted_s(:govuk_date), attribute: "startdate" }, + { name: "Availability", value: location&.startdate&.to_formatted_s(:govuk_date), attribute: "availability" }, ] end @@ -65,8 +65,8 @@ module LocationsHelper availability.strip end - def location_edit_path(location, page) - send("scheme_location_#{page}_path", location.scheme, location, referrer: "check_answers", route: params[:route]) + def location_edit_path(location, attribute) + send("scheme_location_#{attribute}_path", location.scheme, location, referrer: "check_answers", route: params[:route]) end def action_text_helper(attr, location) diff --git a/app/views/locations/check_answers.html.erb b/app/views/locations/check_answers.html.erb index 217cf3dba..666820b6f 100644 --- a/app/views/locations/check_answers.html.erb +++ b/app/views/locations/check_answers.html.erb @@ -21,7 +21,7 @@ <% display_location_attributes_for_check_answers(@location).each do |attr| %> <%= summary_list.row do |row| %> <% row.key { attr[:name] } %> - <% row.value { details_html(attr) } %> + <% row.value { details_html(attr) } %> <% row.action(text: action_text_helper(attr, @location), href: location_edit_path(@location, attr[:attribute]))%> <% end %> <% end %> @@ -29,8 +29,8 @@
- <% if @location.incomplete? %> - <%= govuk_button_to "Add this location", scheme_location_confirm_path(@scheme, @location, route: params[:route])), method: :patch %> + <% if !@location.incomplete? %> + <%= govuk_button_to "Add this location", scheme_location_confirm_path(@scheme, @location, route: params[:route]), method: :patch %> <% end %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index 164fe79ae..d55d584a7 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -140,7 +140,7 @@ RSpec.describe LocationsHelper do attributes = [ { attribute: "postcode", name: "Postcode", value: location.postcode }, { attribute: "name", name: "Location name", value: location.name }, - { attribute: "location_admin_district", name: "Local authority", value: location.location_admin_district }, + { attribute: "local_authority", name: "Local authority", value: location.location_admin_district }, { 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 }, diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 3996e8f41..07958b46f 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1260,7 +1260,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location: { confirmed: true } } } before do - patch "/schemes/#{scheme.id}/locations/#{location.id}/check-answers", params: + patch "/schemes/#{scheme.id}/locations/#{location.id}/confirm", params: end it "confirms location" do @@ -1305,7 +1305,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location: { confirmed: true } } } before do - patch "/schemes/#{scheme.id}/locations/#{location.id}/check-answers", params: + patch "/schemes/#{scheme.id}/locations/#{location.id}/confirm", params: end it "confirms location" do