diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index aea892a18..a1ec640eb 100644 --- a/app/helpers/schemes_helper.rb +++ b/app/helpers/schemes_helper.rb @@ -38,7 +38,8 @@ module SchemesHelper all_orgs = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } user_org = [OpenStruct.new(id: current_user.organisation_id, name: current_user.organisation.name)] stock_owners = current_user.organisation.stock_owners.map { |org| OpenStruct.new(id: org.id, name: org.name) } - current_user.support? ? all_orgs : user_org + stock_owners + merged_organisations = current_user.organisation.absorbed_organisations.merged_during_open_collection_period.map { |org| OpenStruct.new(id: org.id, name: org.name) } + current_user.support? ? all_orgs : user_org + stock_owners + merged_organisations end def null_option diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 1e05bddab..077f0413e 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -146,4 +146,8 @@ class Organisation < ApplicationRecord absorbed_organisations.merged_during_open_collection_period.group_by(&:merge_date) end + + def has_recent_absorbed_organisations? + absorbed_organisations&.merged_during_open_collection_period.present? + end end diff --git a/app/views/schemes/details.html.erb b/app/views/schemes/details.html.erb index 3dc6208b1..9c0c333e2 100644 --- a/app/views/schemes/details.html.erb +++ b/app/views/schemes/details.html.erb @@ -44,7 +44,7 @@ :description, legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> - <% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? %> + <% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <% else %> <%= f.govuk_collection_select :owning_organisation_id, diff --git a/app/views/schemes/edit_name.html.erb b/app/views/schemes/edit_name.html.erb index 0c7c1091e..e908fd1b5 100644 --- a/app/views/schemes/edit_name.html.erb +++ b/app/views/schemes/edit_name.html.erb @@ -25,7 +25,7 @@ label: { text: "This scheme contains confidential information" } %> <% end %> - <% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? %> + <% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <% else %> <%= f.govuk_collection_select :owning_organisation_id, diff --git a/app/views/schemes/new.html.erb b/app/views/schemes/new.html.erb index af5c2089a..1be0f7f74 100644 --- a/app/views/schemes/new.html.erb +++ b/app/views/schemes/new.html.erb @@ -44,7 +44,7 @@ :description, legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> - <% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? %> + <% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <% else %> <%= f.govuk_collection_select :owning_organisation_id, diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 997526edb..3016c3f4b 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -2224,6 +2224,47 @@ RSpec.describe SchemesController, type: :request do end end + context "when there are no stock owners" do + before do + get "/schemes/#{scheme.id}/edit-name" + end + + context "and there are no absorbed organisations" do + it "does not include the owning organisation question" do + expect(response).to have_http_status(:ok) + expect(page).not_to have_content("Which organisation owns the housing stock for this scheme?") + end + end + + context "and there are organisations absorbed during an open collection period" do + let(:merged_organisation) { create(:organisation) } + + before do + merged_organisation.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today) + get "/schemes/#{scheme.id}/edit-name" + end + + it "includes the owning organisation question" do + expect(response).to have_http_status(:ok) + expect(page).to have_content("Which organisation owns the housing stock for this scheme?") + end + end + + context "and there are no recently absorbed organisations" do + let(:merged_organisation) { create(:organisation) } + + before do + merged_organisation.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today - 2.years) + get "/schemes/#{scheme.id}/edit-name" + end + + it "does not include the owning organisation question" do + expect(response).to have_http_status(:ok) + expect(page).not_to have_content("Which organisation owns the housing stock for this scheme?") + end + end + end + context "when attempting to access secondary-client-group scheme page for another organisation" do before do get "/schemes/#{another_scheme.id}/edit-name"