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
elsif request.path.include?("organisations") && request.path.include?("schemes")
request.path
elsif request.path.include?("organisations") && request.path.include?("housing-providers")
elsif request.path.include?("organisations") && request.path.include?("stock-owners")
request.path
elsif request.path.include?("organisations") && request.path.include?("managing-agents")
request.path

34
app/controllers/organisation_relationships_controller.rb

@ -7,19 +7,19 @@ class OrganisationRelationshipsController < ApplicationController
before_action :organisations
before_action :target_organisation, only: %i[
remove_housing_provider
remove_stock_owner
remove_managing_agent
delete_housing_provider
delete_stock_owner
delete_managing_agent
]
def housing_providers
housing_providers = organisation.housing_providers
unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term)
def stock_owners
stock_owners = organisation.stock_owners
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
@total_count = housing_providers.size
@total_count = stock_owners.size
end
def managing_agents
@ -31,7 +31,7 @@ class OrganisationRelationshipsController < ApplicationController
@total_count = managing_agents.size
end
def add_housing_provider
def add_stock_owner
@organisation_relationship = organisation.parent_organisation_relationships.new
end
@ -39,14 +39,14 @@ class OrganisationRelationshipsController < ApplicationController
@organisation_relationship = organisation.child_organisation_relationships.new
end
def create_housing_provider
def create_stock_owner
@organisation_relationship = organisation.parent_organisation_relationships.new(organisation_relationship_params)
if @organisation_relationship.save(context: :housing_provider)
flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers"
redirect_to housing_providers_organisation_path
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"} stock owners"
redirect_to stock_owners_organisation_path
else
@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
@ -61,15 +61,15 @@ class OrganisationRelationshipsController < ApplicationController
end
end
def remove_housing_provider; end
def remove_stock_owner; end
def delete_housing_provider
def delete_stock_owner
OrganisationRelationship.find_by!(
child_organisation: organisation,
parent_organisation: target_organisation,
).destroy!
flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers"
redirect_to housing_providers_organisation_path
flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners"
redirect_to stock_owners_organisation_path
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("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("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?),
].compact
else
@ -26,7 +26,7 @@ module NavigationItemsHelper
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("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?),
].compact
end
@ -40,7 +40,7 @@ module NavigationItemsHelper
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("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?),
].compact
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,
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("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?),
].compact
end
@ -104,8 +104,8 @@ private
path.include?("/organisations") && path.include?("/details")
end
def housing_providers_path?(path)
path.include?("/housing-providers")
def stock_owners_path?(path)
path.include?("/stock-owners")
end
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)
super
@id = "housing_provider"
@id = "stock_owner"
@header = ""
@description = ""
@subsection = subsection
@ -9,7 +9,7 @@ class Form::Lettings::Pages::HousingProvider < ::Form::Page
def questions
@questions ||= [
Form::Lettings::Questions::HousingProvider.new(nil, nil, self),
Form::Lettings::Questions::StockOwner.new(nil, nil, self),
]
end
@ -17,17 +17,17 @@ class Form::Lettings::Pages::HousingProvider < ::Form::Page
return false unless current_user
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?
return true if housing_providers.count >= 1
return true if stock_owners.count >= 1
log.update!(owning_organisation: current_user.organisation)
else
return false if housing_providers.count.zero?
return true if housing_providers.count > 1
return false if stock_owners.count.zero?
return true if stock_owners.count > 1
log.update!(owning_organisation: housing_providers.first)
log.update!(owning_organisation: stock_owners.first)
end
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
def initialize(id, hsh, page)
super
@id = "owning_organisation_id"
@check_answer_label = "Housing provider"
@check_answer_label = "Stock owner"
@header = "Which organisation owns this property?"
@type = "select"
@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)"
end
answer_opts.merge(housing_providers_answer_options)
answer_opts.merge(stock_owners_answer_options)
end
def displayed_answer_options(log, user = nil)
@ -44,12 +44,12 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question
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?
housing_providers.count.zero?
stock_owners.count.zero?
else
housing_providers.count <= 1
stock_owners.count <= 1
end
end
@ -63,11 +63,11 @@ private
true
end
def housing_providers_answer_options
def stock_owners_answer_options
if current_user.support?
Organisation
else
current_user.organisation.housing_providers
current_user.organisation.stock_owners
end.pluck(:id, :name).to_h
end
end

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

@ -9,7 +9,7 @@ class Form::Lettings::Subsections::Setup < ::Form::Subsection
def pages
@pages ||= [
organisation_page,
housing_provider_page,
stock_owner_page,
managing_organisation_page,
created_by_page,
Form::Lettings::Pages::NeedsType.new(nil, nil, self),
@ -35,10 +35,10 @@ private
Form::Common::Pages::Organisation.new(nil, nil, self)
end
def housing_provider_page
def stock_owner_page
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
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_organisations, through: :child_organisation_relationships
has_many :housing_provider_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship"
has_many :housing_providers, through: :housing_provider_relationships, source: :parent_organisation
has_many :stock_owner_relationships, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship"
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_agents, through: :managing_agent_relationships, source: :child_organisation

10
app/models/organisation_relationship.rb

@ -1,17 +1,17 @@
class OrganisationRelationship < ApplicationRecord
belongs_to :child_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 :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") }
validate :validate_housing_provider_owns_stock, on: :housing_provider
validate :validate_stock_owner_owns_stock, on: :stock_owner
private
def validate_housing_provider_owns_stock
def validate_stock_owner_owns_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

2
app/models/scheme.rb

@ -103,7 +103,7 @@ class Scheme < ApplicationRecord
ARRANGEMENT_TYPE = {
"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",
"Another organisation": "O",
"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 %>">
<%= govuk_table do |table| %>
<%= 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 %>
<% @housing_providers.each do |housing_provider| %>
<% @stock_owners.each do |stock_owner| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: housing_provider.name) %>
<% row.cell(text: stock_owner.name) %>
<% if current_user.data_coordinator? || current_user.support? %>
<% row.cell(html_attributes: {
scope: "row",
class: "govuk-!-text-align-right",
}) 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 %>

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? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= 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) %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's housing provider?", sub: nil } %>
<p class="govuk-body">Start typing to search for a housing provider</p>
<%= 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 stock owner</p>
<% else %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% end %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %>
<p class="govuk-body">Start typing to search for your housing provider</p>
<%= 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 stock owner</p>
<% end %>
<% answer_options = { "" => "Select an option" } %>
<% @organisations.each do |organisation| %>
@ -23,7 +23,7 @@
f:,
} %>
<%= 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">
<li>Double check the spelling and try again</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? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= 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 %>
<% if current_user.support? %>
<%= 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 %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% 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 %>
<%= govuk_warning_text text: "You will no longer be able to submit logs for #{@target_organisation.name}" %>
<div class="govuk-button-group">
<%= 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>
<% 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? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
<h2 class="govuk-visually-hidden">Housing Providers</h2>
<p class="govuk-body">This organisation can submit logs for its housing providers.</p>
<h2 class="govuk-visually-hidden">Stock Owners</h2>
<p class="govuk-body">This organisation can submit logs for its stock owners.</p>
<% 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 %>
<% else %>
<%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: current_user.organisation.name } %>
<p class="govuk-body">Your organisation can submit logs for its housing providers.</p>
<%= 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 stock owners.</p>
<% 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 %>
<% 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 %>
<% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", 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: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a stock owner", value: @searched) %>
<%= 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: "stock owners" } %>
<% end %>

2
config/locales/en.yml

@ -116,7 +116,7 @@ en:
organisation:
name_missing: "Enter the name of the organisation"
provider_type_missing: "Select the organisation type"
housing_provider:
stock_owner:
blank: "You must choose a 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."

10
config/routes.rb

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

12
db/seeds.rb

@ -8,8 +8,8 @@
# rubocop:disable Rails/Output
unless Rails.env.test?
housing_provider1 = Organisation.find_or_create_by!(
name: "Housing Provider 1",
stock_owner1 = Organisation.find_or_create_by!(
name: "Stock Owner 1",
address_line1: "2 Marsham Street",
address_line2: "London",
postcode: "SW1P 4DF",
@ -18,8 +18,8 @@ unless Rails.env.test?
managing_agents_label: "None",
provider_type: "LA",
)
housing_provider2 = Organisation.find_or_create_by!(
name: "Housing Provider 2",
stock_owner2 = Organisation.find_or_create_by!(
name: "Stock Owner 2",
address_line1: "2 Marsham Street",
address_line2: "London",
postcode: "SW1P 4DF",
@ -130,11 +130,11 @@ unless Rails.env.test?
end
OrganisationRelationship.find_or_create_by!(
parent_organisation: housing_provider1,
parent_organisation: stock_owner1,
child_organisation: org,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: housing_provider2,
parent_organisation: stock_owner2,
child_organisation: org,
)
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")
log_id = page.current_path.scan(/\d/).join
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")
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
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"
expect(page).to have_content("You didn’t answer this question")
end
@ -613,7 +613,7 @@ RSpec.describe "Schemes scheme Features" do
let!(:another_organisation) { FactoryBot.create(:organisation, name: "Another Org") }
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
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("Users", users_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),
]
end
@ -364,7 +364,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_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),
]
end
@ -382,7 +382,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, true),
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),
]
end
@ -400,7 +400,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, false),
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),
]
end
@ -418,7 +418,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", 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),
]
end
@ -436,7 +436,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true),
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),
]
end
@ -454,7 +454,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", 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),
]
end
@ -632,7 +632,7 @@ RSpec.describe NavigationItemsHelper do
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("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),
]
end
@ -662,7 +662,7 @@ RSpec.describe NavigationItemsHelper do
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("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),
]
end
@ -692,7 +692,7 @@ RSpec.describe NavigationItemsHelper do
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("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),
]
end
@ -722,7 +722,7 @@ RSpec.describe NavigationItemsHelper do
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("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),
]
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"
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) }
let(:page_id) { nil }
@ -17,7 +17,7 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end
it "has the correct id" do
expect(page.id).to eq("housing_provider")
expect(page.id).to eq("stock_owner")
end
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))
end
context "with 0 housing_providers" do
context "with 0 stock_owners" do
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
@ -73,14 +73,14 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end
end
context "with 1 housing_providers" do
let(:housing_provider) { create(:organisation) }
context "with 1 stock_owners" do
let(:stock_owner) { create(:organisation) }
before do
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: housing_provider,
parent_organisation: stock_owner,
)
end
@ -89,24 +89,24 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end
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
context "with >1 housing_providers" do
let(:housing_provider1) { create(:organisation) }
let(:housing_provider2) { create(:organisation) }
context "with >1 stock_owners" do
let(:stock_owner1) { create(:organisation) }
let(:stock_owner2) { create(:organisation) }
before do
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: housing_provider1,
parent_organisation: stock_owner1,
)
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: housing_provider2,
parent_organisation: stock_owner2,
)
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))
end
context "with 0 housing_providers" do
context "with 0 stock_owners" do
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
@ -135,7 +135,7 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do
end
end
context "with >0 housing_providers" do
context "with >0 stock_owners" do
before do
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"
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) }
let(:question_id) { nil }
@ -22,7 +22,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
end
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
it "has the correct type" do
@ -55,7 +55,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
question.current_user = user
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)
end
end
@ -94,24 +94,24 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
context "when org holds own stock", :aggregate_failures do
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
user.organisation.housing_providers.delete_all
user.organisation.stock_owners.delete_all
end
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
end
end
context "when housing providers != 0" do
context "when stock owners != 0" do
before do
create(:organisation_relationship, child_organisation: user.organisation)
end
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
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
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
create(:organisation_relationship, child_organisation: user.organisation)
end
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
end
end
context "when housing providers >= 2" do
context "when stock owners >= 2" do
before do
create(:organisation_relationship, child_organisation: user.organisation)
create(:organisation_relationship, child_organisation: user.organisation)
end
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
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
expect(setup.pages.map(&:id)).to eq(
%w[
housing_provider
stock_owner
managing_organisation
created_by
needs_type
@ -41,7 +41,7 @@ RSpec.describe Form::Lettings::Subsections::Setup, type: :model do
it "has correct pages" do
expect(setup.pages.map(&:id)).to eq(
%w[
housing_provider
stock_owner
managing_organisation
created_by
needs_type

4
spec/models/organisation_relationship_spec.rb

@ -16,9 +16,9 @@ RSpec.describe OrganisationRelationship do
end
end
describe "child#housing_providers" do
describe "child#stock_owners" 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

6
spec/models/organisation_spec.rb

@ -74,9 +74,9 @@ RSpec.describe Organisation, type: :model do
)
end
it "has correct housing_providers" do
expect(child_organisation.housing_providers).to eq([organisation])
expect(grandchild_organisation.housing_providers).to eq([child_organisation])
it "has correct stock_owners" do
expect(child_organisation.stock_owners).to eq([organisation])
expect(grandchild_organisation.stock_owners).to eq([child_organisation])
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(:managing_organisation) { create(:organisation) }
let(:managing_organisation_too) { create(:organisation) }
let(:housing_provider) { create(:organisation) }
let(:stock_owner) { create(:organisation) }
let(:support_user) { create(:user, :support) }
before do
organisation.housing_providers << housing_provider
organisation.stock_owners << stock_owner
organisation.managing_agents << managing_organisation
organisation.managing_agents << managing_organisation_too
organisation.reload
@ -99,7 +99,7 @@ RSpec.describe FormController, type: :request do
end
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
end
@ -142,8 +142,8 @@ RSpec.describe FormController, type: :request do
{
id: lettings_log.id,
lettings_log: {
page: "housing_provider",
owning_organisation_id: housing_provider.id,
page: "stock_owner",
owning_organisation_id: stock_owner.id,
},
}
end
@ -162,13 +162,13 @@ RSpec.describe FormController, type: :request do
end
end
context "with only adding the housing provider" do
context "with only adding the stock owner" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: "housing_provider",
owning_organisation_id: housing_provider.id,
page: "stock_owner",
owning_organisation_id: stock_owner.id,
},
}
end
@ -420,7 +420,7 @@ RSpec.describe FormController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:managing_organisation) { create(:organisation) }
let(:managing_organisation_too) { create(:organisation) }
let(:housing_provider) { create(:organisation) }
let(:stock_owner) { create(:organisation) }
let(:params) do
{
id: lettings_log.id,
@ -432,11 +432,11 @@ RSpec.describe FormController, type: :request do
end
before do
organisation.housing_providers << housing_provider
organisation.stock_owners << stock_owner
organisation.managing_agents << managing_organisation
organisation.managing_agents << managing_organisation_too
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
end

146
spec/requests/organisation_relationships_controller_spec.rb

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

Loading…
Cancel
Save