Browse Source

feat: add case and _ replacements

pull/1104/head
natdeanlewissoftwire 4 years ago
parent
commit
c4820b0bea
  1. 30
      app/controllers/organisation_relationships_controller.rb
  2. 10
      app/helpers/navigation_items_helper.rb
  3. 12
      app/models/form/lettings/pages/housing_provider.rb
  4. 14
      app/models/form/lettings/questions/housing_provider.rb
  5. 4
      app/models/form/lettings/subsections/setup.rb
  6. 4
      app/models/organisation.rb
  7. 10
      app/models/organisation_relationship.rb
  8. 6
      app/views/organisation_relationships/_housing_provider_list.erb
  9. 4
      app/views/organisation_relationships/add_housing_provider.html.erb
  10. 6
      app/views/organisation_relationships/housing_providers.html.erb
  11. 6
      app/views/organisation_relationships/remove_housing_provider.html.erb
  12. 2
      config/locales/en.yml
  13. 10
      config/routes.rb
  14. 12
      db/seeds.rb
  15. 2
      spec/features/lettings_log_spec.rb
  16. 22
      spec/helpers/navigation_items_helper_spec.rb
  17. 26
      spec/models/form/lettings/pages/housing_provider_spec.rb
  18. 12
      spec/models/form/lettings/questions/housing_provider_spec.rb
  19. 4
      spec/models/form/lettings/subsections/setup_spec.rb
  20. 4
      spec/models/organisation_relationship_spec.rb
  21. 6
      spec/models/organisation_spec.rb
  22. 20
      spec/requests/form_controller_spec.rb
  23. 74
      spec/requests/organisation_relationships_controller_spec.rb

30
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)
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 housing_providers_organisation_path
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"} stock owners"
redirect_to housing_providers_organisation_path
redirect_to stock_owners_organisation_path
end
def remove_managing_agent; end

10
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,7 +104,7 @@ private
path.include?("/organisations") && path.include?("/details")
end
def housing_providers_path?(path)
def stock_owners_path?(path)
path.include?("/housing-providers")
end

12
app/models/form/lettings/pages/housing_provider.rb

@ -1,7 +1,7 @@
class Form::Lettings::Pages::HousingProvider < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "housing_provider"
@id = "stock_owner"
@header = ""
@description = ""
@subsection = subsection
@ -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

14
app/models/form/lettings/questions/housing_provider.rb

@ -4,7 +4,7 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question
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

4
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,7 +35,7 @@ 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)

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

6
app/views/organisation_relationships/_housing_provider_list.erb

@ -3,16 +3,16 @@
<%= 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: "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 %>

4
app/views/organisation_relationships/add_housing_provider.html.erb

@ -1,8 +1,8 @@
<%= 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 stock owner?", sub: nil } %>
<p class="govuk-body">Start typing to search for a stock owner</p>

6
app/views/organisation_relationships/housing_providers.html.erb

@ -2,7 +2,7 @@
<% 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>
<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 stock owners.</p>
@ -15,10 +15,10 @@
<% end %>
<% end %>
<% if current_user.support? || current_user.data_coordinator? %>
<%= govuk_button_link_to "Add a stock owner", 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 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: "stock owners" } %>
<% end %>

6
app/views/organisation_relationships/remove_housing_provider.html.erb

@ -1,8 +1,8 @@
<%= 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) %>
@ -16,6 +16,6 @@
<%= 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 %>

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 "housing-providers", to: "organisation_relationships#stock_owners"
get "housing-providers/add", to: "organisation_relationships#add_stock_owner"
get "housing-providers/remove", to: "organisation_relationships#remove_stock_owner"
post "housing-providers", to: "organisation_relationships#create_stock_owner"
delete "housing-providers", 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

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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", 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}/housing-providers", false),
NavigationItemsHelper::NavigationItem.new("Managing agents", "/organisations/#{current_user.organisation.id}/managing-agents", false),
]
end

26
spec/models/form/lettings/pages/housing_provider_spec.rb

@ -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)

12
spec/models/form/lettings/questions/housing_provider_spec.rb

@ -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
@ -96,11 +96,11 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model 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
@ -111,7 +111,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
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
@ -126,7 +126,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
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
@ -138,7 +138,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
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

20
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
@ -167,8 +167,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
@ -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

74
spec/requests/organisation_relationships_controller_spec.rb

@ -16,13 +16,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request 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)
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}/housing-providers", headers:, params: {}
end
@ -38,12 +38,12 @@ RSpec.describe OrganisationRelationshipsController, type: :request 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 stock owners 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)
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
@ -134,13 +134,13 @@ 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
@ -153,7 +153,7 @@ 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
@ -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: }
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
@ -250,13 +250,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request 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)
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}/housing-providers", headers:, params: {}
end
@ -272,12 +272,12 @@ RSpec.describe OrganisationRelationshipsController, type: :request 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 stock owners 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)
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
@ -363,13 +363,13 @@ 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
@ -382,7 +382,7 @@ 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
@ -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: }
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
@ -470,13 +470,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
context "when viewing a specific organisation's stock owners" 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)
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}/housing-providers", headers:, params: {}
end
@ -492,12 +492,12 @@ RSpec.describe OrganisationRelationshipsController, type: :request 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 stock owners for this organisation" do
expect(page).to have_content(housing_provider.name)
expect(page).not_to have_content(other_org_housing_provider.name)
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

Loading…
Cancel
Save