diff --git a/app/models/location.rb b/app/models/location.rb
index af7cb1365..bfe9f77a4 100644
--- a/app/models/location.rb
+++ b/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]
diff --git a/app/views/locations/check_answers.html.erb b/app/views/locations/check_answers.html.erb
index fdc9796a5..7d45eb158 100644
--- a/app/views/locations/check_answers.html.erb
+++ b/app/views/locations/check_answers.html.erb
@@ -18,11 +18,20 @@
<%= govuk_summary_list do |summary_list| %>
<% display_location_attributes_for_check_answers(@location).each do |attr| %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name] } %>
- <% row.value { details_html(attr) } %>
- <% if LocationPolicy.new(current_user, @location).update? %>
- <% row.action(text: action_text_helper(attr, @location), href: location_edit_path(@location, attr[:attribute])) %>
+ <% 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) %>
+ <%= formatted_local_authority_timeline(@location) %>
+ <% 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 %>
diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb
index f4371213c..54758b00f 100644
--- a/app/views/locations/show.html.erb
+++ b/app/views/locations/show.html.erb
@@ -15,18 +15,29 @@
<%= govuk_summary_list do |summary_list| %>
<% display_location_attributes(@location).each do |attr| %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name] } %>
- <% row.value { attr[:attribute].eql?("status") ? status_tag_from_resource(@location) : details_html(attr) } %>
- <% 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" %>
- <% row.action(text: "Change", href: scheme_location_units_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "units" && current_user.support? %>
- <% row.action(text: "Change", href: scheme_location_type_of_unit_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "type_of_unit" && current_user.support? %>
- <% row.action(text: "Change", href: scheme_location_mobility_standards_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "mobility_standards" && current_user.support? %>
+ <% unless attr[:attribute].eql?("local_authority") && @location.is_la_inferred %>
+ <%= summary_list.row do |row| %>
+ <% row.key { attr[:name] } %>
+ <% 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) %>
+ <%= formatted_local_authority_timeline(@location) %>
+ <% 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" %>
+ <% row.action(text: "Change", href: scheme_location_units_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "units" && current_user.support? %>
+ <% row.action(text: "Change", href: scheme_location_type_of_unit_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "type_of_unit" && current_user.support? %>
+ <% row.action(text: "Change", href: scheme_location_mobility_standards_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "mobility_standards" && current_user.support? %>
+ <% end %>
<% end %>
<% end %>
- <% end %>
+ <% end %>
<% end %>
diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb
index 68474124a..996dd3de0 100644
--- a/spec/requests/locations_controller_spec.rb
+++ b/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