Browse Source

change housing provider -> stock owner (#1104)

* change housing provider -> stock owner

* feat: add case and _ replacements

* refactor: rename files

* refactor: - changes

* housing provider

* refactor: registered ... renaming
pull/1097/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
b855a2987e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/components/search_component.rb
  2. 34
      app/controllers/organisation_relationships_controller.rb
  3. 12
      app/helpers/navigation_items_helper.rb
  4. 16
      app/models/form/lettings/pages/stock_owner.rb
  5. 16
      app/models/form/lettings/questions/stock_owner.rb
  6. 6
      app/models/form/lettings/subsections/setup.rb
  7. 4
      app/models/organisation.rb
  8. 10
      app/models/organisation_relationship.rb
  9. 2
      app/models/scheme.rb
  10. 8
      app/views/organisation_relationships/_stock_owner_list.erb
  11. 14
      app/views/organisation_relationships/add_stock_owner.html.erb
  12. 10
      app/views/organisation_relationships/remove_stock_owner.html.erb
  13. 22
      app/views/organisation_relationships/stock_owners.html.erb
  14. 2
      config/locales/en.yml
  15. 10
      config/routes.rb
  16. 12
      db/seeds.rb
  17. 2
      spec/features/lettings_log_spec.rb
  18. 4
      spec/features/schemes_spec.rb
  19. 22
      spec/helpers/navigation_items_helper_spec.rb
  20. 28
      spec/models/form/lettings/pages/stock_owner_spec.rb
  21. 24
      spec/models/form/lettings/questions/stock_owner_spec.rb
  22. 4
      spec/models/form/lettings/subsections/setup_spec.rb
  23. 4
      spec/models/organisation_relationship_spec.rb
  24. 6
      spec/models/organisation_spec.rb
  25. 22
      spec/requests/form_controller_spec.rb
  26. 146
      spec/requests/organisation_relationships_controller_spec.rb

2
app/components/search_component.rb

@ -15,7 +15,7 @@ class SearchComponent < ViewComponent::Base
request.path request.path
elsif request.path.include?("organisations") && request.path.include?("schemes") elsif request.path.include?("organisations") && request.path.include?("schemes")
request.path request.path
elsif request.path.include?("organisations") && request.path.include?("housing-providers") elsif request.path.include?("organisations") && request.path.include?("stock-owners")
request.path request.path
elsif request.path.include?("organisations") && request.path.include?("managing-agents") elsif request.path.include?("organisations") && request.path.include?("managing-agents")
request.path request.path

34
app/controllers/organisation_relationships_controller.rb

@ -7,19 +7,19 @@ class OrganisationRelationshipsController < ApplicationController
before_action :organisations before_action :organisations
before_action :target_organisation, only: %i[ before_action :target_organisation, only: %i[
remove_housing_provider remove_stock_owner
remove_managing_agent remove_managing_agent
delete_housing_provider delete_stock_owner
delete_managing_agent delete_managing_agent
] ]
def housing_providers def stock_owners
housing_providers = organisation.housing_providers stock_owners = organisation.stock_owners
unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) unpaginated_filtered_stock_owners = filtered_collection(stock_owners, search_term)
@pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) @pagy, @stock_owners = pagy(unpaginated_filtered_stock_owners)
@searched = search_term.presence @searched = search_term.presence
@total_count = housing_providers.size @total_count = stock_owners.size
end end
def managing_agents def managing_agents
@ -31,7 +31,7 @@ class OrganisationRelationshipsController < ApplicationController
@total_count = managing_agents.size @total_count = managing_agents.size
end end
def add_housing_provider def add_stock_owner
@organisation_relationship = organisation.parent_organisation_relationships.new @organisation_relationship = organisation.parent_organisation_relationships.new
end end
@ -39,14 +39,14 @@ class OrganisationRelationshipsController < ApplicationController
@organisation_relationship = organisation.child_organisation_relationships.new @organisation_relationship = organisation.child_organisation_relationships.new
end end
def create_housing_provider def create_stock_owner
@organisation_relationship = organisation.parent_organisation_relationships.new(organisation_relationship_params) @organisation_relationship = organisation.parent_organisation_relationships.new(organisation_relationship_params)
if @organisation_relationship.save(context: :housing_provider) if @organisation_relationship.save(context: :stock_owner)
flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners"
redirect_to housing_providers_organisation_path redirect_to stock_owners_organisation_path
else else
@organisations = Organisation.where.not(id: organisation.id).pluck(:id, :name) @organisations = Organisation.where.not(id: organisation.id).pluck(:id, :name)
render "organisation_relationships/add_housing_provider", status: :unprocessable_entity render "organisation_relationships/add_stock_owner", status: :unprocessable_entity
end end
end end
@ -61,15 +61,15 @@ class OrganisationRelationshipsController < ApplicationController
end end
end end
def remove_housing_provider; end def remove_stock_owner; end
def delete_housing_provider def delete_stock_owner
OrganisationRelationship.find_by!( OrganisationRelationship.find_by!(
child_organisation: organisation, child_organisation: organisation,
parent_organisation: target_organisation, parent_organisation: target_organisation,
).destroy! ).destroy!
flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners"
redirect_to housing_providers_organisation_path redirect_to stock_owners_organisation_path
end end
def remove_managing_agent; end def remove_managing_agent; end

12
app/helpers/navigation_items_helper.rb

@ -17,7 +17,7 @@ module NavigationItemsHelper
NavigationItem.new("Schemes", "/schemes", subnav_supported_housing_schemes_path?(path)), NavigationItem.new("Schemes", "/schemes", subnav_supported_housing_schemes_path?(path)),
NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)),
NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)),
(NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_user.organisation), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?),
(NavigationItem.new("Managing agents", managing_agents_organisation_path(current_user.organisation), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_user.organisation), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?),
].compact ].compact
else else
@ -26,7 +26,7 @@ module NavigationItemsHelper
FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil, FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil,
NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)),
NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)),
(NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_user.organisation), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?),
(NavigationItem.new("Managing agents", managing_agents_organisation_path(current_user.organisation), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_user.organisation), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?),
].compact ].compact
end end
@ -40,7 +40,7 @@ module NavigationItemsHelper
NavigationItem.new("Schemes", "/organisations/#{current_organisation_id}/schemes", subnav_supported_housing_schemes_path?(path)), NavigationItem.new("Schemes", "/organisations/#{current_organisation_id}/schemes", subnav_supported_housing_schemes_path?(path)),
NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)),
NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)),
(NavigationItem.new("Housing providers", housing_providers_organisation_path(current_organisation_id), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_organisation_id), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?),
(NavigationItem.new("Managing agents", managing_agents_organisation_path(current_organisation_id), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_organisation_id), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?),
].compact ].compact
else else
@ -49,7 +49,7 @@ module NavigationItemsHelper
FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", sales_logs_current?(path)) : nil, FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", sales_logs_current?(path)) : nil,
NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)),
NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)),
(NavigationItem.new("Housing providers", housing_providers_organisation_path(current_organisation_id), housing_providers_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Stock owners", stock_owners_organisation_path(current_organisation_id), stock_owners_path?(path)) if FeatureToggle.managing_owning_enabled?),
(NavigationItem.new("Managing agents", managing_agents_organisation_path(current_organisation_id), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?), (NavigationItem.new("Managing agents", managing_agents_organisation_path(current_organisation_id), managing_agents_path?(path)) if FeatureToggle.managing_owning_enabled?),
].compact ].compact
end end
@ -104,8 +104,8 @@ private
path.include?("/organisations") && path.include?("/details") path.include?("/organisations") && path.include?("/details")
end end
def housing_providers_path?(path) def stock_owners_path?(path)
path.include?("/housing-providers") path.include?("/stock-owners")
end end
def managing_agents_path?(path) def managing_agents_path?(path)

16
app/models/form/lettings/pages/housing_provider.rb → app/models/form/lettings/pages/stock_owner.rb

@ -1,7 +1,7 @@
class Form::Lettings::Pages::HousingProvider < ::Form::Page class Form::Lettings::Pages::StockOwner < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "housing_provider" @id = "stock_owner"
@header = "" @header = ""
@description = "" @description = ""
@subsection = subsection @subsection = subsection
@ -9,7 +9,7 @@ class Form::Lettings::Pages::HousingProvider < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Lettings::Questions::HousingProvider.new(nil, nil, self), Form::Lettings::Questions::StockOwner.new(nil, nil, self),
] ]
end end
@ -17,17 +17,17 @@ class Form::Lettings::Pages::HousingProvider < ::Form::Page
return false unless current_user return false unless current_user
return true if current_user.support? return true if current_user.support?
housing_providers = current_user.organisation.housing_providers stock_owners = current_user.organisation.stock_owners
if current_user.organisation.holds_own_stock? if current_user.organisation.holds_own_stock?
return true if housing_providers.count >= 1 return true if stock_owners.count >= 1
log.update!(owning_organisation: current_user.organisation) log.update!(owning_organisation: current_user.organisation)
else else
return false if housing_providers.count.zero? return false if stock_owners.count.zero?
return true if housing_providers.count > 1 return true if stock_owners.count > 1
log.update!(owning_organisation: housing_providers.first) log.update!(owning_organisation: stock_owners.first)
end end
false false

16
app/models/form/lettings/questions/housing_provider.rb → app/models/form/lettings/questions/stock_owner.rb

@ -1,10 +1,10 @@
class Form::Lettings::Questions::HousingProvider < ::Form::Question class Form::Lettings::Questions::StockOwner < ::Form::Question
attr_accessor :current_user, :log attr_accessor :current_user, :log
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "owning_organisation_id" @id = "owning_organisation_id"
@check_answer_label = "Housing provider" @check_answer_label = "Stock owner"
@header = "Which organisation owns this property?" @header = "Which organisation owns this property?"
@type = "select" @type = "select"
@page = page @page = page
@ -19,7 +19,7 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question
answer_opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)" answer_opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)"
end end
answer_opts.merge(housing_providers_answer_options) answer_opts.merge(stock_owners_answer_options)
end end
def displayed_answer_options(log, user = nil) def displayed_answer_options(log, user = nil)
@ -44,12 +44,12 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question
return false if current_user.support? return false if current_user.support?
housing_providers = current_user.organisation.housing_providers stock_owners = current_user.organisation.stock_owners
if current_user.organisation.holds_own_stock? if current_user.organisation.holds_own_stock?
housing_providers.count.zero? stock_owners.count.zero?
else else
housing_providers.count <= 1 stock_owners.count <= 1
end end
end end
@ -63,11 +63,11 @@ private
true true
end end
def housing_providers_answer_options def stock_owners_answer_options
if current_user.support? if current_user.support?
Organisation Organisation
else else
current_user.organisation.housing_providers current_user.organisation.stock_owners
end.pluck(:id, :name).to_h end.pluck(:id, :name).to_h
end end
end end

6
app/models/form/lettings/subsections/setup.rb

@ -9,7 +9,7 @@ class Form::Lettings::Subsections::Setup < ::Form::Subsection
def pages def pages
@pages ||= [ @pages ||= [
organisation_page, organisation_page,
housing_provider_page, stock_owner_page,
managing_organisation_page, managing_organisation_page,
created_by_page, created_by_page,
Form::Lettings::Pages::NeedsType.new(nil, nil, self), Form::Lettings::Pages::NeedsType.new(nil, nil, self),
@ -35,10 +35,10 @@ private
Form::Common::Pages::Organisation.new(nil, nil, self) Form::Common::Pages::Organisation.new(nil, nil, self)
end end
def housing_provider_page def stock_owner_page
return unless FeatureToggle.managing_for_other_user_enabled? return unless FeatureToggle.managing_for_other_user_enabled?
Form::Lettings::Pages::HousingProvider.new(nil, nil, self) Form::Lettings::Pages::StockOwner.new(nil, nil, self)
end end
def managing_organisation_page def managing_organisation_page

4
app/models/organisation.rb

@ -13,8 +13,8 @@ class Organisation < ApplicationRecord
has_many :child_organisation_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship" has_many :child_organisation_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship"
has_many :child_organisations, through: :child_organisation_relationships has_many :child_organisations, through: :child_organisation_relationships
has_many :housing_provider_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" has_many :stock_owner_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship"
has_many :housing_providers, through: :housing_provider_relationships, source: :parent_organisation has_many :stock_owners, through: :stock_owner_relationships, source: :parent_organisation
has_many :managing_agent_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship" has_many :managing_agent_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship"
has_many :managing_agents, through: :managing_agent_relationships, source: :child_organisation has_many :managing_agents, through: :managing_agent_relationships, source: :child_organisation

10
app/models/organisation_relationship.rb

@ -1,17 +1,17 @@
class OrganisationRelationship < ApplicationRecord class OrganisationRelationship < ApplicationRecord
belongs_to :child_organisation, class_name: "Organisation" belongs_to :child_organisation, class_name: "Organisation"
belongs_to :parent_organisation, class_name: "Organisation" belongs_to :parent_organisation, class_name: "Organisation"
validates :parent_organisation_id, presence: { message: I18n.t("validations.organisation.housing_provider.blank") } validates :parent_organisation_id, presence: { message: I18n.t("validations.organisation.stock_owner.blank") }
validates :child_organisation_id, presence: { message: I18n.t("validations.organisation.managing_agent.blank") } validates :child_organisation_id, presence: { message: I18n.t("validations.organisation.managing_agent.blank") }
validates :parent_organisation_id, uniqueness: { scope: :child_organisation_id, message: I18n.t("validations.organisation.housing_provider.already_added") } validates :parent_organisation_id, uniqueness: { scope: :child_organisation_id, message: I18n.t("validations.organisation.stock_owner.already_added") }
validates :child_organisation_id, uniqueness: { scope: :parent_organisation_id, message: I18n.t("validations.organisation.managing_agent.already_added") } validates :child_organisation_id, uniqueness: { scope: :parent_organisation_id, message: I18n.t("validations.organisation.managing_agent.already_added") }
validate :validate_housing_provider_owns_stock, on: :housing_provider validate :validate_stock_owner_owns_stock, on: :stock_owner
private private
def validate_housing_provider_owns_stock def validate_stock_owner_owns_stock
if parent_organisation_id.present? && !parent_organisation.holds_own_stock if parent_organisation_id.present? && !parent_organisation.holds_own_stock
errors.add :parent_organisation_id, I18n.t("validations.organisation.housing_provider.does_not_own_stock") errors.add :parent_organisation_id, I18n.t("validations.organisation.stock_owner.does_not_own_stock")
end end
end end
end end

2
app/models/scheme.rb

@ -103,7 +103,7 @@ class Scheme < ApplicationRecord
ARRANGEMENT_TYPE = { ARRANGEMENT_TYPE = {
"The same organisation that owns the housing stock": "D", "The same organisation that owns the housing stock": "D",
"Another registered housing provider": "R", "Another registered stock owner": "R",
"A registered charity or voluntary organisation": "V", "A registered charity or voluntary organisation": "V",
"Another organisation": "O", "Another organisation": "O",
"Missing": "X", "Missing": "X",

8
app/views/organisation_relationships/_housing_provider_list.erb → app/views/organisation_relationships/_stock_owner_list.erb

@ -1,18 +1,18 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> <section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "housing providers", path: request.path)) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "stock owners", path: request.path)) %>
<% end %> <% end %>
<% @housing_providers.each do |housing_provider| %> <% @stock_owners.each do |stock_owner| %>
<%= table.body do |body| %> <%= table.body do |body| %>
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: housing_provider.name) %> <% row.cell(text: stock_owner.name) %>
<% if current_user.data_coordinator? || current_user.support? %> <% if current_user.data_coordinator? || current_user.support? %>
<% row.cell(html_attributes: { <% row.cell(html_attributes: {
scope: "row", scope: "row",
class: "govuk-!-text-align-right", class: "govuk-!-text-align-right",
}) do %> }) do %>
<%= govuk_link_to("Remove", housing_providers_remove_organisation_path(target_organisation_id: housing_provider.id)) %> <%= govuk_link_to("Remove", stock_owners_remove_organisation_path(target_organisation_id: stock_owner.id)) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

14
app/views/organisation_relationships/add_housing_provider.html.erb → app/views/organisation_relationships/add_stock_owner.html.erb

@ -1,17 +1,17 @@
<%= form_with model: @organisation_relationship, url: housing_providers_organisation_path, method: "post", local: true do |f| %> <%= form_with model: @organisation_relationship, url: stock_owners_organisation_path, method: "post", local: true do |f| %>
<% if current_user.support? %> <% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
<h2 class="govuk-visually-hidden">Add Housing Provider</h2> <h2 class="govuk-visually-hidden">Add Stock Owner</h2>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's housing provider?", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's stock owner?", sub: nil } %>
<p class="govuk-body">Start typing to search for a housing provider</p> <p class="govuk-body">Start typing to search for a stock owner</p>
<% else %> <% else %>
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "What is the name of your stock owner?", sub: nil } %>
<p class="govuk-body">Start typing to search for your housing provider</p> <p class="govuk-body">Start typing to search for your stock owner</p>
<% end %> <% end %>
<% answer_options = { "" => "Select an option" } %> <% answer_options = { "" => "Select an option" } %>
<% @organisations.each do |organisation| %> <% @organisations.each do |organisation| %>
@ -23,7 +23,7 @@
f:, f:,
} %> } %>
<%= f.govuk_submit "Add" %> <%= f.govuk_submit "Add" %>
<%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %> <%= govuk_details(summary_text: "Can't find the stock owner you're looking for?") do %>
<ul class="govuk-list govuk-list--bullet"> <ul class="govuk-list govuk-list--bullet">
<li>Double check the spelling and try again</li> <li>Double check the spelling and try again</li>
<li>Type the first few letters to see the suggestions</li> <li>Type the first few letters to see the suggestions</li>

10
app/views/organisation_relationships/remove_housing_provider.html.erb → app/views/organisation_relationships/remove_stock_owner.html.erb

@ -1,21 +1,21 @@
<%= form_with url: housing_providers_organisation_path(target_organisation_id: @target_organisation.id), method: "delete", local: true do |f| %> <%= form_with url: stock_owners_organisation_path(target_organisation_id: @target_organisation.id), method: "delete", local: true do |f| %>
<% if current_user.support? %> <% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
<h2 class="govuk-visually-hidden">Remove Housing Provider</h2> <h2 class="govuk-visually-hidden">Remove Stock Owner</h2>
<% end %> <% end %>
<% if current_user.support? %> <% if current_user.support? %>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from this organisation's housing providers", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from this organisation's stock owners", sub: nil } %>
<% else %> <% else %>
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from your organisation's housing providers", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from your organisation's stock owners", sub: nil } %>
<% end %> <% end %>
<%= govuk_warning_text text: "You will no longer be able to submit logs for #{@target_organisation.name}" %> <%= govuk_warning_text text: "You will no longer be able to submit logs for #{@target_organisation.name}" %>
<div class="govuk-button-group"> <div class="govuk-button-group">
<%= f.govuk_submit "Confirm" %> <%= f.govuk_submit "Confirm" %>
<%= govuk_button_link_to "Cancel", housing_providers_organisation_path(current_user.organisation), html: { method: :get }, secondary: true %> <%= govuk_button_link_to "Cancel", stock_owners_organisation_path(current_user.organisation), html: { method: :get }, secondary: true %>
</div> </div>
<% end %> <% end %>

22
app/views/organisation_relationships/housing_providers.html.erb → app/views/organisation_relationships/stock_owners.html.erb

@ -1,24 +1,24 @@
<% item_label = format_label(@pagy.count, "housing providers") %> <% item_label = format_label(@pagy.count, "stock owners") %>
<% if current_user.support? %> <% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
<h2 class="govuk-visually-hidden">Housing Providers</h2> <h2 class="govuk-visually-hidden">Stock Owners</h2>
<p class="govuk-body">This organisation can submit logs for its housing providers.</p> <p class="govuk-body">This organisation can submit logs for its stock owners.</p>
<% if @total_count == 0 %> <% if @total_count == 0 %>
<p class="govuk-body">This organisation does not currently have any housing providers.</p> <p class="govuk-body">This organisation does not currently have any stock owners.</p>
<% end %> <% end %>
<% else %> <% else %>
<%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: current_user.organisation.name } %> <%= render partial: "organisations/headings", locals: { main: "Your stock owners", sub: current_user.organisation.name } %>
<p class="govuk-body">Your organisation can submit logs for its housing providers.</p> <p class="govuk-body">Your organisation can submit logs for its stock owners.</p>
<% if @total_count == 0 %> <% if @total_count == 0 %>
<p class="govuk-body">You do not currently have any housing providers.</p> <p class="govuk-body">You do not currently have any stock owners.</p>
<% end %> <% end %>
<% end %> <% end %>
<% if current_user.support? || current_user.data_coordinator? %> <% if current_user.support? || current_user.data_coordinator? %>
<%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path, html: { method: :get } %> <%= govuk_button_link_to "Add a stock owner", stock_owners_add_organisation_path, html: { method: :get } %>
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search for a stock owner", value: @searched) %>
<%= render partial: "organisation_relationships/housing_provider_list", locals: { index: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> <%= render partial: "organisation_relationships/stock_owner_list", locals: { index: @stock_owners, title: "Stock owners", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "stock owners" } %>
<% end %> <% end %>

2
config/locales/en.yml

@ -116,7 +116,7 @@ en:
organisation: organisation:
name_missing: "Enter the name of the organisation" name_missing: "Enter the name of the organisation"
provider_type_missing: "Select the organisation type" provider_type_missing: "Select the organisation type"
housing_provider: stock_owner:
blank: "You must choose a stock owner" blank: "You must choose a stock owner"
already_added: "You have already added this stock owner" already_added: "You have already added this stock owner"
does_not_own_stock: "You can only add stock owners who own stock, which this organisation does not." does_not_own_stock: "You can only add stock owners who own stock, which this organisation does not."

10
config/routes.rb

@ -91,11 +91,11 @@ Rails.application.routes.draw do
post "logs/email-csv", to: "organisations#email_csv" post "logs/email-csv", to: "organisations#email_csv"
get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation" get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation"
get "schemes", to: "organisations#schemes" get "schemes", to: "organisations#schemes"
get "housing-providers", to: "organisation_relationships#housing_providers" get "stock-owners", to: "organisation_relationships#stock_owners"
get "housing-providers/add", to: "organisation_relationships#add_housing_provider" get "stock-owners/add", to: "organisation_relationships#add_stock_owner"
get "housing-providers/remove", to: "organisation_relationships#remove_housing_provider" get "stock-owners/remove", to: "organisation_relationships#remove_stock_owner"
post "housing-providers", to: "organisation_relationships#create_housing_provider" post "stock-owners", to: "organisation_relationships#create_stock_owner"
delete "housing-providers", to: "organisation_relationships#delete_housing_provider" delete "stock-owners", to: "organisation_relationships#delete_stock_owner"
get "managing-agents", to: "organisation_relationships#managing_agents" get "managing-agents", to: "organisation_relationships#managing_agents"
get "managing-agents/add", to: "organisation_relationships#add_managing_agent" get "managing-agents/add", to: "organisation_relationships#add_managing_agent"
get "managing-agents/remove", to: "organisation_relationships#remove_managing_agent" get "managing-agents/remove", to: "organisation_relationships#remove_managing_agent"

12
db/seeds.rb

@ -8,8 +8,8 @@
# rubocop:disable Rails/Output # rubocop:disable Rails/Output
unless Rails.env.test? unless Rails.env.test?
housing_provider1 = Organisation.find_or_create_by!( stock_owner1 = Organisation.find_or_create_by!(
name: "Housing Provider 1", name: "Stock Owner 1",
address_line1: "2 Marsham Street", address_line1: "2 Marsham Street",
address_line2: "London", address_line2: "London",
postcode: "SW1P 4DF", postcode: "SW1P 4DF",
@ -18,8 +18,8 @@ unless Rails.env.test?
managing_agents_label: "None", managing_agents_label: "None",
provider_type: "LA", provider_type: "LA",
) )
housing_provider2 = Organisation.find_or_create_by!( stock_owner2 = Organisation.find_or_create_by!(
name: "Housing Provider 2", name: "Stock Owner 2",
address_line1: "2 Marsham Street", address_line1: "2 Marsham Street",
address_line2: "London", address_line2: "London",
postcode: "SW1P 4DF", postcode: "SW1P 4DF",
@ -130,11 +130,11 @@ unless Rails.env.test?
end end
OrganisationRelationship.find_or_create_by!( OrganisationRelationship.find_or_create_by!(
parent_organisation: housing_provider1, parent_organisation: stock_owner1,
child_organisation: org, child_organisation: org,
) )
OrganisationRelationship.find_or_create_by!( OrganisationRelationship.find_or_create_by!(
parent_organisation: housing_provider2, parent_organisation: stock_owner2,
child_organisation: org, child_organisation: org,
) )
OrganisationRelationship.find_or_create_by!( OrganisationRelationship.find_or_create_by!(

2
spec/features/lettings_log_spec.rb

@ -88,7 +88,7 @@ RSpec.describe "Lettings Log Features" do
click_button("Save and continue") click_button("Save and continue")
log_id = page.current_path.scan(/\d/).join log_id = page.current_path.scan(/\d/).join
visit("lettings-logs/#{log_id}/setup/check-answers") visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Housing provider #{support_user.organisation.name}") expect(page).to have_content("Stock owner #{support_user.organisation.name}")
expect(page).to have_content("You have answered 2 of 8 questions") expect(page).to have_content("You have answered 2 of 8 questions")
end end
end end

4
spec/features/schemes_spec.rb

@ -585,7 +585,7 @@ RSpec.describe "Schemes scheme Features" do
it "indicates if the scheme is not complete" do it "indicates if the scheme is not complete" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
choose "Another registered housing provider" choose "Another registered stock owner"
click_button "Save and continue" click_button "Save and continue"
expect(page).to have_content("You didn’t answer this question") expect(page).to have_content("You didn’t answer this question")
end end
@ -613,7 +613,7 @@ RSpec.describe "Schemes scheme Features" do
let!(:another_organisation) { FactoryBot.create(:organisation, name: "Another Org") } let!(:another_organisation) { FactoryBot.create(:organisation, name: "Another Org") }
before do before do
fill_in_and_save_scheme_details({ "housing_stock_owners" => "Another registered housing provider" }) fill_in_and_save_scheme_details({ "housing_stock_owners" => "Another registered stock owner" })
end end
it "lets me fill in the managing organisation details" do it "lets me fill in the managing organisation details" do

22
spec/helpers/navigation_items_helper_spec.rb

@ -346,7 +346,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -364,7 +364,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -382,7 +382,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, true), NavigationItemsHelper::NavigationItem.new("Users", users_path, true),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -400,7 +400,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, true), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, true),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -418,7 +418,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -436,7 +436,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -454,7 +454,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -632,7 +632,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -662,7 +662,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -692,7 +692,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", true),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end
@ -722,7 +722,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", true), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", true),
NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), NavigationItemsHelper::NavigationItem.new("Stock owners", "/organisations/#{current_user.organisation.id}/stock-owners", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false), NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
] ]
end end

28
spec/models/form/lettings/pages/housing_provider_spec.rb → spec/models/form/lettings/pages/stock_owner_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do RSpec.describe Form::Lettings::Pages::StockOwner, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil } let(:page_id) { nil }
@ -17,7 +17,7 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("housing_provider") expect(page.id).to eq("stock_owner")
end end
it "has the correct header" do it "has the correct header" do
@ -63,7 +63,7 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false))
end end
context "with 0 housing_providers" do context "with 0 stock_owners" do
it "is not shown" do it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false) expect(page.routed_to?(log, user)).to eq(false)
end end
@ -73,14 +73,14 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end end
end end
context "with 1 housing_providers" do context "with 1 stock_owners" do
let(:housing_provider) { create(:organisation) } let(:stock_owner) { create(:organisation) }
before do before do
create( create(
:organisation_relationship, :organisation_relationship,
child_organisation: user.organisation, child_organisation: user.organisation,
parent_organisation: housing_provider, parent_organisation: stock_owner,
) )
end end
@ -89,24 +89,24 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end end
it "updates owning_organisation_id" do it "updates owning_organisation_id" do
expect { page.routed_to?(log, user) }.to change(log.reload, :owning_organisation).from(nil).to(housing_provider) expect { page.routed_to?(log, user) }.to change(log.reload, :owning_organisation).from(nil).to(stock_owner)
end end
end end
context "with >1 housing_providers" do context "with >1 stock_owners" do
let(:housing_provider1) { create(:organisation) } let(:stock_owner1) { create(:organisation) }
let(:housing_provider2) { create(:organisation) } let(:stock_owner2) { create(:organisation) }
before do before do
create( create(
:organisation_relationship, :organisation_relationship,
child_organisation: user.organisation, child_organisation: user.organisation,
parent_organisation: housing_provider1, parent_organisation: stock_owner1,
) )
create( create(
:organisation_relationship, :organisation_relationship,
child_organisation: user.organisation, child_organisation: user.organisation,
parent_organisation: housing_provider2, parent_organisation: stock_owner2,
) )
end end
@ -125,7 +125,7 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true))
end end
context "with 0 housing_providers" do context "with 0 stock_owners" do
it "is not shown" do it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false) expect(page.routed_to?(log, user)).to eq(false)
end end
@ -135,7 +135,7 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end end
end end
context "with >0 housing_providers" do context "with >0 stock_owners" do
before do before do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)

24
spec/models/form/lettings/questions/housing_provider_spec.rb → spec/models/form/lettings/questions/stock_owner_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) } subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil } let(:question_id) { nil }
@ -22,7 +22,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Housing provider") expect(question.check_answer_label).to eq("Stock owner")
end end
it "has the correct type" do it "has the correct type" do
@ -55,7 +55,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
question.current_user = user question.current_user = user
end end
it "shows housing providers with own org at the top" do it "shows stock owners with own org at the top" do
expect(question.answer_options).to eq(options) expect(question.answer_options).to eq(options)
end end
end end
@ -94,24 +94,24 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
context "when org holds own stock", :aggregate_failures do context "when org holds own stock", :aggregate_failures do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) } let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) }
context "when housing providers == 0" do context "when stock owners == 0" do
before do before do
user.organisation.housing_providers.delete_all user.organisation.stock_owners.delete_all
end end
it "is hidden in check answers" do it "is hidden in check answers" do
expect(user.organisation.housing_providers.count).to eq(0) expect(user.organisation.stock_owners.count).to eq(0)
expect(question.hidden_in_check_answers?(nil, user)).to be true expect(question.hidden_in_check_answers?(nil, user)).to be true
end end
end end
context "when housing providers != 0" do context "when stock owners != 0" do
before do before do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
end end
it "is visible in check answers" do it "is visible in check answers" do
expect(user.organisation.housing_providers.count).to eq(1) expect(user.organisation.stock_owners.count).to eq(1)
expect(question.hidden_in_check_answers?(nil, user)).to be false expect(question.hidden_in_check_answers?(nil, user)).to be false
end end
end end
@ -120,25 +120,25 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
context "when org does not hold own stock", :aggregate_failures do context "when org does not hold own stock", :aggregate_failures do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) } let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) }
context "when housing providers <= 1" do context "when stock owners <= 1" do
before do before do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
end end
it "is hidden in check answers" do it "is hidden in check answers" do
expect(user.organisation.housing_providers.count).to eq(1) expect(user.organisation.stock_owners.count).to eq(1)
expect(question.hidden_in_check_answers?(nil, user)).to be true expect(question.hidden_in_check_answers?(nil, user)).to be true
end end
end end
context "when housing providers >= 2" do context "when stock owners >= 2" do
before do before do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
end end
it "is visible in check answers" do it "is visible in check answers" do
expect(user.organisation.housing_providers.count).to eq(2) expect(user.organisation.stock_owners.count).to eq(2)
expect(question.hidden_in_check_answers?(nil, user)).to be false expect(question.hidden_in_check_answers?(nil, user)).to be false
end end
end end

4
spec/models/form/lettings/subsections/setup_spec.rb

@ -14,7 +14,7 @@ RSpec.describe Form::Lettings::Subsections::Setup, type: :model do
it "has correct pages" do it "has correct pages" do
expect(setup.pages.map(&:id)).to eq( expect(setup.pages.map(&:id)).to eq(
%w[ %w[
housing_provider stock_owner
managing_organisation managing_organisation
created_by created_by
needs_type needs_type
@ -41,7 +41,7 @@ RSpec.describe Form::Lettings::Subsections::Setup, type: :model do
it "has correct pages" do it "has correct pages" do
expect(setup.pages.map(&:id)).to eq( expect(setup.pages.map(&:id)).to eq(
%w[ %w[
housing_provider stock_owner
managing_organisation managing_organisation
created_by created_by
needs_type needs_type

4
spec/models/organisation_relationship_spec.rb

@ -16,9 +16,9 @@ RSpec.describe OrganisationRelationship do
end end
end end
describe "child#housing_providers" do describe "child#stock_owners" do
it "includes parent" do it "includes parent" do
expect(child_organisation.housing_providers).to include(parent_organisation) expect(child_organisation.stock_owners).to include(parent_organisation)
end end
end end
end end

6
spec/models/organisation_spec.rb

@ -74,9 +74,9 @@ RSpec.describe Organisation, type: :model do
) )
end end
it "has correct housing_providers" do it "has correct stock_owners" do
expect(child_organisation.housing_providers).to eq([organisation]) expect(child_organisation.stock_owners).to eq([organisation])
expect(grandchild_organisation.housing_providers).to eq([child_organisation]) expect(grandchild_organisation.stock_owners).to eq([child_organisation])
end end
end end

22
spec/requests/form_controller_spec.rb

@ -75,11 +75,11 @@ RSpec.describe FormController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:managing_organisation) { create(:organisation) } let(:managing_organisation) { create(:organisation) }
let(:managing_organisation_too) { create(:organisation) } let(:managing_organisation_too) { create(:organisation) }
let(:housing_provider) { create(:organisation) } let(:stock_owner) { create(:organisation) }
let(:support_user) { create(:user, :support) } let(:support_user) { create(:user, :support) }
before do before do
organisation.housing_providers << housing_provider organisation.stock_owners << stock_owner
organisation.managing_agents << managing_organisation organisation.managing_agents << managing_organisation
organisation.managing_agents << managing_organisation_too organisation.managing_agents << managing_organisation_too
organisation.reload organisation.reload
@ -99,7 +99,7 @@ RSpec.describe FormController, type: :request do
end end
before do before do
lettings_log.update!(owning_organisation: housing_provider, created_by: user, managing_organisation: organisation) lettings_log.update!(owning_organisation: stock_owner, created_by: user, managing_organisation: organisation)
lettings_log.reload lettings_log.reload
end end
@ -142,8 +142,8 @@ RSpec.describe FormController, type: :request do
{ {
id: lettings_log.id, id: lettings_log.id,
lettings_log: { lettings_log: {
page: "housing_provider", page: "stock_owner",
owning_organisation_id: housing_provider.id, owning_organisation_id: stock_owner.id,
}, },
} }
end end
@ -162,13 +162,13 @@ RSpec.describe FormController, type: :request do
end end
end end
context "with only adding the housing provider" do context "with only adding the stock owner" do
let(:params) do let(:params) do
{ {
id: lettings_log.id, id: lettings_log.id,
lettings_log: { lettings_log: {
page: "housing_provider", page: "stock_owner",
owning_organisation_id: housing_provider.id, owning_organisation_id: stock_owner.id,
}, },
} }
end end
@ -420,7 +420,7 @@ RSpec.describe FormController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:managing_organisation) { create(:organisation) } let(:managing_organisation) { create(:organisation) }
let(:managing_organisation_too) { create(:organisation) } let(:managing_organisation_too) { create(:organisation) }
let(:housing_provider) { create(:organisation) } let(:stock_owner) { create(:organisation) }
let(:params) do let(:params) do
{ {
id: lettings_log.id, id: lettings_log.id,
@ -432,11 +432,11 @@ RSpec.describe FormController, type: :request do
end end
before do before do
organisation.housing_providers << housing_provider organisation.stock_owners << stock_owner
organisation.managing_agents << managing_organisation organisation.managing_agents << managing_organisation
organisation.managing_agents << managing_organisation_too organisation.managing_agents << managing_organisation_too
organisation.reload organisation.reload
lettings_log.update!(owning_organisation: housing_provider, created_by: user, managing_organisation: organisation) lettings_log.update!(owning_organisation: stock_owner, created_by: user, managing_organisation: organisation)
lettings_log.reload lettings_log.reload
end end

146
spec/requests/organisation_relationships_controller_spec.rb

@ -14,16 +14,16 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
sign_in user sign_in user
end end
context "when accessing the housing providers tab" do context "when accessing the stock owners tab" do
context "with an organisation that the user belongs to" do context "with an organisation that the user belongs to" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:stock_owner) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } let!(:other_org_stock_owner) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") } let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_stock_owner)
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} get "/organisations/#{organisation.id}/stock-owners", headers:, params: {}
end end
it "shows the tab navigation" do it "shows the tab navigation" do
@ -31,32 +31,32 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
end end
it "shows an add housing provider button" do it "shows an add stock owner button" do
expect(page).to have_link("Add a housing provider") expect(page).to have_link("Add a stock owner")
end end
it "shows a table of housing providers" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name) expect(response.body).to include(stock_owner.name)
end end
it "shows only housing providers for the current user's organisation" do it "shows only stock owners for the current user's organisation" do
expect(page).to have_content(housing_provider.name) expect(page).to have_content(stock_owner.name)
expect(page).not_to have_content(other_org_housing_provider.name) expect(page).not_to have_content(other_org_stock_owner.name)
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total housing providers") expect(page).to have_content("1 total stock owners")
end end
context "when adding a housing provider" do context "when adding a stock owner" do
before do before do
get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {} get "/organisations/#{organisation.id}/stock-owners/add", headers:, params: {}
end end
it "has the correct header" do it "has the correct header" do
expect(response.body).to include("What is the name of your housing provider?") expect(response.body).to include("What is the name of your stock owner?")
end end
it "shows an add button" do it "shows an add button" do
@ -67,7 +67,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do
before do before do
get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {} get "/organisations/#{unauthorised_organisation.id}/stock-owners", headers:, params: {}
end end
it "returns not found 404 from users page" do it "returns not found 404 from users page" do
@ -134,18 +134,18 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
end end
describe "organisation_relationships#create_housing_provider" do describe "organisation_relationships#create_stock_owner" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:stock_owner) { FactoryBot.create(:organisation) }
let(:params) do let(:params) do
{ {
"organisation_relationship": { "organisation_relationship": {
"parent_organisation_id": housing_provider.id, "parent_organisation_id": stock_owner.id,
}, },
} }
end end
let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: } let(:request) { post "/organisations/#{organisation.id}/stock-owners", headers:, params: }
it "creates a new organisation relationship" do it "creates a new organisation relationship" do
expect { request }.to change(OrganisationRelationship, :count).by(1) expect { request }.to change(OrganisationRelationship, :count).by(1)
@ -153,12 +153,12 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "sets the organisation relationship attributes correctly" do it "sets the organisation relationship attributes correctly" do
request request
expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id) expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: stock_owner.id)
end end
it "redirects to the organisation list" do it "redirects to the organisation list" do
request request
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") expect(response).to redirect_to("/organisations/#{organisation.id}/stock-owners")
end end
end end
@ -190,17 +190,17 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
end end
describe "organisation_relationships#delete_housing_provider" do describe "organisation_relationships#delete_stock_owner" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:stock_owner) { FactoryBot.create(:organisation) }
let(:params) do let(:params) do
{ {
"target_organisation_id": housing_provider.id, "target_organisation_id": stock_owner.id,
} }
end end
let(:request) { delete "/organisations/#{organisation.id}/housing-providers", headers:, params: } let(:request) { delete "/organisations/#{organisation.id}/stock-owners", headers:, params: }
before do before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
end end
it "deletes the new organisation relationship" do it "deletes the new organisation relationship" do
@ -209,7 +209,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "redirects to the organisation list" do it "redirects to the organisation list" do
request request
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") expect(response).to redirect_to("/organisations/#{organisation.id}/stock-owners")
end end
end end
@ -248,16 +248,16 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
sign_in user sign_in user
end end
context "when accessing the housing providers tab" do context "when accessing the stock owners tab" do
context "with an organisation that the user belongs to" do context "with an organisation that the user belongs to" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:stock_owner) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } let!(:other_org_stock_owner) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") }
before do before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_stock_owner)
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} get "/organisations/#{organisation.id}/stock-owners", headers:, params: {}
end end
it "shows the tab navigation" do it "shows the tab navigation" do
@ -265,29 +265,29 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
end end
it "doesn't show an add housing provider button" do it "doesn't show an add stock owner button" do
expect(page).not_to have_link("Add a housing provider") expect(page).not_to have_link("Add a stock owner")
end end
it "shows a table of housing providers" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name) expect(response.body).to include(stock_owner.name)
end end
it "shows only housing providers for the current user's organisation" do it "shows only stock owners for the current user's organisation" do
expect(page).to have_content(housing_provider.name) expect(page).to have_content(stock_owner.name)
expect(page).not_to have_content(other_org_housing_provider.name) expect(page).not_to have_content(other_org_stock_owner.name)
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total housing providers") expect(page).to have_content("1 total stock owners")
end end
end end
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do
before do before do
get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {} get "/organisations/#{unauthorised_organisation.id}/stock-owners", headers:, params: {}
end end
it "returns not found 404 from users page" do it "returns not found 404 from users page" do
@ -363,18 +363,18 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
sign_in user sign_in user
end end
describe "organisation_relationships#create_housing_provider" do describe "organisation_relationships#create_stock_owner" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:stock_owner) { FactoryBot.create(:organisation) }
let(:params) do let(:params) do
{ {
"organisation_relationship": { "organisation_relationship": {
"parent_organisation_id": housing_provider.id, "parent_organisation_id": stock_owner.id,
}, },
} }
end end
let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: } let(:request) { post "/organisations/#{organisation.id}/stock-owners", headers:, params: }
it "creates a new organisation relationship" do it "creates a new organisation relationship" do
expect { request }.to change(OrganisationRelationship, :count).by(1) expect { request }.to change(OrganisationRelationship, :count).by(1)
@ -382,12 +382,12 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "sets the organisation relationship attributes correctly" do it "sets the organisation relationship attributes correctly" do
request request
expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id) expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: stock_owner.id)
end end
it "redirects to the organisation list" do it "redirects to the organisation list" do
request request
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") expect(response).to redirect_to("/organisations/#{organisation.id}/stock-owners")
end end
end end
@ -419,17 +419,17 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
end end
describe "organisation_relationships#delete_housing_provider" do describe "organisation_relationships#delete_stock_owner" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:stock_owner) { FactoryBot.create(:organisation) }
let(:params) do let(:params) do
{ {
"target_organisation_id": housing_provider.id, "target_organisation_id": stock_owner.id,
} }
end end
let(:request) { delete "/organisations/#{organisation.id}/housing-providers", headers:, params: } let(:request) { delete "/organisations/#{organisation.id}/stock-owners", headers:, params: }
before do before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
end end
it "deletes the new organisation relationship" do it "deletes the new organisation relationship" do
@ -438,7 +438,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "redirects to the organisation list" do it "redirects to the organisation list" do
request request
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") expect(response).to redirect_to("/organisations/#{organisation.id}/stock-owners")
end end
end end
@ -469,15 +469,15 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
end end
context "when viewing a specific organisation's housing providers" do context "when viewing a specific organisation's stock owners" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:stock_owner) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } let!(:other_org_stock_owner) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") } let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider) FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_stock_owner)
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} get "/organisations/#{organisation.id}/stock-owners", headers:, params: {}
end end
it "displays the name of the organisation" do it "displays the name of the organisation" do
@ -489,15 +489,15 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(page).to have_content("Users") expect(page).to have_content("Users")
end end
it "shows a table of housing providers" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name) expect(response.body).to include(stock_owner.name)
end end
it "shows only housing providers for this organisation" do it "shows only stock owners for this organisation" do
expect(page).to have_content(housing_provider.name) expect(page).to have_content(stock_owner.name)
expect(page).not_to have_content(other_org_housing_provider.name) expect(page).not_to have_content(other_org_stock_owner.name)
end end
it "shows remove link(s)" do it "shows remove link(s)" do
@ -505,16 +505,16 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total housing providers") expect(page).to have_content("1 total stock owners")
end end
context "when adding a housing provider" do context "when adding a stock owner" do
before do before do
get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {} get "/organisations/#{organisation.id}/stock-owners/add", headers:, params: {}
end end
it "has the correct header" do it "has the correct header" do
expect(response.body).to include("What is the name of this organisation&#39;s housing provider?") expect(response.body).to include("What is the name of this organisation&#39;s stock owner?")
end end
it "shows an add button" do it "shows an add button" do
@ -562,7 +562,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(response.body).to include("Remove") expect(response.body).to include("Remove")
end end
context "when adding a housing provider" do context "when adding a stock owner" do
before do before do
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {} get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {}
end end

Loading…
Cancel
Save