Browse Source

Display inferred local authority

pull/2098/head
Kat 2 years ago
parent
commit
db5bd7f27f
  1. 1
      app/models/location.rb
  2. 9
      app/views/locations/check_answers.html.erb
  3. 13
      app/views/locations/show.html.erb
  4. 36
      spec/requests/locations_controller_spec.rb

1
app/models/location.rb

@ -199,6 +199,7 @@ private
unless location_admin_district_changed?
self.location_admin_district = nil
self.location_code = nil
self.is_la_inferred = false
end
if result
self.location_code = result[:location_code]

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

@ -18,15 +18,24 @@
<div class="govuk-grid-column-two-thirds-from-desktop">
<%= govuk_summary_list do |summary_list| %>
<% display_location_attributes_for_check_answers(@location).each do |attr| %>
<% unless attr[:attribute].eql?("local_authority") && @location.is_la_inferred %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% if attr[:attribute].eql?("postcode") && @location.is_la_inferred %>
<% row.value do %>
<%= details_html(attr) %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= formatted_local_authority_timeline(@location) %></span>
<% end %>
<% else %>
<% row.value { details_html(attr) } %>
<% end %>
<% if LocationPolicy.new(current_user, @location).update? %>
<% row.action(text: action_text_helper(attr, @location), href: location_edit_path(@location, attr[:attribute])) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</div>
</div>

13
app/views/locations/show.html.erb

@ -15,9 +15,19 @@
<%= govuk_summary_list do |summary_list| %>
<% display_location_attributes(@location).each do |attr| %>
<% unless attr[:attribute].eql?("local_authority") && @location.is_la_inferred %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value { attr[:attribute].eql?("status") ? status_tag_from_resource(@location) : details_html(attr) } %>
<% if attr[:attribute].eql?("status") %>
<%= row.value { status_tag_from_resource(@location) } %>
<% elsif attr[:attribute].eql?("postcode") && @location.is_la_inferred %>
<% row.value do %>
<%= details_html(attr) %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= formatted_local_authority_timeline(@location) %></span>
<% end %>
<% else %>
<%= row.value { details_html(attr) } %>
<% end %>
<% if LocationPolicy.new(current_user, @location).update? %>
<% row.action(text: "Change", href: scheme_location_postcode_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "postcode" && current_user.support? %>
<% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %>
@ -28,6 +38,7 @@
<% end %>
<% end %>
<% end %>
<% end %>
</div>
</div>

36
spec/requests/locations_controller_spec.rb

@ -466,7 +466,7 @@ RSpec.describe LocationsController, type: :request do
it "redirects correctly when postcodes.io does return a local authority" do
follow_redirect!
expect(page).to have_content("What is the local authority")
expect(page).to have_content("What is the name of this location")
end
end
@ -527,7 +527,7 @@ RSpec.describe LocationsController, type: :request do
it "redirects correctly when postcodes.io does return a local authority" do
follow_redirect!
expect(page).to have_content("What is the local authority")
expect(page).to have_content("What is the name of this location")
end
end
@ -1344,6 +1344,38 @@ RSpec.describe LocationsController, type: :request do
expect(page).not_to have_content("added to this scheme")
end
end
context "when local authority is inferred" do
let(:params) { { location: { postcode: "zz1 1zz" } } }
before do
patch "/schemes/#{scheme.id}/locations/#{location.id}/postcode?referrer=check_answers", params:
end
it "does not display local authority row" do
location.reload
follow_redirect!
expect(location.is_la_inferred).to eq(true)
expect(location.location_admin_district).to eq("Westminster")
expect(page).not_to have_content("Local authority")
expect(page).to have_content("Westminster")
end
end
context "when local authority is not inferred" do
let(:params) { { location: { postcode: "a1 1aa" } } }
before do
patch "/schemes/#{scheme.id}/locations/#{location.id}/postcode?referrer=check_answers", params:
end
it "displays local authority row" do
location.reload
get "/schemes/#{scheme.id}/locations/#{location.id}/check-answers"
expect(location.is_la_inferred).to eq(false)
expect(page).to have_content("Local authority")
end
end
end
context "when trying to edit check_answers of location that belongs to another organisation" do

Loading…
Cancel
Save