From 75206fdde9cc76fd3c0c201eee980ae34a8ea39b Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Tue, 18 Oct 2022 09:27:56 +0100 Subject: [PATCH 01/18] [CLDC-1679] Add relationshop type to org relationship (#947) --- app/models/organisation_relationship.rb | 7 +++++++ ..._relationship_type_to_org_relationships.rb | 10 ++++++++++ db/schema.rb | 8 ++++---- spec/models/organisation_spec.rb | 20 +++++++++++++++++-- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb diff --git a/app/models/organisation_relationship.rb b/app/models/organisation_relationship.rb index 034fc5d0e..5c50c3e0f 100644 --- a/app/models/organisation_relationship.rb +++ b/app/models/organisation_relationship.rb @@ -1,4 +1,11 @@ class OrganisationRelationship < ApplicationRecord belongs_to :child_organisation, class_name: "Organisation" belongs_to :parent_organisation, class_name: "Organisation" + + RELATIONSHIP_TYPE = { + "owning": 0, + "managing": 1, + }.freeze + + enum relationship_type: RELATIONSHIP_TYPE end diff --git a/db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb b/db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb new file mode 100644 index 000000000..a45cff1d9 --- /dev/null +++ b/db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb @@ -0,0 +1,10 @@ +class AddRelationshipTypeToOrgRelationships < ActiveRecord::Migration[7.0] + def change + add_column( + :organisation_relationships, + :relationship_type, + :integer, + null: false, # rubocop:disable Rails/NotNullColumn + ) + end +end diff --git a/db/schema.rb b/db/schema.rb index 2af1b4f54..59a0dbd24 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do +ActiveRecord::Schema[7.0].define(version: 2022_10_17_095918) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -277,6 +277,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do t.integer "parent_organisation_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "relationship_type", null: false end create_table "organisation_rent_periods", force: :cascade do |t| @@ -358,15 +359,14 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do t.integer "hholdcount" t.integer "age3" t.integer "age3_known" + t.integer "income1" + t.integer "income1nk" t.integer "age4" t.integer "age4_known" t.integer "age5" t.integer "age5_known" t.integer "age6" t.integer "age6_known" - t.integer "proplen" - t.integer "income1" - t.integer "income1nk" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 7bc1d7cc1..b6011cf20 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -27,11 +27,27 @@ RSpec.describe Organisation, type: :model do .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type #{I18n.t('validations.organisation.provider_type_missing')}") end - context "with parent/child association" do + context "with managing association" do let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } before do - FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation) + FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 0) + end + + it "has correct child" do + expect(organisation.child_organisations.first).to eq(child_organisation) + end + + it "has correct parent" do + expect(child_organisation.parent_organisations.first).to eq(organisation) + end + end + + context "with owning association" do + let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + + before do + FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 1) end it "has correct child" do From 4aede34cf00b1e37a30a3606c2d1a2ec6100c968 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:32:20 +0100 Subject: [PATCH 02/18] Cldc 1661 housing providers branch (#950) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break Co-authored-by: Jack S --- Gemfile.lock | 6 +- app/components/search_component.html.erb | 2 +- app/components/search_component.rb | 2 + .../organisation_relationships_controller.rb | 36 ++++++ app/helpers/navigation_items_helper.rb | 18 ++- app/models/organisation.rb | 6 +- app/models/organisation_relationship.rb | 6 +- app/views/logs/index.html.erb | 2 +- .../_housing_provider_list.erb | 22 ++++ .../housing_providers.html.erb | 24 ++++ app/views/organisations/index.html.erb | 2 +- app/views/organisations/logs.html.erb | 2 +- config/routes.rb | 1 + ...019082625_rename_managing_agents_column.rb | 5 + db/schema.rb | 4 +- db/seeds.rb | 21 +++- spec/factories/organisation.rb | 5 - spec/factories/organisation_relationship.rb | 14 +++ spec/helpers/navigation_items_helper_spec.rb | 21 ++++ spec/models/organisation_spec.rb | 62 ++++++++--- .../requests/lettings_logs_controller_spec.rb | 2 +- .../requests/organisations_controller_spec.rb | 104 +++++++++++++++++- spec/requests/sales_logs_controller_spec.rb | 2 +- 23 files changed, 325 insertions(+), 44 deletions(-) create mode 100644 app/controllers/organisation_relationships_controller.rb create mode 100644 app/views/organisation_relationships/_housing_provider_list.erb create mode 100644 app/views/organisation_relationships/housing_providers.html.erb create mode 100644 db/migrate/20221019082625_rename_managing_agents_column.rb create mode 100644 spec/factories/organisation_relationship.rb diff --git a/Gemfile.lock b/Gemfile.lock index 9e0fe5371..2a9fb454f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -225,11 +225,11 @@ GEM net-protocol timeout nio4r (2.5.8) - nokogiri (1.13.8-arm64-darwin) + nokogiri (1.13.9-arm64-darwin) racc (~> 1.4) - nokogiri (1.13.8-x86_64-darwin) + nokogiri (1.13.9-x86_64-darwin) racc (~> 1.4) - nokogiri (1.13.8-x86_64-linux) + nokogiri (1.13.9-x86_64-linux) racc (~> 1.4) notifications-ruby-client (5.3.0) jwt (>= 1.5, < 3) diff --git a/app/components/search_component.html.erb b/app/components/search_component.html.erb index c63039b8c..2c10f3ed8 100644 --- a/app/components/search_component.html.erb +++ b/app/components/search_component.html.erb @@ -10,6 +10,6 @@ autocomplete: "off", class: "app-search__input" %> - <%= f.govuk_submit "Search", classes: "app-search__button" %> + <%= f.govuk_submit "Search", classes: "app-search__button govuk-button--secondary" %> <% end %> diff --git a/app/components/search_component.rb b/app/components/search_component.rb index 035500b54..23b5ea65e 100644 --- a/app/components/search_component.rb +++ b/app/components/search_component.rb @@ -15,6 +15,8 @@ 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") + request.path elsif request.path.include?("users") user_path(current_user) elsif request.path.include?("organisations") diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb new file mode 100644 index 000000000..98456ac7b --- /dev/null +++ b/app/controllers/organisation_relationships_controller.rb @@ -0,0 +1,36 @@ +class OrganisationRelationshipsController < ApplicationController + include Pagy::Backend + include Modules::SearchFilter + + before_action :authenticate_user! + before_action :authenticate_scope! + + def housing_providers + housing_providers = organisation.housing_providers + unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) + respond_to do |format| + format.html do + @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) + @searched = search_term.presence + @total_count = housing_providers.size + render "organisation_relationships/housing_providers", layout: "application" + end + end + end + +private + + def organisation + @organisation ||= Organisation.find(params[:id]) + end + + def search_term + params["search"] + end + + def authenticate_scope! + if current_user.organisation != organisation + render_not_found + end + end +end diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 3ac422c2d..a8cbef13d 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -17,6 +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)), ].compact else [ @@ -24,6 +25,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)), ].compact end end @@ -31,11 +33,12 @@ module NavigationItemsHelper def secondary_items(path, current_organisation_id) if current_user.organisation.holds_own_stock? [ - NavigationItem.new("Lettings logs", "/organisations/#{current_organisation_id}/lettings-logs", subnav_logs_path?(path)), - FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", sales_logs_current?(path)) : nil, + NavigationItem.new("Lettings logs", "/organisations/#{current_organisation_id}/lettings-logs", subnav_lettings_logs_path?(path)), + FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", subnav_sales_logs_path?(path)) : nil, 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", "/organisations/#{current_organisation_id}/housing-providers", housing_providers_path?(path)), ].compact else [ @@ -43,6 +46,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", "/organisations/#{current_organisation_id}/housing-providers", housing_providers_path?(path)), ].compact end end @@ -84,11 +88,19 @@ private (path.include?("/organisations") && path.include?("/users")) || path.include?("/users/") end - def subnav_logs_path?(path) + def subnav_lettings_logs_path?(path) path.include?("/organisations") && path.include?("/lettings-logs") end + def subnav_sales_logs_path?(path) + path.include?("/organisations") && path.include?("/sales-logs") + end + def subnav_details_path?(path) path.include?("/organisations") && path.include?("/details") end + + def housing_providers_path?(path) + path.include?("/housing-providers") + end end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 9eb039ab1..cc7bb49fd 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -13,9 +13,11 @@ 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, -> { where(relationship_type: OrganisationRelationship::OWNING) }, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" + has_many :housing_providers, through: :housing_provider_relationships, source: :parent_organisation + scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by, ->(param) { search_by_name(param) } - has_paper_trail auto_strip_attributes :name @@ -83,7 +85,7 @@ class Organisation < ApplicationRecord { name: "Rent_periods", value: rent_period_labels, editable: false, format: :bullet }, { name: "Owns housing stock", value: holds_own_stock ? "Yes" : "No", editable: false }, { name: "Other stock owners", value: other_stock_owners, editable: false }, - { name: "Managing agents", value: managing_agents, editable: false }, + { name: "Managing agents", value: managing_agents_label, editable: false }, { name: "Data protection agreement", value: data_protection_agreement_string, editable: false }, ] end diff --git a/app/models/organisation_relationship.rb b/app/models/organisation_relationship.rb index 5c50c3e0f..acda8d2c4 100644 --- a/app/models/organisation_relationship.rb +++ b/app/models/organisation_relationship.rb @@ -2,9 +2,11 @@ class OrganisationRelationship < ApplicationRecord belongs_to :child_organisation, class_name: "Organisation" belongs_to :parent_organisation, class_name: "Organisation" + OWNING = "owning".freeze + MANAGING = "managing".freeze RELATIONSHIP_TYPE = { - "owning": 0, - "managing": 1, + OWNING => 0, + MANAGING => 1, }.freeze enum relationship_type: RELATIONSHIP_TYPE diff --git a/app/views/logs/index.html.erb b/app/views/logs/index.html.erb index f84a487df..4ccf4a3fb 100644 --- a/app/views/logs/index.html.erb +++ b/app/views/logs/index.html.erb @@ -1,4 +1,4 @@ -<% item_label = format_label(@pagy.count, "log") %> +<% item_label = format_label(@pagy.count, "logs") %> <% title = format_title(@searched, "Logs", current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> diff --git a/app/views/organisation_relationships/_housing_provider_list.erb b/app/views/organisation_relationships/_housing_provider_list.erb new file mode 100644 index 000000000..e43766c5b --- /dev/null +++ b/app/views/organisation_relationships/_housing_provider_list.erb @@ -0,0 +1,22 @@ +
+ <%= 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)) %> + <% end %> + <% @housing_providers.each do |housing_provider| %> + <%= table.body do |body| %> + <%= body.row do |row| %> + <% row.cell(text: housing_provider.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/#{housing_provider.id}") %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> +
diff --git a/app/views/organisation_relationships/housing_providers.html.erb b/app/views/organisation_relationships/housing_providers.html.erb new file mode 100644 index 000000000..84f38cde6 --- /dev/null +++ b/app/views/organisation_relationships/housing_providers.html.erb @@ -0,0 +1,24 @@ +<% item_label = format_label(@pagy.count, "housing providers") %> +<% title = "Housing Providers" %> +<% content_for :title, title %> +<% if current_user.support? %> + <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> + <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> +

Housing Providers

+

This organisation can submit logs for its housing providers.

+<% else %> + <%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: nil } %> +

Your organisation can submit logs for its housing providers.

+<% end %> + +<% if @total_count == 0 %> +

This organisation does not currently have any housing providers.

+<% end %> +<% if current_user.data_coordinator? || current_user.support? %> + <%= govuk_button_link_to "Add a housing provider", housing_providers_organisation_path(organisation_id: @organisation.id), 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" } %> +<% end %> diff --git a/app/views/organisations/index.html.erb b/app/views/organisations/index.html.erb index b81922c5e..75a4d799c 100644 --- a/app/views/organisations/index.html.erb +++ b/app/views/organisations/index.html.erb @@ -1,4 +1,4 @@ -<% item_label = format_label(@pagy.count, "organisation") %> +<% item_label = format_label(@pagy.count, "organisations") %> <% title = format_title(@searched, "Organisations", current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> diff --git a/app/views/organisations/logs.html.erb b/app/views/organisations/logs.html.erb index f954a0839..94fe8e9bc 100644 --- a/app/views/organisations/logs.html.erb +++ b/app/views/organisations/logs.html.erb @@ -1,4 +1,4 @@ -<% item_label = format_label(@pagy.count, "log") %> +<% item_label = format_label(@pagy.count, "logs") %> <% title = format_title(@searched, "Logs", current_user, item_label, @pagy.count, @organisation.name) %> <% content_for :title, title %> diff --git a/config/routes.rb b/config/routes.rb index 0be5f5b6a..e703b853d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,6 +79,7 @@ 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" end end diff --git a/db/migrate/20221019082625_rename_managing_agents_column.rb b/db/migrate/20221019082625_rename_managing_agents_column.rb new file mode 100644 index 000000000..dd03a7435 --- /dev/null +++ b/db/migrate/20221019082625_rename_managing_agents_column.rb @@ -0,0 +1,5 @@ +class RenameManagingAgentsColumn < ActiveRecord::Migration[7.0] + def change + rename_column :organisations, :managing_agents, :managing_agents_label + end +end diff --git a/db/schema.rb b/db/schema.rb index 59a0dbd24..80f37a6b0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_10_17_095918) do +ActiveRecord::Schema[7.0].define(version: 2022_10_19_082625) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -297,7 +297,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_17_095918) do t.string "postcode" t.boolean "holds_own_stock" t.string "other_stock_owners" - t.string "managing_agents" + t.string "managing_agents_label" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "active" diff --git a/db/seeds.rb b/db/seeds.rb index 8491db6b6..2ad174195 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,6 +8,17 @@ # rubocop:disable Rails/Output unless Rails.env.test? + housing_provider = Organisation.find_or_create_by!( + name: "Housing Provider", + address_line1: "2 Marsham Street", + address_line2: "London", + postcode: "SW1P 4DF", + holds_own_stock: true, + other_stock_owners: "None", + managing_agents_label: "None", + provider_type: "LA", + ) + org = Organisation.find_or_create_by!( name: "DLUHC", address_line1: "2 Marsham Street", @@ -15,7 +26,7 @@ unless Rails.env.test? postcode: "SW1P 4DF", holds_own_stock: false, other_stock_owners: "None", - managing_agents: "None", + managing_agents_label: "None", provider_type: "LA", ) do info = "Seeded DLUHC Organisation" @@ -26,6 +37,12 @@ unless Rails.env.test? end end + OrganisationRelationship.create!( + child_organisation: org, + parent_organisation: housing_provider, + relationship_type: OrganisationRelationship::OWNING, + ) + if Rails.env.development? && User.count.zero? User.create!( name: "Provider", @@ -65,7 +82,7 @@ unless Rails.env.test? postcode: "BA21 4AT", holds_own_stock: false, other_stock_owners: "None", - managing_agents: "None", + managing_agents_label: "None", provider_type: "LA", ) diff --git a/spec/factories/organisation.rb b/spec/factories/organisation.rb index 8b02f030a..fa40663ac 100644 --- a/spec/factories/organisation.rb +++ b/spec/factories/organisation.rb @@ -17,9 +17,4 @@ FactoryBot.define do created_at { Time.zone.now } updated_at { Time.zone.now } end - - factory :organisation_relationship do - child_organisation { FactoryBot.create(:organisation) } - parent_organisation { FactoryBot.create(:organisation) } - end end diff --git a/spec/factories/organisation_relationship.rb b/spec/factories/organisation_relationship.rb new file mode 100644 index 000000000..418599902 --- /dev/null +++ b/spec/factories/organisation_relationship.rb @@ -0,0 +1,14 @@ +FactoryBot.define do + factory :organisation_relationship do + child_organisation { FactoryBot.create(:organisation) } + parent_organisation { FactoryBot.create(:organisation) } + + trait :owning do + relationship_type { OrganisationRelationship::OWNING } + end + + trait :managing do + relationship_type { OrganisationRelationship::MANAGING } + end + end +end diff --git a/spec/helpers/navigation_items_helper_spec.rb b/spec/helpers/navigation_items_helper_spec.rb index fc656d024..05599c3cf 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -20,6 +20,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), ] end @@ -35,6 +36,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), ] end @@ -50,6 +52,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), ] end @@ -65,6 +68,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), ] end @@ -80,6 +84,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), ] end @@ -95,6 +100,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), ] end @@ -246,6 +252,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), ] end @@ -272,6 +279,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), ] end @@ -298,6 +306,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), ] end @@ -324,6 +333,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), ] end @@ -346,6 +356,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), ] end @@ -362,6 +373,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), ] end @@ -378,6 +390,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), ] end @@ -394,6 +407,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), ] end @@ -410,6 +424,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), ] end @@ -426,6 +441,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), ] end @@ -442,6 +458,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), ] end @@ -618,6 +635,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), ] end @@ -646,6 +664,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), ] end @@ -674,6 +693,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), ] end @@ -702,6 +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), ] end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index b6011cf20..ec83e7469 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -27,35 +27,67 @@ RSpec.describe Organisation, type: :model do .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type #{I18n.t('validations.organisation.provider_type_missing')}") end - context "with managing association" do - let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + context "with parent/child associations", :aggregate_failures do + let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } before do - FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 0) + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation:, + parent_organisation: organisation, + ) + + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation: grandchild_organisation, + parent_organisation: child_organisation, + ) end - it "has correct child" do - expect(organisation.child_organisations.first).to eq(child_organisation) + it "has correct child_organisations" do + expect(organisation.child_organisations).to eq([child_organisation]) + expect(child_organisation.child_organisations).to eq([grandchild_organisation]) end - it "has correct parent" do - expect(child_organisation.parent_organisations.first).to eq(organisation) + it "has correct parent_organisations" do + expect(child_organisation.parent_organisations).to eq([organisation]) + expect(grandchild_organisation.parent_organisations).to eq([child_organisation]) end end - context "with owning association" do - let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + context "with owning association", :aggregate_failures do + let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } before do - FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 1) - end + FactoryBot.create( + :organisation_relationship, + :managing, + child_organisation:, + parent_organisation: organisation, + ) + + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation:, + parent_organisation: organisation, + ) - it "has correct child" do - expect(organisation.child_organisations.first).to eq(child_organisation) + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation: grandchild_organisation, + parent_organisation: child_organisation, + ) end - it "has correct parent" do - expect(child_organisation.parent_organisations.first).to eq(organisation) + it "has correct housing_providers" do + expect(child_organisation.housing_providers).to eq([organisation]) + expect(grandchild_organisation.housing_providers).to eq([child_organisation]) end end diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 651655139..db4226152 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -365,7 +365,7 @@ RSpec.describe LettingsLogsController, type: :request do it "has search results in the title" do get "/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {} - expect(page).to have_title("Logs (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + expect(page).to have_title("Logs (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") end it "shows lettings logs matching the id" do diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 6bc335921..25a1eb256 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -284,6 +284,54 @@ RSpec.describe OrganisationsController, type: :request do end end + context "when accessing the housing providers 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!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } + + before do + FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) + FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) + get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} + end + + it "shows the tab navigation" do + expected_html = "