Browse Source

CLDC-3011 Display scheme owner question for absorbing orgs (#2066)

* Display scheme owner question for absorbing orgs

* Add test
pull/2075/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
259252ae37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/helpers/schemes_helper.rb
  2. 4
      app/models/organisation.rb
  3. 2
      app/views/schemes/details.html.erb
  4. 2
      app/views/schemes/edit_name.html.erb
  5. 2
      app/views/schemes/new.html.erb
  6. 41
      spec/requests/schemes_controller_spec.rb

3
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) } 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)] 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) } 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 end
def null_option def null_option

4
app/models/organisation.rb

@ -146,4 +146,8 @@ class Organisation < ApplicationRecord
absorbed_organisations.merged_during_open_collection_period.group_by(&:merge_date) absorbed_organisations.merged_during_open_collection_period.group_by(&:merge_date)
end end
def has_recent_absorbed_organisations?
absorbed_organisations&.merged_during_open_collection_period.present?
end
end end

2
app/views/schemes/details.html.erb

@ -44,7 +44,7 @@
:description, :description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> 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 %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %> <% else %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,

2
app/views/schemes/edit_name.html.erb

@ -25,7 +25,7 @@
label: { text: "This scheme contains confidential information" } %> label: { text: "This scheme contains confidential information" } %>
<% end %> <% 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 %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %> <% else %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,

2
app/views/schemes/new.html.erb

@ -44,7 +44,7 @@
:description, :description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> 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 %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %> <% else %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,

41
spec/requests/schemes_controller_spec.rb

@ -2224,6 +2224,47 @@ RSpec.describe SchemesController, type: :request do
end end
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 context "when attempting to access secondary-client-group scheme page for another organisation" do
before do before do
get "/schemes/#{another_scheme.id}/edit-name" get "/schemes/#{another_scheme.id}/edit-name"

Loading…
Cancel
Save