Browse Source

refactor: simplify display attributes helpers and update tests

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
947f7e1afe
  1. 8
      app/helpers/locations_helper.rb
  2. 4
      app/views/locations/check_answers.html.erb
  3. 2
      spec/helpers/locations_helper_spec.rb
  4. 4
      spec/requests/locations_controller_spec.rb

8
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)

4
app/views/locations/check_answers.html.erb

@ -29,8 +29,8 @@
</div>
</div>
<div class="govuk-button-group">
<% 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 %>
</div>

2
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 },

4
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

Loading…
Cancel
Save