Browse Source

CLDC-1666 Update locations table (#987)

* feat: remove redundant cols from locations table

* feat: add status col to locations table

* test: start adding status tag tests

* test: pick the simplest format for the tag helper tests

* feat: make the locations table (plus related content above & below) 2/3 width

* feat: add incomplete to location status method

* test: all status tag helpers

* test: update test text to match what's being tested

* test: update locations list test in locations_controller_spec.rb

* test: update locations list test in schemes feature tests

* test: that status=incomplete when mandatory info is missing

* feat: simplify logic for incomplete status

Co-authored-by: James Rose <james@jbpr.net>

* feat: hide new locations table layout behind feature flag

* feat: use route helpers to get scheme_location path

* feat: simplify "scheme_id: @scheme.id" to "@scheme"

* feat: reference location, not @location, in scheme_location_path

* feat: reorder postcode and code in locations table

* feat: change ' ' to "" in location_spec

* feat: update wording and ordering for 'view location details' page

* test: re-add tests for locations page when new layout not enabled

* test: check for mobility_type and location_admin_district in locations_controller as support user

* test: update locations helper test to match new field naming and ordering

* feat: always scale locations list by 2/3, not just when new layout used

* feat: scale the scheme details page by 2/3 to match the locations list page

* feat: only make scheme details and locations pages 2/3 scale if feature toggle on

* test: mock new locations layout feature toggle in tests

* feat: use the existing location_toggle_enabled instead of new_locations_table_layout_enabled

* refactor: don't use html inside ruby in locations index page

* refactor: use Rails routes in all places in locations index page

* style: lint

* feat: move logic from views/schemes/show into schemes_helper

* refactor: make consistent the removal of fields from SchemeHelper base_attributes

* test: improvements to tests

* test: make 'returns correct display attributes' tests sensible

* test: check scheme toggle off => no scheme status shown

* style: correct indentation in spec/helpers/schemes_helper_spec.rb

* test: that when owning = managing, "Organisation providing support" hidden

* style: lint code

* test: don't set scheme id explicitly in schemes_helper_spec

* style: reorder tag helper spec to match tag helper

* refactor: ensure display_scheme_attributes always takes user type

* test: make location incomplete status depend on location.confirmed

* test: add missing location validations for nil postcode & mobility type

Co-authored-by: James Rose <james@jbpr.net>
pull/1039/head
SamSeed-Softwire 2 years ago committed by GitHub
parent
commit
a62846c212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/helpers/locations_helper.rb
  2. 10
      app/helpers/schemes_helper.rb
  3. 1
      app/models/location.rb
  4. 65
      app/views/locations/index.html.erb
  5. 22
      app/views/schemes/show.html.erb
  6. 18
      spec/features/schemes_spec.rb
  7. 4
      spec/helpers/locations_helper_spec.rb
  8. 105
      spec/helpers/schemes_helper_spec.rb
  9. 9
      spec/helpers/tag_helper_spec.rb
  10. 27
      spec/models/location_spec.rb
  11. 32
      spec/requests/locations_controller_spec.rb

4
app/helpers/locations_helper.rb

@ -26,12 +26,12 @@ module LocationsHelper
def display_location_attributes(location)
base_attributes = [
{ name: "Postcode", value: location.postcode },
{ name: "Local authority", value: location.location_admin_district },
{ name: "Location name", value: location.name, edit: true },
{ name: "Local authority", value: location.location_admin_district },
{ name: "Total number of units at this location", value: location.units },
{ name: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code },
{ name: "Location code", value: location.location_code },
{ name: "Availability", value: location_availability(location) },
]

10
app/helpers/schemes_helper.rb

@ -1,5 +1,5 @@
module SchemesHelper
def display_scheme_attributes(scheme)
def display_scheme_attributes(scheme, user)
base_attributes = [
{ name: "Scheme code", value: scheme.id_to_display },
{ name: "Name", value: scheme.service_name, edit: true },
@ -18,11 +18,15 @@ module SchemesHelper
]
if FeatureToggle.scheme_toggle_enabled?
base_attributes.append({ name: "Status", value: scheme.status })
base_attributes.append({ name: "Status", value: status_tag(scheme.status) })
end
if user.data_coordinator?
base_attributes.delete_if { |item| item[:name] == "Housing stock owned by" }
end
if scheme.arrangement_type_same?
base_attributes.delete({ name: "Organisation providing support", value: scheme.managing_organisation&.name })
base_attributes.delete_if { |item| item[:name] == "Organisation providing support" }
end
base_attributes
end

1
app/models/location.rb

@ -384,6 +384,7 @@ class Location < ApplicationRecord
end
def status(date = Time.zone.now)
return :incomplete unless confirmed
return :deactivated if open_deactivation&.deactivation_date.present? && date >= open_deactivation.deactivation_date
return :deactivating_soon if open_deactivation&.deactivation_date.present? && date < open_deactivation.deactivation_date
return :reactivating_soon if recent_deactivation&.reactivation_date.present? && date < recent_deactivation.reactivation_date

65
app/views/locations/index.html.erb

@ -11,15 +11,58 @@
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %>
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, "Locations")) %>
<% if FeatureToggle.location_toggle_enabled? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<% end %>
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, "Locations")) %>
<h2 class="govuk-visually-hidden">Locations</h2>
<h2 class="govuk-visually-hidden">Locations</h2>
<%= render SearchComponent.new(current_user:, search_label: "Search by location name or postcode", value: @searched) %>
<%= render SearchComponent.new(current_user:, search_label: "Search by location name or postcode", value: @searched) %>
<%= govuk_section_break(visible: true, size: "m") %>
<% if FeatureToggle.location_toggle_enabled? %>
</div>
</div>
<% end %>
<%= govuk_section_break(visible: true, size: "m") %>
<% if FeatureToggle.location_toggle_enabled? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched: @searched, count: @pagy.count, item_label:, total_count: @total_count, item: "locations", path: request.path)) %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Postcode", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Location code", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Status", html_attributes: {
scope: "col",
}) %>
<% end %>
<% end %>
<% @locations.each do |location| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: simple_format(location_cell_postcode(location, scheme_location_path(@scheme, location)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.id) %>
<% row.cell(text: status_tag(location.status)) %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= govuk_button_link_to "Add a location", new_scheme_location_path(@scheme), secondary: true %>
</div>
</div>
<%= govuk_table do |table| %>
<% else %>
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched: @searched, count: @pagy.count, item_label:, total_count: @total_count, item: "locations", path: request.path)) %>
<% end %>
@ -52,16 +95,20 @@
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell_postcode(location, "/schemes/#{@scheme.id}/locations/#{location.id}"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: simple_format(location_cell_postcode(location, scheme_location_path(@scheme, location)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell do %>
<span><%= simple_format(location.type_of_unit) %></span>
<% end %>
<% row.cell(text: location.mobility_type) %>
<% row.cell(text: simple_format(location_cell_location_admin_district(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-local-authority"), wrapper_tag: "div")) %>
<% row.cell(text: simple_format(location_cell_location_admin_district(location, scheme_location_edit_local_authority_path(@scheme, location)), wrapper_tag: "div")) %>
<% row.cell(text: location.startdate&.to_formatted_s(:govuk_date)) %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= govuk_button_link_to "Add a location", new_scheme_location_path(@scheme), secondary: true %>
<% end %>
<%= govuk_button_link_to "Add a location", new_scheme_location_path(scheme_id: @scheme.id), secondary: true %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %>

22
app/views/schemes/show.html.erb

@ -10,19 +10,27 @@
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %>
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, "Locations")) %>
<% if FeatureToggle.location_toggle_enabled? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<% end %>
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, "Locations")) %>
<h2 class="govuk-visually-hidden">Scheme</h2>
<h2 class="govuk-visually-hidden">Scheme</h2>
<%= govuk_summary_list do |summary_list| %>
<% display_scheme_attributes(@scheme).each do |attr| %>
<% next if current_user.data_coordinator? && attr[:name] == ("Housing stock owned by") %>
<%= govuk_summary_list do |summary_list| %>
<% display_scheme_attributes(@scheme, current_user).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].eql?("Registered under Care Standards Act 2000") ? "Registered under Care Standards Act 2000" : attr[:name].to_s.humanize } %>
<% row.value { attr[:name].eql?("Status") ? status_tag(attr[:value]) : details_html(attr) } %>
<% row.key { attr[:name] } %>
<% row.value { details_html(attr) } %>
<% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id)) if attr[:edit] %>
<% end %>
<% end %>
<% end %>
<% if FeatureToggle.location_toggle_enabled? %>
</div>
</div>
<% end %>
<% if FeatureToggle.scheme_toggle_enabled? %>

18
spec/features/schemes_spec.rb

@ -195,11 +195,27 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_link("Locations")
end
context "when I click locations link" do
context "when I click locations link and the new locations layout feature toggle is enabled" do
before do
click_link("Locations")
end
it "shows details of those locations" do
locations.each do |location|
expect(page).to have_content(location.id)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.name)
expect(page).to have_content("Active")
end
end
end
context "when I click locations link and the new locations layout feature toggle is disabled" do
before do
allow(FeatureToggle).to receive(:location_toggle_enabled?).and_return(false)
click_link("Locations")
end
it "shows details of those locations" do
locations.each do |location|
expect(page).to have_content(location.id)

4
spec/helpers/locations_helper_spec.rb

@ -139,12 +139,12 @@ RSpec.describe LocationsHelper do
it "returns correct display attributes" do
attributes = [
{ name: "Postcode", value: location.postcode },
{ name: "Local authority", value: location.location_admin_district },
{ name: "Location name", value: location.name, edit: true },
{ name: "Local authority", value: location.location_admin_district },
{ name: "Total number of units at this location", value: location.units },
{ name: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code },
{ name: "Location code", value: location.location_code },
{ name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: :active },
]

105
spec/helpers/schemes_helper_spec.rb

@ -87,40 +87,97 @@ RSpec.describe SchemesHelper do
end
end
include TagHelper
describe "display_scheme_attributes" do
let!(:scheme) { FactoryBot.create(:scheme, created_at: Time.zone.local(2022, 4, 1)) }
let(:owning_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Owning") }
let(:managing_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Managing") }
let!(:scheme) do
FactoryBot.create(:scheme,
service_name: "Test service_name",
sensitive: 0,
scheme_type: 7,
registered_under_care_act: 3,
owning_organisation:,
managing_organisation:,
arrangement_type: "V",
primary_client_group: "S",
has_other_client_group: 1,
secondary_client_group: "I",
support_type: 4,
intended_stay: "P",
created_at: Time.zone.local(2022, 4, 1))
end
let!(:scheme_where_managing_organisation_is_owning_organisation) { FactoryBot.create(:scheme, arrangement_type: "D") }
let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) }
it "returns correct display attributes for a support user" do
attributes = [
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Organisation providing support", value: "Acme LTD Managing" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: status_tag(:active) },
]
expect(display_scheme_attributes(scheme, support_user)).to eq(attributes)
end
it "returns correct display attributes" do
it "returns correct display attributes for a coordinator user" do
attributes = [
{ name: "Scheme code", value: scheme.id_to_display },
{ name: "Name", value: scheme.service_name, edit: true },
{ name: "Confidential information", value: scheme.sensitive, edit: true },
{ name: "Type of scheme", value: scheme.scheme_type },
{ name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act },
{ name: "Housing stock owned by", value: scheme.owning_organisation.name, edit: true },
{ name: "Support services provided by", value: scheme.arrangement_type },
{ name: "Primary client group", value: scheme.primary_client_group },
{ name: "Has another client group", value: scheme.has_other_client_group },
{ name: "Secondary client group", value: scheme.secondary_client_group },
{ name: "Level of support given", value: scheme.support_type },
{ name: "Intended length of stay", value: scheme.intended_stay },
{ name: "Scheme code", value: "S#{scheme.id}" },
{ name: "Name", value: "Test service_name", edit: true },
{ name: "Confidential information", value: "No", edit: true },
{ name: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" },
{ name: "Organisation providing support", value: "Acme LTD Managing" },
{ name: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" },
{ name: "Level of support given", value: "High level" },
{ name: "Intended length of stay", value: "Permanent" },
{ name: "Availability", value: "Active from 1 April 2022" },
{ name: "Status", value: :active },
{ name: "Status", value: status_tag(:active) },
]
expect(display_scheme_attributes(scheme)).to eq(attributes)
expect(display_scheme_attributes(scheme, coordinator_user)).to eq(attributes)
end
context "when the scheme toggle is disabled" do
it "doesn't show the scheme status" do
allow(FeatureToggle).to receive(:scheme_toggle_enabled?).and_return(false)
attributes = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Status" }
expect(attributes).to be_nil
end
end
context "when the managing organisation is the owning organisation" do
it "doesn't show the organisation providing support" do
attributes = display_scheme_attributes(scheme_where_managing_organisation_is_owning_organisation, support_user).find { |x| x[:name] == "Organisation providing support" }
expect(attributes).to be_nil
end
end
context "when viewing availability" do
context "with no deactivations" do
it "displays created_at as availability date" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from #{scheme.created_at.to_formatted_s(:govuk_date)}")
end
it "displays current collection start date as availability date if created_at is later than collection start date" do
scheme.update!(created_at: Time.zone.local(2022, 4, 16))
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022")
end
@ -135,7 +192,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022")
end
@ -149,7 +206,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
end
@ -165,7 +222,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022")
end
@ -179,7 +236,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022")
end
@ -196,7 +253,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022")
end
@ -211,7 +268,7 @@ RSpec.describe SchemesHelper do
end
it "displays the timeline of availability" do
availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
availability_attribute = display_scheme_attributes(scheme, support_user).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
end

9
spec/helpers/tag_helper_spec.rb

@ -11,6 +11,15 @@ RSpec.describe TagHelper do
it "returns tag with correct status text and colour and custom class" do
expect(status_tag("not_started", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--grey app-tag--small\">Not started</strong>")
expect(status_tag("cannot_start_yet", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--grey app-tag--small\">Cannot start yet</strong>")
expect(status_tag("in_progress", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--blue app-tag--small\">In progress</strong>")
expect(status_tag("completed", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--green app-tag--small\">Completed</strong>")
expect(status_tag("active", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--green app-tag--small\">Active</strong>")
expect(status_tag("incomplete", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--red app-tag--small\">Incomplete</strong>")
expect(status_tag("deactivating_soon", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--yellow app-tag--small\">Deactivating soon</strong>")
expect(status_tag("activating_soon", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--blue app-tag--small\">Activating soon</strong>")
expect(status_tag("reactivating_soon", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--blue app-tag--small\">Reactivating soon</strong>")
expect(status_tag("deactivated", "app-tag--small")).to eq("<strong class=\"govuk-tag govuk-tag--grey app-tag--small\">Deactivated</strong>")
end
end
end

27
spec/models/location_spec.rb

@ -34,12 +34,18 @@ RSpec.describe Location, type: :model do
expect { location.save! }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode #{I18n.t('validations.postcode')}")
end
it "does add an error when the postcode is missing" do
location.postcode = nil
expect { location.save! }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode #{I18n.t('validations.postcode')}")
end
end
describe "#units" do
let(:location) { FactoryBot.build(:location) }
it "does add an error when the postcode is invalid" do
it "does add an error when the number of units is invalid" do
location.units = nil
expect { location.save! }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Units #{I18n.t('activerecord.errors.models.location.attributes.units.blank')}")
@ -49,13 +55,23 @@ RSpec.describe Location, type: :model do
describe "#type_of_unit" do
let(:location) { FactoryBot.build(:location) }
it "does add an error when the postcode is invalid" do
it "does add an error when the type of unit is invalid" do
location.type_of_unit = nil
expect { location.save! }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Type of unit #{I18n.t('activerecord.errors.models.location.attributes.type_of_unit.blank')}")
end
end
describe "#mobility_type" do
let(:location) { FactoryBot.build(:location) }
it "does add an error when the mobility type is invalid" do
location.mobility_type = nil
expect { location.save! }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Mobility type #{I18n.t('activerecord.errors.models.location.attributes.mobility_type.blank')}")
end
end
describe "paper trail" do
let(:location) { FactoryBot.create(:location) }
let!(:name) { location.name }
@ -123,6 +139,13 @@ RSpec.describe Location, type: :model do
Timecop.unfreeze
end
context "when location is not confirmed" do
it "returns incomplete " do
location.confirmed = false
expect(location.status).to eq(:incomplete)
end
end
context "when there have not been any previous deactivations" do
it "returns active if the location has no deactivation records" do
expect(location.status).to eq(:active)

32
spec/requests/locations_controller_spec.rb

@ -867,14 +867,25 @@ RSpec.describe LocationsController, type: :request do
end
end
it "shows scheme" do
it "shows locations with correct data wben the new locations layout feature toggle is enabled" do
locations.each do |location|
expect(page).to have_content(location.id)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.name)
expect(page).to have_content(location.status)
end
end
it "shows locations with correct data wben the new locations layout feature toggle is disabled" do
allow(FeatureToggle).to receive(:location_toggle_enabled?).and_return(false)
get "/schemes/#{scheme.id}/locations"
locations.each do |location|
expect(page).to have_content(location.id)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.mobility_type)
expect(page).to have_content(location.location_admin_district)
expect(page).to have_content(location.startdate.to_formatted_s(:govuk_date))
expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date))
end
end
@ -972,12 +983,25 @@ RSpec.describe LocationsController, type: :request do
get "/schemes/#{scheme.id}/locations"
end
it "shows scheme" do
it "shows locations with correct data wben the new locations layout feature toggle is enabled" do
locations.each do |location|
expect(page).to have_content(location.id)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.name)
expect(page).to have_content(location.status)
end
end
it "shows locations with correct data wben the new locations layout feature toggle is disabled" do
allow(FeatureToggle).to receive(:location_toggle_enabled?).and_return(false)
get "/schemes/#{scheme.id}/locations"
locations.each do |location|
expect(page).to have_content(location.id)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.startdate.to_formatted_s(:govuk_date))
expect(page).to have_content(location.mobility_type)
expect(page).to have_content(location.location_admin_district)
expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date))
end
end

Loading…
Cancel
Save