diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index 1d35c17e9..03fe556a2 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -54,6 +54,10 @@ module CollectionTimeHelper current_collection_start_year - 1 end + def previous_collection_end_year + current_collection_end_year - 1 + end + def previous_collection_start_date current_collection_start_date - 1.year end @@ -62,6 +66,10 @@ module CollectionTimeHelper current_collection_start_year - 2 end + def archived_collection_end_year + current_collection_end_year - 2 + end + def previous_collection_new_logs_end_date FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date end diff --git a/app/models/scheme.rb b/app/models/scheme.rb index f563573b5..cf13ff29d 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -148,9 +148,8 @@ class Scheme < ApplicationRecord enum :sensitive, SENSITIVE, suffix: true REGISTERED_UNDER_CARE_ACT = { - "Yes – registered care home providing nursing care": 4, - "Yes – registered care home providing personal care": 3, - "Yes – part registered as a care home": 2, + "Yes": 5, + "Partially - some but not all units in the scheme are regulated by the CQC": 2, "No": 1, }.freeze @@ -251,7 +250,7 @@ class Scheme < ApplicationRecord { name: "Status", value: status, id: "status" }, { 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: "Regulated by the Care Quality Commission", 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 }, { name: "Primary client group", value: primary_client_group, id: "primary_client_group", edit: true }, @@ -262,10 +261,8 @@ class Scheme < ApplicationRecord ] end - def care_acts_options_with_hints - hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } - - Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) } + def self.care_acts_options + Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s) } end def support_level_options_with_hints diff --git a/app/views/schemes/details.html.erb b/app/views/schemes/details.html.erb index d1943cabe..722e58883 100644 --- a/app/views/schemes/details.html.erb +++ b/app/views/schemes/details.html.erb @@ -38,16 +38,12 @@ :name, legend: { text: "What is this type of scheme?", size: "m" } %> - <% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %> - - <% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %> - <%= f.govuk_collection_radio_buttons :registered_under_care_act, - care_acts_options_with_hints, + Scheme.care_acts_options, :id, :name, :description, - legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> + legend: { text: "Is the scheme regulated by the Care Quality Commission (CQC)?", size: "m" } %> <% scheme_owning_organisation_options = owning_organisation_options(current_user) %> diff --git a/app/views/schemes/new.html.erb b/app/views/schemes/new.html.erb index 1be0f7f74..88bddacd5 100644 --- a/app/views/schemes/new.html.erb +++ b/app/views/schemes/new.html.erb @@ -33,16 +33,12 @@ :name, legend: { text: "What is this type of scheme?", size: "m" } %> - <% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %> - - <% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %> - <%= f.govuk_collection_radio_buttons :registered_under_care_act, - care_acts_options_with_hints, + Scheme.care_acts_options, :id, :name, :description, - legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> + legend: { text: "Is the scheme regulated by the Care Quality Commission (CQC)?", size: "m" } %> <% 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 %> diff --git a/lib/tasks/update_scheme_registered_under_care_value.rake b/lib/tasks/update_scheme_registered_under_care_value.rake new file mode 100644 index 000000000..f29b9e1dd --- /dev/null +++ b/lib/tasks/update_scheme_registered_under_care_value.rake @@ -0,0 +1,4 @@ +desc "Alter registered under care act values for schemes in the database to 5 if they are 3 or 4, as these options are being deprecated" +task update_scheme_registered_under_care_value: :environment do + Scheme.where(registered_under_care_act: [3, 4]).update_all(registered_under_care_act: 5) +end diff --git a/spec/features/accessibility_spec.rb b/spec/features/accessibility_spec.rb index 889fcdf26..bfb962c57 100644 --- a/spec/features/accessibility_spec.rb +++ b/spec/features/accessibility_spec.rb @@ -21,6 +21,22 @@ RSpec.describe "Accessibility", js: true do end before do + # see https://github.com/dequelabs/axe-core-gems/issues/386#issuecomment-2135927504 for why this is needed + # axe-core will normally use 1 second page load timeout. + # see https://github.com/dequelabs/axe-core-gems/blob/87632f5e8e947214f10e35b57ea5e2c327f20612/packages/axe-core-api/lib/axe/api/run.rb#L36 + # this causes timeout errors for slower pages + # so we override the page load timeout to 10 seconds for feature specs + # this is for the a11y tests, we can only scope to feature specs + page.driver.browser.manage.timeouts.instance_eval do + def page_load=(*) + # no-op don't want axe-core changing this + end + + def page_load + 10 # seconds + end + end + allow(Storage::S3Service).to receive(:new).and_return(storage_service) allow(storage_service).to receive(:configuration).and_return(OpenStruct.new(bucket_name: "core-test-collection-resources")) allow(user).to receive(:need_two_factor_authentication?).and_return(false) diff --git a/spec/features/schemes_helpers.rb b/spec/features/schemes_helpers.rb index 0b99d54de..e14c65cbf 100644 --- a/spec/features/schemes_helpers.rb +++ b/spec/features/schemes_helpers.rb @@ -29,7 +29,7 @@ module SchemesHelpers fill_in "Scheme name", with: "FooBar" check "This scheme contains confidential information" choose "Direct access hostel" - choose "Yes – registered care home providing nursing care" + choose "Yes" select organisation_name, from: "scheme-owning-organisation-id-field" choose answers["housing_stock_owners"].presence || "The same organisation that owns the housing stock" click_button "Save and continue" diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index e9cb23770..ec053b615 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -446,7 +446,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "This scheme contains confidential information" expect(page).to have_content "Which organisation owns the housing stock for this scheme?" expect(page).to have_content "What is this type of scheme?" - expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" + expect(page).to have_content "Is the scheme regulated by the Care Quality Commission (CQC)?" expect(page).to have_content "Who provides the support services used by this scheme?" end @@ -463,7 +463,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "This scheme contains confidential information" expect(page).to have_content "What is this type of scheme?" expect(page).to have_content "Who provides the support services used by this scheme?" - expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" + expect(page).to have_content "Is the scheme regulated by the Care Quality Commission (CQC)?" end it "returns to the primary client group question after amending scheme details" do diff --git a/spec/fixtures/files/original_schemes.csv b/spec/fixtures/files/original_schemes.csv index f28bbedbb..a068a132c 100644 --- a/spec/fixtures/files/original_schemes.csv +++ b/spec/fixtures/files/original_schemes.csv @@ -1,6 +1,6 @@ scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates -{id1},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" -{id2},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" -{id3},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" -{id4},Incomplete scheme,incomplete,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" -SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" +{id1},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" +{id2},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" +{id3},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" +{id4},Incomplete scheme,incomplete,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" +SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" diff --git a/spec/fixtures/files/updated_schemes.csv b/spec/fixtures/files/updated_schemes.csv index 5f4631a02..5091ea2de 100644 --- a/spec/fixtures/files/updated_schemes.csv +++ b/spec/fixtures/files/updated_schemes.csv @@ -1,6 +1,6 @@ scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates {id1},Updated test name,incomplete,No,Direct Access Hostel,No,Different organisation,Another registered stock owner,People with drug problems,No,Older people with support needs,Low level,Permanent,2022-04-01T00:00:00+01:00,"Active from 2 April 2020" -{id2},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" -{id3}, ,active,Yse,Direct access Hostel,Yes – registered care home providing nursing care,non existing org,wrong answer,FD,no,lder people with support needs,high,Permanent ,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" +{id2},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" +{id3}, ,active,Yse,Direct access Hostel,Yes,non existing org,wrong answer,FD,no,lder people with support needs,high,Permanent ,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" Wrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index a7d18295a..ac68c07d3 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -41,7 +41,8 @@ RSpec.describe CheckAnswersHelper do describe "#get_answer_label" do context "when unanswered and bulk upload" do - let(:question) { log.form.questions.reject { |q| log.optional_fields.include?(q.id) }.sample } + # make sure to not include questions that override the answer label + let(:question) { log.form.questions.reject { |q| log.optional_fields.include?(q.id) || q.answer_label(log, current_user).present? }.sample } let(:bulk_upload) { create(:bulk_upload) } let(:log) { create(:sales_log, creation_method: "bulk upload", bulk_upload:) } diff --git a/spec/helpers/collection_time_helper_spec.rb b/spec/helpers/collection_time_helper_spec.rb index 2efeb8b9d..aa9bec444 100644 --- a/spec/helpers/collection_time_helper_spec.rb +++ b/spec/helpers/collection_time_helper_spec.rb @@ -152,7 +152,7 @@ RSpec.describe CollectionTimeHelper do it "returns a different date within the collection year" do result = generate_different_date_within_collection_year(date) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive + expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive end end @@ -162,7 +162,7 @@ RSpec.describe CollectionTimeHelper do it "returns a different date within the collection year" do result = generate_different_date_within_collection_year(date) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive + expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive end end @@ -170,7 +170,7 @@ RSpec.describe CollectionTimeHelper do it "ignores the override and returns a different date within the collection year" do result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31)) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive + expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive end end @@ -178,7 +178,7 @@ RSpec.describe CollectionTimeHelper do it "ignores the override and returns a different date within the collection year" do result = generate_different_date_within_collection_year(date, end_date_override: Time.zone.local(2025, 12, 1)) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive + expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive end end @@ -186,7 +186,7 @@ RSpec.describe CollectionTimeHelper do it "returns a different date within the overridden range" do result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 8, 1), end_date_override: Time.zone.local(2024, 9, 1)) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2024, 8, 1), Time.zone.local(2024, 9, 1)).inclusive + expect(result).to be_between(Date.new(2024, 8, 1), Date.new(2024, 9, 1)).inclusive end end @@ -194,7 +194,7 @@ RSpec.describe CollectionTimeHelper do it "ignores the start_date_override and returns a different date within the collection year" do result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2024, 5, 1)) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2024, 5, 1)).inclusive + expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2024, 5, 1)).inclusive end end @@ -202,7 +202,7 @@ RSpec.describe CollectionTimeHelper do it "ignores the end_date_override and returns a different date within the collection year" do result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2025, 3, 1), end_date_override: Time.zone.local(2025, 12, 1)) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2025, 3, 1), Time.zone.local(2025, 3, 31)).inclusive + expect(result).to be_between(Date.new(2025, 3, 1), Date.new(2025, 3, 31)).inclusive end end @@ -210,7 +210,7 @@ RSpec.describe CollectionTimeHelper do it "ignores both overrides and returns a different date within the collection year" do result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2025, 12, 1)) expect(result).not_to eq(date) - expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive + expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive end end end diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb index ce60d07f7..952a45ffc 100644 --- a/spec/helpers/filters_helper_spec.rb +++ b/spec/helpers/filters_helper_spec.rb @@ -478,136 +478,100 @@ RSpec.describe FiltersHelper do end describe "#collection_year_options" do - context "with 23/24 as the current collection year" do + context "and in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) end - context "and in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) - end - - it "has the correct options" do - expect(collection_year_options).to eq( - { - "2023" => "2023 to 2024", "2022" => "2022 to 2023", "2021" => "2021 to 2022" - }, - ) - end - end - - context "and not in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) - end - - it "has the correct options" do - expect(collection_year_options).to eq( - { - "2023" => "2023 to 2024", "2022" => "2022 to 2023" - }, - ) - end + it "has the correct options" do + expect(collection_year_options).to eq( + { + current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}", + previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}", + archived_collection_start_year.to_s => "#{archived_collection_start_year} to #{archived_collection_end_year}", + }, + ) end end - context "with 24/25 as the current collection year" do + context "and not in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) end - context "and in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) - end - - it "has the correct options" do - expect(collection_year_options).to eq( - { - "2024" => "2024 to 2025", "2023" => "2023 to 2024", "2022" => "2022 to 2023" - }, - ) - end + it "has the correct options" do + expect(collection_year_options).to eq( + { + current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}", + previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}", + }, + ) end - context "and not in crossover period" do + context "with future form use turned on" do before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) + allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) end - it "has the correct options" do + it "includes next year in the options" do expect(collection_year_options).to eq( { - "2024" => "2024 to 2025", "2023" => "2023 to 2024" + next_collection_start_year.to_s => "#{next_collection_start_year} to #{next_collection_end_year}", + current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}", + previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}", }, ) end - - context "with future form use turned on" do - before do - allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) - end - - it "includes next year in the options" do - expect(collection_year_options).to eq( - { - "2025" => "2025 to 2026", "2024" => "2024 to 2025", "2023" => "2023 to 2024" - }, - ) - end - end end end end describe "#collection_year_radio_options" do - context "with 23/24 as the current collection year" do + context "and in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) - end - - context "and in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) - end - - it "has the correct options" do - expect(collection_year_radio_options).to eq( - { - "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }, "2021" => { label: "2021 to 2022" } - }, - ) - end + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) end - context "and not in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) - end - - it "has the correct options" do - expect(collection_year_radio_options).to eq( - { - "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" } - }, - ) - end + it "has the correct options" do + expect(collection_year_radio_options).to eq( + { + current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" }, + previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" }, + archived_collection_start_year.to_s => { label: "#{archived_collection_start_year} to #{archived_collection_end_year}" }, + }, + ) end end - context "with 24/25 as the current collection year" do + context "and not in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) end it "has the correct options" do expect(collection_year_radio_options).to eq( { - "2024" => { label: "2024 to 2025" }, "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" } + current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" }, + previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" }, }, ) end + + context "with future form use turned on" do + before do + allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) + end + + it "includes next year in the options" do + expect(collection_year_radio_options).to eq( + { + next_collection_start_year.to_s => { label: "#{next_collection_start_year} to #{next_collection_end_year}" }, + current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" }, + previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" }, + }, + ) + end + end end end diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index 48374661c..d8452bdff 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -59,6 +59,7 @@ RSpec.describe LocationsHelper do before do allow(Time).to receive(:now).and_return(today) allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) + Singleton.__init__(FormHandler) end it "returns one active period without to date" do diff --git a/spec/lib/tasks/count_duplicates_spec.rb b/spec/lib/tasks/count_duplicates_spec.rb index b4f6a8db8..ba9aa7e59 100644 --- a/spec/lib/tasks/count_duplicates_spec.rb +++ b/spec/lib/tasks/count_duplicates_spec.rb @@ -101,7 +101,12 @@ RSpec.describe "count_duplicates" do end it "creates a csv with correct duplicate numbers" do - expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, "\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates\n#{organisation.id},3,6,4,9\n#{organisation2.id},2,7,2,7\n") + expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, satisfy do |s| + s.start_with?("\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates") && + s.include?("#{organisation.id},3,6,4,9") && + s.include?("#{organisation2.id},2,7,2,7") && + s.count("\n") == 3 + end) expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}") task.invoke end @@ -149,7 +154,12 @@ RSpec.describe "count_duplicates" do end it "creates a csv with correct duplicate numbers" do - expect(storage_service).to receive(:write_file).with(/scheme-duplicates-.*\.csv/, "\uFEFFOrganisation id,Number of duplicate sets,Total duplicate schemes\n#{organisation.id},2,5\n#{organisation2.id},1,5\n") + expect(storage_service).to receive(:write_file).with(/scheme-duplicates-.*\.csv/, satisfy do |s| + s.start_with?("\uFEFFOrganisation id,Number of duplicate sets,Total duplicate schemes") && + s.include?("#{organisation.id},2,5") && + s.include?("#{organisation2.id},1,5") && + s.count("\n") == 3 + end) expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}") task.invoke end @@ -211,7 +221,12 @@ RSpec.describe "count_duplicates" do end it "creates a csv with correct duplicate numbers" do - expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, "\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates\n#{organisation.id},3,6,4,9\n#{organisation2.id},2,7,2,7\n") + expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, satisfy do |s| + s.start_with?("\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates") + s.include?("#{organisation.id},3,6,4,9") && + s.include?("#{organisation2.id},2,7,2,7") && + s.count("\n") == 3 + end) expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}") task.invoke end diff --git a/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb b/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb index c397b456a..6c8aa25ed 100644 --- a/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb +++ b/spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb @@ -57,7 +57,7 @@ RSpec.describe "bulk_update" do 3, service_name: "Test name", sensitive: 1, - registered_under_care_act: 4, + registered_under_care_act: 5, support_type: 4, scheme_type: 7, arrangement_type: "D", @@ -123,7 +123,7 @@ RSpec.describe "bulk_update" do schemes[1].reload expect(schemes[1].service_name).to eq("Test name") expect(schemes[1].sensitive).to eq("Yes") - expect(schemes[1].registered_under_care_act).to eq("Yes – registered care home providing nursing care") + expect(schemes[1].registered_under_care_act).to eq("Yes") expect(schemes[1].support_type).to eq("High level") expect(schemes[1].scheme_type).to eq("Housing for older people") expect(schemes[1].arrangement_type).to eq("The same organisation that owns the housing stock") @@ -141,7 +141,7 @@ RSpec.describe "bulk_update" do schemes[2].reload expect(schemes[2].service_name).to eq("Test name") expect(schemes[2].sensitive).to eq("Yes") - expect(schemes[2].registered_under_care_act).to eq("Yes – registered care home providing nursing care") + expect(schemes[2].registered_under_care_act).to eq("Yes") expect(schemes[2].support_type).to eq("High level") expect(schemes[2].scheme_type).to eq("Housing for older people") expect(schemes[2].arrangement_type).to eq("The same organisation that owns the housing stock") diff --git a/spec/services/merge/merge_organisations_service_spec.rb b/spec/services/merge/merge_organisations_service_spec.rb index 84e0ebbe1..3f0ee4b1c 100644 --- a/spec/services/merge/merge_organisations_service_spec.rb +++ b/spec/services/merge/merge_organisations_service_spec.rb @@ -546,9 +546,12 @@ RSpec.describe Merge::MergeOrganisationsService do merging_organisation.reload expect(absorbing_organisation.owned_lettings_logs.count).to eq(2) expect(absorbing_organisation.managed_lettings_logs.count).to eq(1) - expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(absorbing_organisation.owned_schemes.first) - expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(absorbing_organisation.owned_schemes.first.locations.first) - expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(absorbing_organisation.owned_schemes.first) + + absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) + absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) + expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(absorbed_active_scheme) + expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(absorbed_active_location) + expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(absorbed_active_scheme) expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).location).to eq(nil) end @@ -814,12 +817,12 @@ RSpec.describe Merge::MergeOrganisationsService do it "moves active schemes and locations to absorbing organisation" do expect(absorbing_organisation.owned_schemes.count).to eq(2) - expect(absorbing_organisation.owned_schemes.first.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode)) - expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday) - expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday) - expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months) absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) + expect(absorbed_active_scheme.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode)) + expect(absorbed_active_scheme.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday) + expect(absorbed_active_scheme.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday) + expect(absorbed_active_scheme.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months) expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) expect(absorbed_active_scheme.old_id).to be_nil expect(absorbed_active_scheme.old_visible_id).to be_nil