diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb
index 682e1bc02..b59ee9864 100644
--- a/app/controllers/schemes_controller.rb
+++ b/app/controllers/schemes_controller.rb
@@ -310,7 +310,7 @@ private
end
def redirect_if_scheme_confirmed
- redirect_to @scheme if @scheme.confirmed?
+ redirect_to @scheme if @scheme.confirmed? && !current_user.support?
end
def deactivate_success_notice
diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb
index 80f4326f7..761a7ac44 100644
--- a/app/helpers/check_answers_helper.rb
+++ b/app/helpers/check_answers_helper.rb
@@ -12,7 +12,8 @@ module CheckAnswersHelper
end
def can_change_scheme_answer?(attribute_name, scheme)
- return false unless current_user.support? || current_user.data_coordinator?
+ return true if current_user.support?
+ return false unless current_user.data_coordinator?
editable_attributes = ["Name", "Confidential information", "Housing stock owned by"]
diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb
index 88022dd53..7a6695a44 100644
--- a/app/helpers/schemes_helper.rb
+++ b/app/helpers/schemes_helper.rb
@@ -1,23 +1,4 @@
module SchemesHelper
- def display_scheme_attributes(scheme)
- [
- { name: "Scheme code", value: scheme.id_to_display },
- { name: "Name", value: scheme.service_name, edit: true },
- { name: "Status", value: status_tag_from_resource(scheme) },
- { name: "Confidential information", value: scheme.sensitive, edit: true },
- { name: "Type of scheme", value: scheme.scheme_type },
- { name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act },
- { name: "Housing stock owned by", value: scheme.owning_organisation.name, edit: true },
- { name: "Support services provided by", value: scheme.arrangement_type },
- { name: "Primary client group", value: scheme.primary_client_group },
- { name: "Has another client group", value: scheme.has_other_client_group },
- scheme.has_other_client_group == "Yes" ? { name: "Secondary client group", value: scheme.secondary_client_group } : nil,
- { name: "Level of support given", value: scheme.support_type },
- { name: "Intended length of stay", value: scheme.intended_stay },
- { name: "Availability", value: scheme_availability(scheme) },
- ].compact
- end
-
def scheme_availability(scheme)
availability = ""
scheme_active_periods(scheme).each do |period|
diff --git a/app/models/scheme.rb b/app/models/scheme.rb
index 00db3924d..1598b31d3 100644
--- a/app/models/scheme.rb
+++ b/app/models/scheme.rb
@@ -187,37 +187,37 @@ class Scheme < ApplicationRecord
def check_details_attributes
[
{ name: "Scheme code", value: id_to_display, id: "id" },
- { name: "Name", value: service_name, id: "service_name" },
- { name: "Confidential information", value: sensitive, id: "sensitive" },
- { name: "Type of scheme", value: scheme_type, id: "scheme_type" },
- { name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act" },
- { name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id" },
- { name: "Support services provided by", value: arrangement_type, id: "arrangement_type" },
+ { name: "Name", value: service_name, id: "service_name", edit: true },
+ { name: "Confidential information", value: sensitive, id: "sensitive", edit: true },
+ { name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true },
+ { name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act", edit: true },
+ { name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id", edit: true },
+ { name: "Support services provided by", value: arrangement_type, id: "arrangement_type", edit: true },
]
end
def check_primary_client_attributes
[
- { name: "Primary client group", value: primary_client_group, id: "primary_client_group" },
+ { name: "Primary client group", value: primary_client_group, id: "primary_client_group", edit: true },
]
end
def check_secondary_client_confirmation_attributes
[
- { name: "Has another client group", value: has_other_client_group, id: "has_other_client_group" },
+ { name: "Has another client group", value: has_other_client_group, id: "has_other_client_group", edit: true },
]
end
def check_secondary_client_attributes
[
- { name: "Secondary client group", value: secondary_client_group, id: "secondary_client_group" },
+ { name: "Secondary client group", value: secondary_client_group, id: "secondary_client_group", edit: true },
]
end
def check_support_attributes
[
- { name: "Level of support given", value: support_type, id: "support_type" },
- { name: "Intended length of stay", value: intended_stay, id: "intended_stay" },
+ { name: "Level of support given", value: support_type, id: "support_type", edit: true },
+ { name: "Intended length of stay", value: intended_stay, id: "intended_stay", edit: true },
]
end
diff --git a/app/views/schemes/_scheme_summary_list_row.html.erb b/app/views/schemes/_scheme_summary_list_row.html.erb
index 309dcfe15..cf82ccd95 100644
--- a/app/views/schemes/_scheme_summary_list_row.html.erb
+++ b/app/views/schemes/_scheme_summary_list_row.html.erb
@@ -1,4 +1,4 @@
-
">
+
">
<%= attribute[:name].to_s %>
@@ -15,7 +15,7 @@
<% end %>
- <% if can_change_scheme_answer?(attribute[:name], scheme) %>
+ <% if can_change_scheme_answer?(attribute[:name], scheme) && attribute[:edit] %>
Change
diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb
index dccefc565..25a7fd221 100644
--- a/app/views/schemes/check_answers.html.erb
+++ b/app/views/schemes/check_answers.html.erb
@@ -9,7 +9,7 @@
Scheme
<% @scheme.check_details_attributes.each do |attr| %>
- <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: @scheme.confirmed? ? scheme_edit_name_path(@scheme) : scheme_details_path(@scheme, check_answers: true) } %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(@scheme) } %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>
diff --git a/app/views/schemes/confirm_secondary.html.erb b/app/views/schemes/confirm_secondary.html.erb
index 706d14c83..48b3ce404 100644
--- a/app/views/schemes/confirm_secondary.html.erb
+++ b/app/views/schemes/confirm_secondary.html.erb
@@ -23,9 +23,10 @@
<%= f.hidden_field :page, value: "confirm-secondary" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
+ <%= f.govuk_submit "Save changes" %>
+ <% else %>
+ <%= f.govuk_submit "Save and continue" %>
<% end %>
-
- <%= f.govuk_submit "Save and continue" %>
<% end %>
diff --git a/app/views/schemes/details.html.erb b/app/views/schemes/details.html.erb
index 9c0c333e2..4210a5f19 100644
--- a/app/views/schemes/details.html.erb
+++ b/app/views/schemes/details.html.erb
@@ -9,7 +9,11 @@
<%= f.govuk_error_summary %>
- <%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %>
+ <% if @scheme.id.present? %>
+ <%= render partial: "organisations/headings", locals: { main: "Scheme details", sub: @scheme.service_name } %>
+ <% else %>
+ <%= render partial: "organisations/headings", locals: { main: "Create a new supported housing scheme", sub: nil } %>
+ <% end %>
<%= f.govuk_text_field :service_name,
label: { text: "Scheme name", size: "m" },
@@ -72,8 +76,10 @@
<%= f.hidden_field :page, value: "details" %>
<% if request.query_parameters["check_answers"] %>
<%= f.hidden_field :check_answers, value: "true" %>
+ <%= f.govuk_submit "Save changes" %>
+ <% else %>
+ <%= f.govuk_submit "Save and continue" %>
<% end %>
- <%= f.govuk_submit "Save and continue" %>
<% end %>
diff --git a/app/views/schemes/primary_client_group.html.erb b/app/views/schemes/primary_client_group.html.erb
index 8fe852c89..aa98394df 100644
--- a/app/views/schemes/primary_client_group.html.erb
+++ b/app/views/schemes/primary_client_group.html.erb
@@ -25,14 +25,16 @@
legend: nil %>
<%= f.hidden_field :page, value: "primary-client-group" %>
- <% if request.query_parameters["check_answers"] == "true" %>
- <%= f.hidden_field :check_answers, value: "true" %>
- <% end %>
<% if request.query_parameters["select_managing_org"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
- <%= f.govuk_submit "Save and continue" %>
+ <% if request.query_parameters["check_answers"] == "true" %>
+ <%= f.hidden_field :check_answers, value: "true" %>
+ <%= f.govuk_submit "Save changes" %>
+ <% else %>
+ <%= f.govuk_submit "Save and continue" %>
+ <% end %>
<% end %>
diff --git a/app/views/schemes/secondary_client_group.html.erb b/app/views/schemes/secondary_client_group.html.erb
index fe292b1c2..a59d5d0ac 100644
--- a/app/views/schemes/secondary_client_group.html.erb
+++ b/app/views/schemes/secondary_client_group.html.erb
@@ -23,9 +23,10 @@
<%= f.hidden_field :page, value: "secondary-client-group" %>
<% if request.query_parameters["check_answers"] == "true" %>
<%= f.hidden_field :check_answers, value: "true" %>
+ <%= f.govuk_submit "Save changes" %>
+ <% else %>
+ <%= f.govuk_submit "Save and continue" %>
<% end %>
-
- <%= f.govuk_submit "Save and continue" %>
<% end %>
diff --git a/app/views/schemes/show.html.erb b/app/views/schemes/show.html.erb
index 1da4e86f5..213df690b 100644
--- a/app/views/schemes/show.html.erb
+++ b/app/views/schemes/show.html.erb
@@ -19,24 +19,29 @@
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id)) %>
Scheme
- <%= govuk_inset_text(text: edit_scheme_text(@scheme, current_user)) %>
-
- <%= govuk_summary_list do |summary_list| %>
- <% display_scheme_attributes(@scheme).each do |attr| %>
- <%= summary_list.row do |row| %>
- <% row.key { attr[:name] } %>
- <% row.value do %>
- <%= details_html(attr) %>
- <% if attr[:name] == "Status" && @scheme.confirmed? && @scheme.locations.confirmed.none? && LocationPolicy.new(current_user, @scheme.locations.new).create? %>
- Complete this scheme by adding a location using the <%= govuk_link_to("‘locations’ tab", scheme_locations_path(@scheme)) %>.
- <% end %>
- <% end %>
- <% if SchemePolicy.new(current_user, @scheme).update? %>
- <% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id)) if attr[:edit] %>
- <% end %>
+
+ <% @scheme.check_details_attributes.each do |attr| %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(scheme_id: @scheme.id) } %>
+ <% end %>
+
+ <% @scheme.check_primary_client_attributes.each do |attr| %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_primary_client_group_path(@scheme, check_answers: true) } %>
+ <% end %>
+
+ <% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true) } %>
+ <% end %>
+
+ <% if @scheme.has_other_client_group == "Yes" %>
+ <% @scheme.check_secondary_client_attributes.each do |attr| %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_secondary_client_group_path(@scheme, check_answers: true) } %>
<% end %>
<% end %>
- <% end %>
+
+ <% @scheme.check_support_attributes.each do |attr| %>
+ <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_path(@scheme, check_answers: true) } %>
+ <% end %>
+
diff --git a/app/views/schemes/support.html.erb b/app/views/schemes/support.html.erb
index be4587617..5b7292252 100644
--- a/app/views/schemes/support.html.erb
+++ b/app/views/schemes/support.html.erb
@@ -37,7 +37,12 @@
<%= f.hidden_field :page, value: "support" %>
- <%= f.govuk_submit "Save and continue" %>
+ <% if request.query_parameters["check_answers"] == "true" %>
+ <%= f.hidden_field :check_answers, value: "true" %>
+ <%= f.govuk_submit "Save changes" %>
+ <% else %>
+ <%= f.govuk_submit "Save and continue" %>
+ <% end %>
<% end %>
diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb
index 3877e3c99..7983bfa0a 100644
--- a/spec/factories/scheme.rb
+++ b/spec/factories/scheme.rb
@@ -4,7 +4,7 @@ FactoryBot.define do
sensitive { Faker::Number.within(range: 0..1) }
registered_under_care_act { 1 }
support_type { [0, 2, 3, 4, 5].sample }
- scheme_type { 0 }
+ scheme_type { 4 }
arrangement_type { "D" }
intended_stay { %w[M P S V X].sample }
primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
@@ -13,6 +13,7 @@ FactoryBot.define do
owning_organisation { FactoryBot.create(:organisation) }
confirmed { true }
created_at { Time.zone.local(2021, 4, 1) }
+ total_units { 2 }
trait :export do
sensitive { 1 }
registered_under_care_act { 1 }
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb
index 491a19bbc..242c40353 100644
--- a/spec/features/schemes_spec.rb
+++ b/spec/features/schemes_spec.rb
@@ -390,7 +390,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "does not let you change details other than the name, confidential information and housing stock owner" do
- assert_selector "a", text: "Change", count: 3
+ assert_selector "a", text: "Change", count: 11
end
end
end
@@ -621,7 +621,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays change links" do
- assert_selector "a", text: "Change", count: 11
+ assert_selector "a", text: "Change", count: 10
end
it "allows changing details questions" do
@@ -629,7 +629,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
fill_in "Scheme name", with: "Example"
- click_button "Save and continue"
+ click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
@@ -645,7 +645,7 @@ RSpec.describe "Schemes scheme Features" do
it "indicates if the scheme is not complete" do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first)
choose "Yes"
- click_button "Save and continue"
+ click_button "Save changes"
visit("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content("You didn’t answer this question")
end
@@ -687,7 +687,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays change links" do
- assert_selector "a", text: "Change", count: 12
+ assert_selector "a", text: "Change", count: 11
end
it "allows changing details questions" do
@@ -695,7 +695,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
fill_in "Scheme name", with: "Example"
- click_button "Save and continue"
+ click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
@@ -711,14 +711,14 @@ RSpec.describe "Schemes scheme Features" do
it "keeps the provider answer when switching between other provider options" do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first)
choose "Yes"
- click_button "Save and continue"
+ click_button "Save changes"
expect(find_field("Offenders and people at risk of offending")).to be_checked
end
it "does not display the answer if it's changed to the same support provider" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
choose "The same organisation that owns the housing stock"
- click_button "Save and continue"
+ click_button "Save changes"
expect(page).not_to have_content("Organisation providing support")
end
end
@@ -766,11 +766,11 @@ RSpec.describe "Schemes scheme Features" do
context "when I click to change scheme name" do
before do
- click_link("Change", href: "/schemes/#{scheme.id}/edit-name", match: :first)
+ click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
end
it "shows available fields to edit" do
- expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name")
+ expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
expect(page).to have_content "Scheme details"
end
@@ -784,7 +784,7 @@ RSpec.describe "Schemes scheme Features" do
it "lets me see amended details on the check answers page" do
expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
- assert_selector "a", text: "Change", count: 3
+ assert_selector "a", text: "Change", count: 11
end
it "lets me save the scheme" do
@@ -1021,7 +1021,7 @@ RSpec.describe "Schemes scheme Features" do
end
it "does not let you change details other than the name, confidential information and housing stock owner" do
- assert_selector "a", text: "Change", count: 3
+ assert_selector "a", text: "Change", count: 11
end
end
end
diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb
index ff3030932..3d1010d4a 100644
--- a/spec/helpers/schemes_helper_spec.rb
+++ b/spec/helpers/schemes_helper_spec.rb
@@ -88,234 +88,6 @@ RSpec.describe SchemesHelper do
end
include TagHelper
- describe "display_scheme_attributes" do
- let(:owning_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Owning") }
- let(:managing_organisation) { FactoryBot.create(:organisation, name: "Acme LTD Managing") }
- let!(:scheme) do
- FactoryBot.create(:scheme,
- service_name: "Test service_name",
- sensitive: 0,
- scheme_type: 7,
- registered_under_care_act: 3,
- owning_organisation:,
- arrangement_type: "V",
- primary_client_group: "S",
- has_other_client_group: 1,
- secondary_client_group: "I",
- support_type: 4,
- intended_stay: "P",
- created_at: Time.zone.local(2022, 4, 1))
- end
- let!(:scheme_where_managing_organisation_is_owning_organisation) { FactoryBot.create(:scheme, arrangement_type: "D") }
- let(:support_user) { FactoryBot.create(:user, :support) }
- let(:coordinator_user) { FactoryBot.create(:user, :data_coordinator) }
-
- context "when scheme has no locations" do
- it "returns correct display attributes" do
- attributes = [
- { name: "Scheme code", value: "S#{scheme.id}" },
- { name: "Name", value: "Test service_name", edit: true },
- { name: "Status", value: status_tag(:incomplete) },
- { name: "Confidential information", value: "No", edit: true },
- { name: "Type of scheme", value: "Housing for older people" },
- { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
- { name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
- { name: "Support services provided by", value: "A registered charity or voluntary organisation" },
- { name: "Primary client group", value: "Rough sleepers" },
- { name: "Has another client group", value: "Yes" },
- { name: "Secondary client group", value: "Refugees (permanent)" },
- { name: "Level of support given", value: "High level" },
- { name: "Intended length of stay", value: "Permanent" },
- { name: "Availability", value: "Active from 1 April 2021" },
- ]
- expect(display_scheme_attributes(scheme)).to eq(attributes)
- end
- end
-
- context "when scheme has a location" do
- before do
- FactoryBot.create(:location, scheme:)
- end
-
- it "returns correct display attributes" do
- attributes = [
- { name: "Scheme code", value: "S#{scheme.id}" },
- { name: "Name", value: "Test service_name", edit: true },
- { name: "Status", value: status_tag(:active) },
- { name: "Confidential information", value: "No", edit: true },
- { name: "Type of scheme", value: "Housing for older people" },
- { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
- { name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
- { name: "Support services provided by", value: "A registered charity or voluntary organisation" },
- { name: "Primary client group", value: "Rough sleepers" },
- { name: "Has another client group", value: "Yes" },
- { name: "Secondary client group", value: "Refugees (permanent)" },
- { name: "Level of support given", value: "High level" },
- { name: "Intended length of stay", value: "Permanent" },
- { name: "Availability", value: "Active from 1 April 2021" },
- ]
- expect(display_scheme_attributes(scheme)).to eq(attributes)
- end
-
- context "when the managing organisation is the owning organisation" do
- it "doesn't show the organisation providing support" do
- attributes = display_scheme_attributes(scheme_where_managing_organisation_is_owning_organisation).find { |x| x[:name] == "Organisation providing support" }
- expect(attributes).to be_nil
- end
- end
-
- context "when viewing availability" do
- context "with no deactivations" do
- it "displays current collection start date as availability date if created_at is later than collection start date" do
- scheme.update!(created_at: Time.zone.local(2022, 4, 16))
- availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
-
- expect(availability_attribute).to eq("Active from 1 April 2021")
- end
- end
-
- context "with previous deactivations" do
- context "and all reactivated deactivations" do
- before do
- Timecop.freeze(Time.zone.local(2023, 11, 10))
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
- Timecop.return
- scheme.reload
- end
-
- it "displays the timeline of availability" do
- availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
-
- expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022\nActive from 28 September 2022")
- end
- end
-
- context "and non reactivated deactivation" do
- before do
- Timecop.freeze(Time.zone.local(2023, 11, 10))
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, scheme:)
- Timecop.return
- scheme.reload
- end
-
- it "displays the timeline of availability" do
- availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
-
- expect(availability_attribute).to eq("Active from 1 April 2021 to 9 August 2022\nDeactivated on 10 August 2022\nActive from 1 September 2022 to 14 September 2022\nDeactivated on 15 September 2022")
- end
- end
- end
-
- context "with out of order deactivations" do
- context "and all reactivated deactivations" do
- before do
- Timecop.freeze(Time.zone.local(2023, 11, 10))
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), scheme:)
- Timecop.return
- scheme.reload
- end
-
- it "displays the timeline of availability" do
- availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
-
- expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 18 June 2022 to 23 September 2022\nDeactivated on 24 September 2022\nActive from 28 September 2022")
- end
- end
-
- context "and one non reactivated deactivation" do
- before do
- Timecop.freeze(Time.zone.local(2023, 11, 10))
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
- Timecop.return
- scheme.reload
- end
-
- it "displays the timeline of availability" do
- availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
-
- expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022")
- end
- end
- end
-
- context "with multiple out of order deactivations" do
- context "and one non reactivated deactivation" do
- before do
- Timecop.freeze(Time.zone.local(2023, 11, 10))
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), scheme:)
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
- Timecop.return
- scheme.reload
- end
-
- it "displays the timeline of availability" do
- availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
-
- expect(availability_attribute).to eq("Active from 1 April 2021 to 14 June 2022\nDeactivated on 15 June 2022\nActive from 28 September 2022 to 23 October 2022\nDeactivated on 24 October 2022\nActive from 28 October 2022")
- end
- end
- end
-
- context "with intersecting deactivations" do
- before do
- Timecop.freeze(Time.zone.local(2023, 11, 10))
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), scheme:)
- FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), scheme:)
- Timecop.return
- scheme.reload
- end
-
- it "displays the timeline of availability" do
- availability_attribute = display_scheme_attributes(scheme).find { |x| x[:name] == "Availability" }[:value]
-
- expect(availability_attribute).to eq("Active from 1 April 2021 to 9 October 2022\nDeactivated on 10 October 2022\nActive from 11 December 2022")
- end
- end
- end
- end
-
- context "when scheme has no secondary client group" do
- before do
- scheme.update!(has_other_client_group: 0)
- end
-
- it "returns correct display attributes" do
- attributes = [
- { name: "Scheme code", value: "S#{scheme.id}" },
- { name: "Name", value: "Test service_name", edit: true },
- { name: "Status", value: status_tag(:incomplete) },
- { name: "Confidential information", value: "No", edit: true },
- { name: "Type of scheme", value: "Housing for older people" },
- { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" },
- { name: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
- { name: "Support services provided by", value: "A registered charity or voluntary organisation" },
- { name: "Primary client group", value: "Rough sleepers" },
- { name: "Has another client group", value: "No" },
- { name: "Level of support given", value: "High level" },
- { name: "Intended length of stay", value: "Permanent" },
- { name: "Availability", value: "Active from 1 April 2021" },
- ]
- expect(display_scheme_attributes(scheme)).to eq(attributes)
- end
- end
-
- context "when scheme was merged from another organisation" do
- before do
- FactoryBot.create(:location, scheme:)
- scheme.startdate = Time.zone.local(2023, 1, 5)
- end
-
- it "returns correct availability" do
- expect(display_scheme_attributes(scheme)).to include({ name: "Availability", value: "Active from 5 January 2023" })
- end
- end
- end
-
describe "edit_scheme_text" do
let(:parent_organisation) { FactoryBot.create(:organisation, name: "Parent") }
let(:child_organisation) { FactoryBot.create(:organisation, name: "Child") }