31 changed files with 1659 additions and 411 deletions
@ -0,0 +1,67 @@
|
||||
class LocationsController < ApplicationController |
||||
include Pagy::Backend |
||||
before_action :authenticate_user! |
||||
before_action :authenticate_scope! |
||||
before_action :find_location, except: %i[new create index] |
||||
before_action :find_scheme |
||||
before_action :authenticate_action! |
||||
|
||||
def index |
||||
@pagy, @locations = pagy(@scheme.locations) |
||||
@total_count = @scheme.locations.size |
||||
end |
||||
|
||||
def new |
||||
@location = Location.new |
||||
end |
||||
|
||||
def create |
||||
@location = Location.new(location_params) |
||||
|
||||
if @location.save |
||||
location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(id: @scheme.id)) : redirect_to(scheme_check_answers_path(scheme_id: @scheme.id)) |
||||
else |
||||
render :new, status: :unprocessable_entity |
||||
end |
||||
end |
||||
|
||||
def edit; end |
||||
|
||||
def update |
||||
if @location.update(location_params) |
||||
location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(@location.scheme)) : redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) |
||||
else |
||||
render :edit, status: :unprocessable_entity |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def find_scheme |
||||
@scheme = if %w[new create index].include?(action_name) |
||||
Scheme.find(params[:id]) |
||||
else |
||||
@location.scheme |
||||
end |
||||
end |
||||
|
||||
def find_location |
||||
@location = Location.find(params[:id]) |
||||
end |
||||
|
||||
def authenticate_scope! |
||||
head :unauthorized and return unless current_user.data_coordinator? || current_user.support? |
||||
end |
||||
|
||||
def authenticate_action! |
||||
if %w[new edit update create index].include?(action_name) && !((current_user.organisation == @scheme.organisation) || current_user.support?) |
||||
render_not_found and return |
||||
end |
||||
end |
||||
|
||||
def location_params |
||||
required_params = params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id) |
||||
required_params[:postcode] = required_params[:postcode].delete(" ").upcase.encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: "") if required_params[:postcode] |
||||
required_params |
||||
end |
||||
end |
@ -0,0 +1,63 @@
|
||||
<% content_for :title, "Add a location to this scheme" %> |
||||
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link( |
||||
text: "Back", |
||||
href: "/schemes/#{@scheme.id}/support", |
||||
) %> |
||||
<% end %> |
||||
|
||||
<%= render partial: "organisations/headings", locals: { main: "Add a location to this scheme", sub: @scheme.service_name } %> |
||||
|
||||
<%= form_for(@location, method: :patch, url: location_path) do |f| %> |
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<%= f.govuk_error_summary %> |
||||
|
||||
<%= f.govuk_text_field :postcode, |
||||
label: { size: "m" }, |
||||
hint: { text: "For example, SW1P 4DF." }, |
||||
width: 5 %> |
||||
|
||||
<%= f.govuk_text_field :name, |
||||
label: { text: "Name (optional)", size: "m" }, |
||||
hint: { text: "This is how you refer to this location within your organisation" } %> |
||||
|
||||
<%= f.govuk_number_field :total_units, |
||||
label: { text: "Total number of units at this location", size: "m" }, |
||||
width: 2, |
||||
hint: { text: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff.s" }, |
||||
autofocus: true %> |
||||
|
||||
<% type_of_units_selection = Location.type_of_units.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :type_of_unit, |
||||
type_of_units_selection, |
||||
:id, |
||||
:name, |
||||
legend: { text: "What is this type of scheme?", size: "m" } %> |
||||
|
||||
<% wheelchair_user_selection = Location.wheelchair_adaptations.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :wheelchair_adaptation, |
||||
wheelchair_user_selection, |
||||
:id, |
||||
:name, |
||||
hint: { text: "This includes stairlifts, ramps, level-access showers or grab rails" }, |
||||
legend: { text: "Are the majority of units in this location built or adapted to wheelchair-user standards?", size: "m" } %> |
||||
|
||||
<%= govuk_section_break(visible: true, size: "m") %> |
||||
|
||||
<% another_location_selection = %w[Yes no].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :add_another_location, |
||||
another_location_selection, |
||||
:id, |
||||
:name, |
||||
inline: true, |
||||
legend: { text: "Do you want to add another location?", size: "m" } %> |
||||
|
||||
<%= f.govuk_submit "Save and continue" %> |
||||
</div> |
||||
</div> |
||||
<% end %> |
@ -0,0 +1,49 @@
|
||||
<% title = @scheme.service_name %> |
||||
<% content_for :title, title %> |
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link( |
||||
text: "Back", |
||||
href: "/schemes/#{@scheme.id}", |
||||
) %> |
||||
<% end %> |
||||
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %> |
||||
<% location_caption = @scheme.locations.count.eql?(1) ? "1 location" : "#{@scheme.locations.count} locations" %> |
||||
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, location_caption)) %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-three-quarters"> |
||||
<%= govuk_table do |table| %> |
||||
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> |
||||
<strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>. |
||||
<% end %> |
||||
<%= table.head do |head| %> |
||||
<%= head.row do |row| %> |
||||
<% row.cell(header: true, text: "Code", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% row.cell(header: true, text: "Postcode", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% row.cell(header: true, text: "Units", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% row.cell(header: true, text: "Common unit type", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @locations.each do |location| %> |
||||
<%= table.body do |body| %> |
||||
<%= body.row do |row| %> |
||||
<% row.cell(text: location.id) %> |
||||
<% row.cell(text: location.postcode) %> |
||||
<% row.cell(text: location.total_units) %> |
||||
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
</div> |
||||
</div> |
||||
|
||||
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %> |
@ -0,0 +1,63 @@
|
||||
<% content_for :title, "Add a location to this scheme" %> |
||||
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link( |
||||
text: "Back", |
||||
href: "/schemes/#{@scheme.id}/support", |
||||
) %> |
||||
<% end %> |
||||
|
||||
<%= render partial: "organisations/headings", locals: { main: "Add a location to this scheme", sub: @scheme.service_name } %> |
||||
|
||||
<%= form_for(@location, method: :post, url: locations_path) do |f| %> |
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<%= f.govuk_error_summary %> |
||||
|
||||
<%= f.govuk_text_field :postcode, |
||||
label: { size: "m" }, |
||||
hint: { text: "For example, SW1P 4DF." }, |
||||
width: 5 %> |
||||
|
||||
<%= f.govuk_text_field :name, |
||||
label: { text: "Name (optional)", size: "m" }, |
||||
hint: { text: "This is how you refer to this location within your organisation" } %> |
||||
|
||||
<%= f.govuk_number_field :total_units, |
||||
label: { text: "Total number of units at this location", size: "m" }, |
||||
width: 2, |
||||
hint: { text: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff.s" }, |
||||
autofocus: true %> |
||||
|
||||
<% type_of_units_selection = Location.type_of_units.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :type_of_unit, |
||||
type_of_units_selection, |
||||
:id, |
||||
:name, |
||||
legend: { text: "What is this type of scheme?", size: "m" } %> |
||||
|
||||
<% wheelchair_user_selection = Location.wheelchair_adaptations.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :wheelchair_adaptation, |
||||
wheelchair_user_selection, |
||||
:id, |
||||
:name, |
||||
hint: { text: "This includes stairlifts, ramps, level-access showers or grab rails" }, |
||||
legend: { text: "Are the majority of units in this location built or adapted to wheelchair-user standards?", size: "m" } %> |
||||
|
||||
<%= govuk_section_break(visible: true, size: "m") %> |
||||
|
||||
<% another_location_selection = %w[Yes No].map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> |
||||
|
||||
<%= f.govuk_collection_radio_buttons :add_another_location, |
||||
another_location_selection, |
||||
:id, |
||||
:name, |
||||
inline: true, |
||||
legend: { text: "Do you want to add another location?", size: "m" } %> |
||||
|
||||
<%= f.govuk_submit "Save and continue" %> |
||||
</div> |
||||
</div> |
||||
<% end %> |
@ -1,65 +1,105 @@
|
||||
<% content_for :title, "Check your answers before creating this scheme" %> |
||||
|
||||
<%= render partial: "organisations/headings", locals: { main: "Check your changes before updating this scheme", sub: @scheme.service_name } %> |
||||
<%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %> |
||||
|
||||
<%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %> |
||||
<% component.tab(label: "Scheme") do %> |
||||
<%= govuk_summary_list do |summary_list| %> |
||||
<% @scheme.check_details_attributes.each do |attr| %> |
||||
<% next if current_user.data_coordinator? && attr[:name] == ("Managed by") %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_details_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @scheme.check_primary_client_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_primary_client_group_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% if @scheme.has_other_client_group == "Yes" %> |
||||
<% @scheme.check_secondary_client_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% location_caption = @scheme.locations.count.eql?(1) ? "1 location" : "#{@scheme.locations.count} locations" %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-three-quarters-from-desktop"> |
||||
<%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %> |
||||
<% component.tab(label: "Scheme") do %> |
||||
<%= govuk_summary_list do |summary_list| %> |
||||
<% @scheme.check_details_attributes.each do |attr| %> |
||||
<% next if current_user.data_coordinator? && attr[:name] == ("Managed by") %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_details_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @scheme.check_primary_client_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_primary_client_group_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% if @scheme.has_other_client_group == "Yes" %> |
||||
<% @scheme.check_secondary_client_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @scheme.check_support_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_support_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @scheme.check_support_attributes.each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name].to_s } %> |
||||
<% row.value { details_html(attr) } %> |
||||
<% row.action( |
||||
text: "Change", |
||||
href: scheme_support_path(scheme_id: @scheme.id, check_answers: true), |
||||
) %> |
||||
<% component.tab(label: "Locations") do %> |
||||
<%= govuk_table do |table| %> |
||||
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> |
||||
<strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %> |
||||
<% end %> |
||||
<%= table.head do |head| %> |
||||
<%= head.row do |row| %> |
||||
<% row.cell(header: true, text: "Code", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% row.cell(header: true, text: "Postcode", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% row.cell(header: true, text: "Units", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% row.cell(header: true, text: "Common unit type", html_attributes: { |
||||
scope: "col", |
||||
}) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @scheme.locations.each do |location| %> |
||||
<%= table.body do |body| %> |
||||
<%= body.row do |row| %> |
||||
<% row.cell(text: location.id) %> |
||||
<% row.cell(text: simple_format(location_cell(location), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> |
||||
<% row.cell(text: location.total_units) %> |
||||
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<%= govuk_button_link_to "Add a location", new_location_path(id: @scheme.id), secondary: true %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
</div> |
||||
</div> |
||||
|
||||
<%= govuk_button_link_to "Create scheme", schemes_path(scheme_id: @scheme.id), html: { method: :get } %> |
||||
|
@ -1,46 +0,0 @@
|
||||
<% title = @scheme.service_name %> |
||||
<% content_for :title, title %> |
||||
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link( |
||||
text: "Back", |
||||
href: "/schemes/#{@scheme.id}", |
||||
) %> |
||||
<% end %> |
||||
|
||||
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %> |
||||
|
||||
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, @scheme.locations.count.eql?(1) ? "1 location" : "#{@scheme.locations.count} locations")) %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-three-quarters"> |
||||
<% @locations.each do |location| %> |
||||
<section class="x-govuk-summary-card govuk-!-margin-bottom-6"> |
||||
<header class="x-govuk-summary-card__header"> |
||||
<h2 class="x-govuk-summary-card__title"> |
||||
<%= location.name %> |
||||
</h2> |
||||
</header> |
||||
<div class="x-govuk-summary-card__body"> |
||||
<dl class="govuk-summary-list"> |
||||
<% location.display_attributes.each do |attribute| %> |
||||
<div class="govuk-summary-list__row"> |
||||
<dt class="govuk-summary-list__key"> |
||||
<%= attribute[:name] %> |
||||
</dt> |
||||
<dd class="govuk-summary-list__value app-!-font-tabular"> |
||||
<span class="govuk-!-margin-right-4"><%= attribute[:value] %></span> |
||||
<% if attribute[:suffix] %> |
||||
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= attribute[:suffix] %></span> |
||||
<% end %> |
||||
</dd> |
||||
</div> |
||||
<% end %> |
||||
</dl> |
||||
</div> |
||||
</section> |
||||
<% end %> |
||||
</div> |
||||
</div> |
||||
|
||||
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %> |
@ -0,0 +1,5 @@
|
||||
class AddNameToLocations < ActiveRecord::Migration[7.0] |
||||
change_table :locations, bulk: true do |t| |
||||
t.integer :total_units |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class RemoveTotalUnitsSchemes < ActiveRecord::Migration[7.0] |
||||
def change |
||||
remove_column :schemes, :total_units, :integer |
||||
end |
||||
end |
@ -0,0 +1,6 @@
|
||||
class ChangeLocationTypeOfUnit < ActiveRecord::Migration[7.0] |
||||
change_table :locations, bulk: true do |t| |
||||
t.remove :type_of_unit |
||||
t.integer :type_of_unit |
||||
end |
||||
end |
@ -1,5 +1,5 @@
|
||||
# Service overview |
||||
|
||||
All lettings and and sales of social housing in England need to be logged with the Department for levelling up, housing and communities (DLUHC). This is done by Local Authorities and Housing Associations, who are the primary users of this service. Data is collected via a form that runs on an annual data collection window basis. Form changes are made annually to add new questions, remove any that are no longer needed, or adjust wording or answer options etc. Each data collection window runs from 1st April to 1st April + an extra 3 months to allow for any late submissions, meaning that between April and July, two collection windows are open simultaneously and logs can be submitted for either. |
||||
All lettings and and sales of social housing in England need to be logged with the Department for levelling up, housing and communities (DLUHC). This is done by Local Authorities and Housing Associations, who are the primary users of this service. Data is collected via a form that runs on an annual data collection window basis. Form changes are made annually to add new questions, remove any that are no longer needed, or adjust wording or answer options etc. Each data collection window runs from 1st April to 1st April + an extra 3 months to allow for any late submissions, meaning that between April and June, two collection windows are open simultaneously and logs can be submitted for either. |
||||
|
||||
ADD (Analytics & Data Directorate) statisticians are the other primary users of the service. The data collected is transferred to DLUHCs data warehouse (CDS - consolidated data store), via nightly exports to XML which are transferred to S3 and ingested from there. CDS ingests and transforms the data, ultimately storing it in a MS SQL database and exposing it to analysts and statisticians via Amazon Workspaces. |
||||
|
@ -1,138 +1,186 @@
|
||||
{ |
||||
"case_log": { |
||||
"tenancycode": "T657", |
||||
"age1": 35, |
||||
"sex1": "F", |
||||
"ethnic": 0, |
||||
"national": 0, |
||||
"prevten": 6, |
||||
"armedforces": 1, |
||||
"armed_forces_partner": "", |
||||
"ecstat1": 1, |
||||
"hhmemb": 8, |
||||
"relat2": "P", |
||||
"age2": 32, |
||||
"sex2": "M", |
||||
"ecstat2": 6, |
||||
"relat3": "C", |
||||
"age3": 12, |
||||
"sex3": "M", |
||||
"ecstat3": 9, |
||||
"relat4": "C", |
||||
"age4": 12, |
||||
"sex4": "F", |
||||
"ecstat4": 9, |
||||
"relat5": "C", |
||||
"age5": 10, |
||||
"sex5": "X", |
||||
"ecstat5": 9, |
||||
"relat6": "C", |
||||
"age6": 5, |
||||
"sex6": "R", |
||||
"ecstat6": 9, |
||||
"age7": 5, |
||||
"sex7": "R", |
||||
"ecstat7": 9, |
||||
"relat8": "C", |
||||
"age8": 2, |
||||
"sex8": "R", |
||||
"ecstat8": 9, |
||||
"homeless": 2, |
||||
"reason": 1, |
||||
"underoccupation_benefitcap": 0, |
||||
"leftreg": 1, |
||||
"reservist": 0, |
||||
"illness": 1, |
||||
"preg_occ": 1, |
||||
"startdate": "12/12/2021", |
||||
"startertenancy": 0, |
||||
"tenancylength": 5, |
||||
"tenancy": 1, |
||||
"landlord": 1, |
||||
"previous_la_known": 1, |
||||
"la": "Barnet", |
||||
"postcode_full": "NW1 5TY", |
||||
"property_relet": 0, |
||||
"rsnvac": 14, |
||||
"property_reference": "P9876", |
||||
"unittype_gn": 7, |
||||
"property_building_type": "dummy", |
||||
"beds": 3, |
||||
"voiddate": "10/10/2020", |
||||
"majorrepairs": 1, |
||||
"mrcdate": "11/11/2020", |
||||
"offered": 2, |
||||
"wchair": 1, |
||||
"net_income_known": 1, |
||||
"earnings": 150, |
||||
"incfreq": 1, |
||||
"benefits": 1, |
||||
"hb": 1, |
||||
"period": 2, |
||||
"brent": 200, |
||||
"scharge": 50, |
||||
"pscharge": 40, |
||||
"supcharg": 35, |
||||
"tcharge": 325, |
||||
"outstanding_amount": 1, |
||||
"layear": 2, |
||||
"lawaitlist": 1, |
||||
"prevloc": "E07000105", |
||||
"ppostcode_full": "SE2 6RT", |
||||
"reasonpref": 1, |
||||
"cbl": 0, |
||||
"chr": 1, |
||||
"cap": 0, |
||||
"hbrentshortfall": 1, |
||||
"tshortfall": 12, |
||||
"reasonother": null, |
||||
"housingneeds_a": 1, |
||||
"housingneeds_b": 0, |
||||
"housingneeds_c": 0, |
||||
"housingneeds_f": 0, |
||||
"housingneeds_g": 0, |
||||
"housingneeds_h": 0, |
||||
"accessibility_requirements_prefer_not_to_say": 0, |
||||
"illness_type_1": 0, |
||||
"illness_type_2": 1, |
||||
"illness_type_3": 0, |
||||
"illness_type_4": 0, |
||||
"illness_type_8": 0, |
||||
"illness_type_5": 0, |
||||
"illness_type_6": 0, |
||||
"illness_type_7": 0, |
||||
"illness_type_9": 0, |
||||
"illness_type_10": 0, |
||||
"condition_effects_prefer_not_to_say": 1, |
||||
"rp_homeless": 0, |
||||
"rp_insan_unsat": 0, |
||||
"rp_medwel": 0, |
||||
"rp_hardship": 0, |
||||
"rp_dontknow": 0, |
||||
"discarded_at": "05/05/2020", |
||||
"net_income_value_check": 0, |
||||
"property_owner_organisation": "", |
||||
"property_manager_organisation": "", |
||||
"rent_type": 0, |
||||
"intermediate_rent_product_name": "", |
||||
"needstype": 1, |
||||
"sale_completion_date": "01/01/2020", |
||||
"purchaser_code": "", |
||||
"propcode": "123", |
||||
"postcode": "a1", |
||||
"postcod2": "w3", |
||||
"first_time_property_let_as_social_housing": 0, |
||||
"unitletas": 1, |
||||
"builtype": 0, |
||||
"property_wheelchair_accessible": 1, |
||||
"void_or_renewal_date": "05/05/2020", |
||||
"renewal": 0, |
||||
"new_build_handover_date": "01/01/2019", |
||||
"has_benefits": 1, |
||||
"household_charge": 0, |
||||
"is_carehome": 0, |
||||
"sheltered": 0, |
||||
"declaration": 1, |
||||
"referral": 1 |
||||
"tenancycode":"T1245", |
||||
"age1":34, |
||||
"sex1":"M", |
||||
"ethnic":1, |
||||
"national":1, |
||||
"prevten":3, |
||||
"ecstat1":1, |
||||
"hhmemb":3, |
||||
"age2":29, |
||||
"sex2":"F", |
||||
"ecstat2":2, |
||||
"age3":11, |
||||
"sex3":"R", |
||||
"ecstat3":9, |
||||
"age4":null, |
||||
"sex4":null, |
||||
"ecstat4":null, |
||||
"age5":null, |
||||
"sex5":null, |
||||
"ecstat5":null, |
||||
"age6":null, |
||||
"sex6":null, |
||||
"ecstat6":null, |
||||
"age7":null, |
||||
"sex7":null, |
||||
"ecstat7":null, |
||||
"age8":null, |
||||
"sex8":null, |
||||
"ecstat8":null, |
||||
"homeless":1, |
||||
"underoccupation_benefitcap":2, |
||||
"leftreg":null, |
||||
"reservist":null, |
||||
"illness":2, |
||||
"preg_occ":2, |
||||
"startertenancy":2, |
||||
"tenancylength":null, |
||||
"tenancy":2, |
||||
"ppostcode_full":"NW18TR", |
||||
"rsnvac":5, |
||||
"unittype_gn":7, |
||||
"beds":2, |
||||
"offered":0, |
||||
"wchair":1, |
||||
"earnings":190, |
||||
"incfreq":1, |
||||
"benefits":3, |
||||
"period":3, |
||||
"layear":7, |
||||
"waityear":2, |
||||
"postcode_full":"NW18EE", |
||||
"reasonpref":2, |
||||
"cbl":1, |
||||
"chr":0, |
||||
"cap":0, |
||||
"reasonother":"", |
||||
"housingneeds_a":0, |
||||
"housingneeds_b":0, |
||||
"housingneeds_c":1, |
||||
"housingneeds_f":0, |
||||
"housingneeds_g":0, |
||||
"housingneeds_h":0, |
||||
"illness_type_1":null, |
||||
"illness_type_2":null, |
||||
"illness_type_3":null, |
||||
"illness_type_4":null, |
||||
"illness_type_8":null, |
||||
"illness_type_5":null, |
||||
"illness_type_6":null, |
||||
"illness_type_7":null, |
||||
"illness_type_9":null, |
||||
"illness_type_10":null, |
||||
"rp_homeless":null, |
||||
"rp_insan_unsat":null, |
||||
"rp_medwel":null, |
||||
"rp_hardship":null, |
||||
"rp_dontknow":null, |
||||
"tenancyother":"", |
||||
"net_income_value_check":null, |
||||
"property_owner_organisation":null, |
||||
"property_manager_organisation":null, |
||||
"sale_or_letting":null, |
||||
"irproduct_other":"", |
||||
"purchaser_code":null, |
||||
"reason":42, |
||||
"propcode":"PT562", |
||||
"majorrepairs":1, |
||||
"la":"E09000007", |
||||
"prevloc":"E09000007", |
||||
"hb":9, |
||||
"hbrentshortfall":null, |
||||
"property_relet":null, |
||||
"mrcdate":"2021-05-07T00:00:00.000+01:00", |
||||
"incref":null, |
||||
"sale_completion_date":null, |
||||
"startdate":"2021-06-06T00:00:00.000+01:00", |
||||
"armedforces":2, |
||||
"first_time_property_let_as_social_housing":0, |
||||
"unitletas":1, |
||||
"builtype":1, |
||||
"voiddate":"2021-05-05T00:00:00.000+01:00", |
||||
"owning_organisation_id":1, |
||||
"managing_organisation_id":1, |
||||
"renttype":2, |
||||
"needstype":1, |
||||
"lettype":7, |
||||
"postcode_known":1, |
||||
"is_la_inferred":true, |
||||
"totchild":1, |
||||
"totelder":0, |
||||
"totadult":2, |
||||
"net_income_known":0, |
||||
"nocharge":0, |
||||
"is_carehome":null, |
||||
"household_charge":null, |
||||
"referral":2, |
||||
"brent":"350.0", |
||||
"scharge":"11.0", |
||||
"pscharge":"11.0", |
||||
"supcharg":"0.0", |
||||
"tcharge":"372.0", |
||||
"tshortfall":null, |
||||
"chcharge":null, |
||||
"declaration":1, |
||||
"ppcodenk":1, |
||||
"previous_la_known":null, |
||||
"is_previous_la_inferred":true, |
||||
"age1_known":0, |
||||
"age2_known":0, |
||||
"age3_known":0, |
||||
"age4_known":null, |
||||
"age5_known":null, |
||||
"age6_known":null, |
||||
"age7_known":null, |
||||
"age8_known":null, |
||||
"ethnic_group":0, |
||||
"ethnic_other":null, |
||||
"letting_allocation_unknown":0, |
||||
"details_known_2":0, |
||||
"details_known_3":0, |
||||
"details_known_4":null, |
||||
"details_known_5":null, |
||||
"details_known_6":null, |
||||
"details_known_7":null, |
||||
"details_known_8":null, |
||||
"rent_type":1, |
||||
"has_benefits":0, |
||||
"renewal":0, |
||||
"wrent":"87.5", |
||||
"wscharge":"2.75", |
||||
"wpschrge":"2.75", |
||||
"wsupchrg":"0.0", |
||||
"wtcharge":"93.0", |
||||
"wtshortfall":null, |
||||
"refused":1, |
||||
"housingneeds":2, |
||||
"wchchrg":null, |
||||
"newprop":2, |
||||
"relat2":"P", |
||||
"relat3":"C", |
||||
"relat4":null, |
||||
"relat5":null, |
||||
"relat6":null, |
||||
"relat7":null, |
||||
"relat8":null, |
||||
"rent_value_check":null, |
||||
"old_form_id":null, |
||||
"lar":null, |
||||
"irproduct":null, |
||||
"old_id":null, |
||||
"joint":null, |
||||
"created_by_id":2, |
||||
"illness_type_0":null, |
||||
"retirement_value_check":null, |
||||
"tshortfall_known":null, |
||||
"sheltered":null, |
||||
"pregnancy_value_check":null, |
||||
"hhtype":6, |
||||
"new_old":1, |
||||
"vacdays":30, |
||||
"scheme_id":null, |
||||
"location_id":null |
||||
} |
||||
} |
||||
|
@ -0,0 +1,27 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Location, type: :model do |
||||
describe "#new" do |
||||
let(:location) { FactoryBot.build(:location) } |
||||
|
||||
it "belongs to an organisation" do |
||||
expect(location.scheme).to be_a(Scheme) |
||||
end |
||||
end |
||||
|
||||
describe "#validate_postcode" do |
||||
let(:location) { FactoryBot.build(:location) } |
||||
|
||||
it "does not add an error if postcode is valid" do |
||||
location.postcode = "M1 1AE" |
||||
location.save! |
||||
expect(location.errors).to be_empty |
||||
end |
||||
|
||||
it "does add an error when the postcode is invalid" do |
||||
location.postcode = "invalid" |
||||
expect { location.save! } |
||||
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode Enter a postcode in the correct format, for example AA1 1AA") |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,784 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe LocationsController, type: :request do |
||||
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||
let(:user) { FactoryBot.create(:user, :support) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
|
||||
describe "#new" do |
||||
context "when not signed in" do |
||||
it "redirects to the sign in page" do |
||||
get "/schemes/1/locations/new" |
||||
expect(response).to redirect_to("/account/sign-in") |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data provider" do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
|
||||
before do |
||||
sign_in user |
||||
get "/schemes/1/locations/new" |
||||
end |
||||
|
||||
it "returns 401 unauthorized" do |
||||
request |
||||
expect(response).to have_http_status(:unauthorized) |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data coordinator" do |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
|
||||
before do |
||||
sign_in user |
||||
get "/schemes/#{scheme.id}/locations/new" |
||||
end |
||||
|
||||
it "returns a template for a new location" do |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
|
||||
context "when trying to new location to a scheme that belongs to another organisation" do |
||||
let(:another_scheme) { FactoryBot.create(:scheme) } |
||||
|
||||
it "displays the new page with an error message" do |
||||
get "/schemes/#{another_scheme.id}/locations/new" |
||||
expect(response).to have_http_status(:not_found) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a support user" do |
||||
before do |
||||
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||
sign_in user |
||||
get "/schemes/#{scheme.id}/locations/new" |
||||
end |
||||
|
||||
it "returns a template for a new location" do |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "#create" do |
||||
context "when not signed in" do |
||||
it "redirects to the sign in page" do |
||||
post "/schemes/1/locations" |
||||
expect(response).to redirect_to("/account/sign-in") |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data provider" do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
|
||||
before do |
||||
sign_in user |
||||
post "/schemes/1/locations" |
||||
end |
||||
|
||||
it "returns 401 unauthorized" do |
||||
request |
||||
expect(response).to have_http_status(:unauthorized) |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data coordinator" do |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
before do |
||||
sign_in user |
||||
post "/schemes/#{scheme.id}/locations", params: params |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your answers before creating this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
|
||||
context "when postcode is submitted with lower case" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } |
||||
|
||||
it "creates a new location for scheme with postcode " do |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
end |
||||
end |
||||
|
||||
context "when trying to add location to a scheme that belongs to another organisation" do |
||||
let(:another_scheme) { FactoryBot.create(:scheme) } |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "displays the new page with an error message" do |
||||
post "/schemes/#{another_scheme.id}/locations", params: params |
||||
expect(response).to have_http_status(:not_found) |
||||
end |
||||
end |
||||
|
||||
context "when required postcode param is missing" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } } |
||||
|
||||
it "displays the new page with an error message" do |
||||
expect(response).to have_http_status(:unprocessable_entity) |
||||
expect(page).to have_content(I18n.t("validations.postcode")) |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as yes" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as no" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is not selected" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a support user" do |
||||
let(:user) { FactoryBot.create(:user, :support) } |
||||
let!(:scheme) { FactoryBot.create(:scheme) } |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
before do |
||||
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||
sign_in user |
||||
post "/schemes/#{scheme.id}/locations", params: params |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your answers before creating this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
|
||||
context "when postcode is submitted with lower case" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } |
||||
|
||||
it "creates a new location for scheme with postcode " do |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
end |
||||
end |
||||
|
||||
context "when required postcode param is missing" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } } |
||||
|
||||
it "displays the new page with an error message" do |
||||
post "/schemes/#{scheme.id}/locations", params: params |
||||
expect(response).to have_http_status(:unprocessable_entity) |
||||
expect(page).to have_content(I18n.t("validations.postcode")) |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as yes" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as no" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is not selected" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "creates a new location for scheme with valid params and redirects to correct page" do |
||||
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "creates a new location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "#edit" do |
||||
context "when not signed in" do |
||||
it "redirects to the sign in page" do |
||||
get "/schemes/1/locations/1/edit" |
||||
expect(response).to redirect_to("/account/sign-in") |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data provider" do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
|
||||
before do |
||||
sign_in user |
||||
get "/schemes/1/locations/1/edit" |
||||
end |
||||
|
||||
it "returns 401 unauthorized" do |
||||
request |
||||
expect(response).to have_http_status(:unauthorized) |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data coordinator" do |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
let!(:location) { FactoryBot.create(:location, scheme:) } |
||||
|
||||
before do |
||||
sign_in user |
||||
get "/schemes/#{scheme.id}/locations/#{location.id}/edit" |
||||
end |
||||
|
||||
it "returns a template for a new location" do |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
|
||||
context "when trying to new location to a scheme that belongs to another organisation" do |
||||
let(:another_scheme) { FactoryBot.create(:scheme) } |
||||
let(:another_location) { FactoryBot.create(:location, scheme: another_scheme) } |
||||
|
||||
it "displays the new page with an error message" do |
||||
get "/schemes/#{another_scheme.id}/locations/#{another_location.id}/edit" |
||||
expect(response).to have_http_status(:not_found) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a support user" do |
||||
let(:user) { FactoryBot.create(:user, :support) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
let!(:location) { FactoryBot.create(:location, scheme:) } |
||||
|
||||
before do |
||||
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||
sign_in user |
||||
get "/schemes/#{scheme.id}/locations/#{location.id}/edit" |
||||
end |
||||
|
||||
it "returns a template for a new location" do |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "#update" do |
||||
context "when not signed in" do |
||||
it "redirects to the sign in page" do |
||||
patch "/schemes/1/locations/1" |
||||
expect(response).to redirect_to("/account/sign-in") |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data provider" do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
|
||||
before do |
||||
sign_in user |
||||
patch "/schemes/1/locations/1" |
||||
end |
||||
|
||||
it "returns 401 unauthorized" do |
||||
request |
||||
expect(response).to have_http_status(:unauthorized) |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data coordinator" do |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
let!(:location) { FactoryBot.create(:location, scheme:) } |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
before do |
||||
sign_in user |
||||
patch "/schemes/#{scheme.id}/locations/#{location.id}", params: params |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your answers before creating this scheme") |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
|
||||
context "when postcode is submitted with lower case" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } |
||||
|
||||
it "updates existing location for scheme with postcode " do |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
end |
||||
end |
||||
|
||||
context "when trying to update location for a scheme that belongs to another organisation" do |
||||
let(:another_scheme) { FactoryBot.create(:scheme) } |
||||
let(:another_location) { FactoryBot.create(:location) } |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "displays the new page with an error message" do |
||||
patch "/schemes/#{another_scheme.id}/locations/#{another_location.id}", params: params |
||||
expect(response).to have_http_status(:not_found) |
||||
end |
||||
end |
||||
|
||||
context "when required postcode param is invalid" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid" } } } |
||||
|
||||
it "displays the new page with an error message" do |
||||
expect(response).to have_http_status(:unprocessable_entity) |
||||
expect(page).to have_content(I18n.t("validations.postcode")) |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as yes" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "updates existing location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as no" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "updates existing location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is not selected" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "updates existing location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params" do |
||||
expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a support user" do |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
let!(:location) { FactoryBot.create(:location, scheme:) } |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
before do |
||||
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||
sign_in user |
||||
patch "/schemes/#{scheme.id}/locations/#{location.id}", params: params |
||||
end |
||||
|
||||
it "updates a location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your answers before creating this scheme") |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
|
||||
context "when postcode is submitted with lower case" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } |
||||
|
||||
it "updates a location for scheme with postcode " do |
||||
expect(Location.last.postcode).to eq("ZZ11ZZ") |
||||
end |
||||
end |
||||
|
||||
context "when required postcode param is missing" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid" } } } |
||||
|
||||
it "displays the new page with an error message" do |
||||
expect(response).to have_http_status(:unprocessable_entity) |
||||
expect(page).to have_content(I18n.t("validations.postcode")) |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as yes" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "updates location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Add a location to this scheme") |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is selected as no" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "updates a location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "updates existing location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
|
||||
context "when do you want to add another location is not selected" do |
||||
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } |
||||
|
||||
it "updates a location for scheme with valid params and redirects to correct page" do |
||||
follow_redirect! |
||||
expect(response).to have_http_status(:ok) |
||||
expect(page).to have_content("Check your changes before creating this scheme") |
||||
end |
||||
|
||||
it "updates a location for scheme with valid params" do |
||||
expect(Location.last.name).to eq("Test") |
||||
expect(Location.last.total_units).to eq(5) |
||||
expect(Location.last.type_of_unit).to eq("Bungalow") |
||||
expect(Location.last.wheelchair_adaptation).to eq("No") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "#index" do |
||||
context "when not signed in" do |
||||
it "redirects to the sign in page" do |
||||
get "/schemes/#{scheme.id}/locations" |
||||
expect(response).to redirect_to("/account/sign-in") |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data provider user" do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
|
||||
before do |
||||
sign_in user |
||||
get "/schemes/#{scheme.id}/locations" |
||||
end |
||||
|
||||
it "returns 401 unauthorized" do |
||||
request |
||||
expect(response).to have_http_status(:unauthorized) |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a data coordinator user" do |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } |
||||
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) } |
||||
|
||||
before do |
||||
sign_in user |
||||
get "/schemes/#{scheme.id}/locations" |
||||
end |
||||
|
||||
context "when coordinator attempts to see scheme belonging to a different organisation" do |
||||
let!(:another_scheme) { FactoryBot.create(:scheme) } |
||||
|
||||
before do |
||||
FactoryBot.create(:location, scheme:) |
||||
end |
||||
|
||||
it "returns 404 not found" do |
||||
get "/schemes/#{another_scheme.id}/locations" |
||||
expect(response).to have_http_status(:not_found) |
||||
end |
||||
end |
||||
|
||||
it "shows scheme" 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.type_of_unit) |
||||
expect(page).to have_content(location.wheelchair_adaptation) |
||||
end |
||||
end |
||||
|
||||
it "has page heading" do |
||||
expect(page).to have_content(scheme.service_name) |
||||
end |
||||
|
||||
it "has correct title" do |
||||
expected_title = CGI.escapeHTML("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK") |
||||
expect(page).to have_title(expected_title) |
||||
end |
||||
|
||||
context "when paginating over 20 results" do |
||||
let!(:locations) { FactoryBot.create_list(:location, 25, scheme:) } |
||||
|
||||
context "when on the first page" do |
||||
before do |
||||
get "/schemes/#{scheme.id}/locations" |
||||
end |
||||
|
||||
it "shows which schemes are being shown on the current page" do |
||||
expect(CGI.unescape_html(response.body)).to match("Showing <b>1</b> to <b>20</b> of <b>#{locations.count}</b> locations") |
||||
end |
||||
|
||||
it "has correct page 1 of 2 title" do |
||||
expected_title = CGI.escapeHTML("#{scheme.service_name} (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK") |
||||
expect(page).to have_title(expected_title) |
||||
end |
||||
|
||||
it "has pagination links" do |
||||
expect(page).not_to have_content("Previous") |
||||
expect(page).not_to have_link("Previous") |
||||
expect(page).to have_content("Next") |
||||
expect(page).to have_link("Next") |
||||
end |
||||
end |
||||
|
||||
context "when on the second page" do |
||||
before do |
||||
get "/schemes/#{scheme.id}/locations?page=2" |
||||
end |
||||
|
||||
it "shows which schemes are being shown on the current page" do |
||||
expect(CGI.unescape_html(response.body)).to match("Showing <b>21</b> to <b>25</b> of <b>#{locations.count}</b> locations") |
||||
end |
||||
|
||||
it "has correct page 2 of 2 title" do |
||||
expected_title = CGI.escapeHTML("#{scheme.service_name} (page 2 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK") |
||||
expect(page).to have_title(expected_title) |
||||
end |
||||
|
||||
it "has pagination links" do |
||||
expect(page).to have_content("Previous") |
||||
expect(page).to have_link("Previous") |
||||
expect(page).not_to have_content("Next") |
||||
expect(page).not_to have_link("Next") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when signed in as a support user" do |
||||
let(:user) { FactoryBot.create(:user, :support) } |
||||
let!(:scheme) { FactoryBot.create(:scheme) } |
||||
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) } |
||||
|
||||
before do |
||||
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||
sign_in user |
||||
get "/schemes/#{scheme.id}/locations" |
||||
end |
||||
|
||||
it "shows scheme" 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.type_of_unit) |
||||
expect(page).to have_content(location.wheelchair_adaptation) |
||||
end |
||||
end |
||||
|
||||
it "has page heading" do |
||||
expect(page).to have_content(scheme.service_name) |
||||
end |
||||
|
||||
it "has correct title" do |
||||
expected_title = CGI.escapeHTML("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK") |
||||
expect(page).to have_title(expected_title) |
||||
end |
||||
|
||||
context "when paginating over 20 results" do |
||||
let!(:locations) { FactoryBot.create_list(:location, 25, scheme:) } |
||||
|
||||
context "when on the first page" do |
||||
before do |
||||
get "/schemes/#{scheme.id}/locations" |
||||
end |
||||
|
||||
it "shows which schemes are being shown on the current page" do |
||||
expect(CGI.unescape_html(response.body)).to match("Showing <b>1</b> to <b>20</b> of <b>#{locations.count}</b> locations") |
||||
end |
||||
|
||||
it "has correct page 1 of 2 title" do |
||||
expected_title = CGI.escapeHTML("#{scheme.service_name} (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK") |
||||
expect(page).to have_title(expected_title) |
||||
end |
||||
|
||||
it "has pagination links" do |
||||
expect(page).not_to have_content("Previous") |
||||
expect(page).not_to have_link("Previous") |
||||
expect(page).to have_content("Next") |
||||
expect(page).to have_link("Next") |
||||
end |
||||
end |
||||
|
||||
context "when on the second page" do |
||||
before do |
||||
get "/schemes/#{scheme.id}/locations?page=2" |
||||
end |
||||
|
||||
it "shows which schemes are being shown on the current page" do |
||||
expect(CGI.unescape_html(response.body)).to match("Showing <b>21</b> to <b>25</b> of <b>#{locations.count}</b> locations") |
||||
end |
||||
|
||||
it "has correct page 1 of 2 title" do |
||||
expected_title = CGI.escapeHTML("#{scheme.service_name} (page 2 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK") |
||||
expect(page).to have_title(expected_title) |
||||
end |
||||
|
||||
it "has pagination links" do |
||||
expect(page).to have_content("Previous") |
||||
expect(page).to have_link("Previous") |
||||
expect(page).not_to have_content("Next") |
||||
expect(page).not_to have_link("Next") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue