From 3115fcef62c99fc9934c8ee6fbfa06e9a6f53a89 Mon Sep 17 00:00:00 2001 From: Kat <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:30:48 +0000 Subject: [PATCH] Update some tests --- app/components/search_component.html.erb | 2 +- app/controllers/sessions_controller.rb | 12 ++-- app/helpers/filters_helper.rb | 4 +- config/locales/test.en.yml | 17 +++++ spec/controllers/errors_controller_spec.rb | 2 +- spec/features/organisation_spec.rb | 6 +- spec/features/schemes_spec.rb | 4 +- spec/features/user_spec.rb | 6 +- .../auth/passwords_controller_spec.rb | 2 +- spec/requests/delete_logs_controller_spec.rb | 32 +++++---- spec/requests/form_controller_spec.rb | 2 - .../requests/lettings_logs_controller_spec.rb | 4 +- spec/requests/locations_controller_spec.rb | 32 ++++----- .../merge_requests_controller_spec.rb | 20 +++--- .../requests/notifications_controller_spec.rb | 2 +- .../requests/organisations_controller_spec.rb | 6 +- spec/requests/sales_logs_controller_spec.rb | 2 +- spec/requests/schemes_controller_spec.rb | 28 ++++---- spec/requests/users_controller_spec.rb | 58 ++++++++------- .../merge/merge_organisations_service_spec.rb | 70 +++++++++---------- 20 files changed, 166 insertions(+), 145 deletions(-) create mode 100644 config/locales/test.en.yml diff --git a/app/components/search_component.html.erb b/app/components/search_component.html.erb index 5e3eb4ae3..62dca0ec2 100644 --- a/app/components/search_component.html.erb +++ b/app/components/search_component.html.erb @@ -1,4 +1,4 @@ -<%= form_with model: @user, url: path(current_user), method: "get", local: true do |f| %> +<%= form_with url: path(current_user), method: "get", local: true do |f| %>
Schemes are attached to the organisation that owns the property. Check you have correctly answered question 1 \"Which organisation owns this property?\"
+If your organisation’s schemes were migrated from old CORE, they may have new names and codes. Search by postcode to find your scheme.
" + scheme_changes_link_text: "Read more about how schemes have changed" + view_schemes_link_text: "View your organisation’s schemes" + soft_validations: + net_income: + hint_text: "hint text" diff --git a/spec/controllers/errors_controller_spec.rb b/spec/controllers/errors_controller_spec.rb index d8ae16165..30361ea42 100644 --- a/spec/controllers/errors_controller_spec.rb +++ b/spec/controllers/errors_controller_spec.rb @@ -18,7 +18,7 @@ RSpec.describe ErrorsController, type: :controller do describe "GET #unprocessable_entity" do it "returns unprocessable_entity" do get :unprocessable_entity - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) end end end diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index 6f90428be..15bfecf39 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -206,14 +206,14 @@ RSpec.describe "User Features" do it "can filter lettings logs by year" do check("years-2022-field") click_button("Apply filters") - expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2022&status[]=&needstypes[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=") + expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?%5Byears%5D[]=&years[]=2022&%5Bstatus%5D[]=&%5Bneedstypes%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=") expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}" end it "can filter lettings logs by needstype" do check("needstypes-1-field") click_button("Apply filters") - expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&status[]=&needstypes[]=&needstypes[]=1&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=") + expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?%5Byears%5D[]=&%5Bstatus%5D[]=&%5Bneedstypes%5D[]=&needstypes[]=1&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=") other_general_needs_logs.each do |general_needs_log| expect(page).to have_link general_needs_log.id.to_s, href: "/lettings-logs/#{general_needs_log.id}" end @@ -256,7 +256,7 @@ RSpec.describe "User Features" do end check("years-2022-field") click_button("Apply filters") - expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2022&status[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=") + expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?%5Byears%5D[]=&years[]=2022&%5Bstatus%5D[]=&assigned_to=all&user_text_search=&user=&owning_organisation_select=all&owning_organisation_text_search=&owning_organisation=&managing_organisation_select=all&managing_organisation_text_search=&managing_organisation=") expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}" end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index dfb56665b..84572f35b 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -87,7 +87,7 @@ RSpec.describe "Schemes scheme Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_link("Clear", href: /clear-filters\?filter_type=schemes/) + expect(page).to have_link("Clear", href: /clear-filters\?.*filter_type=schemes/) end context "when clearing the filters" do @@ -326,7 +326,7 @@ RSpec.describe "Schemes scheme Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/) + expect(page).to have_link("Clear", href: /\/clear-filters\?.*filter_type=scheme_locations/) end context "when clearing the filters" do diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 2e837abe2..de3f2cbc5 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -269,7 +269,7 @@ RSpec.describe "User Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_link("Clear", href: /clear-filters\?filter_type=users/) + expect(page).to have_link("Clear", href: /clear-filters\?.*filter_type=users/) end context "when clearing the filters" do @@ -678,7 +678,7 @@ RSpec.describe "User Features" do fill_in("code", with: otp) click_button("Submit") expect(page).to have_content("Check your email") - expect(page).to have_http_status(:unprocessable_entity) + expect(page).to have_http_status(:unprocessable_content) expect(page).to have_title("Error") expect(page).to have_selector(".govuk-error-summary__title") end @@ -691,7 +691,7 @@ RSpec.describe "User Features" do fill_in("code", with: otp) click_button("Submit") expect(page).to have_content("Check your email") - expect(page).to have_http_status(:unprocessable_entity) + expect(page).to have_http_status(:unprocessable_content) expect(page).to have_title("Error") expect(page).to have_selector(".govuk-error-summary__title") end diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index f35df1c5a..2685e19ab 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/spec/requests/auth/passwords_controller_spec.rb @@ -107,7 +107,7 @@ RSpec.describe Auth::PasswordsController, type: :request do it "shows an error on the same page" do put "/account/password", headers: headers, params: params - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_css("h1", text: "Reset your password") expect(page).to have_content("passwords you entered do not match") end diff --git a/spec/requests/delete_logs_controller_spec.rb b/spec/requests/delete_logs_controller_spec.rb index cde0848f6..b055e9dd1 100644 --- a/spec/requests/delete_logs_controller_spec.rb +++ b/spec/requests/delete_logs_controller_spec.rb @@ -61,8 +61,9 @@ RSpec.describe "DeleteLogs", type: :request do allow(FilterManager).to receive(:filter_logs).and_return LettingsLog.all end - it "throws an error if selected ids are not provided" do - expect { post delete_logs_lettings_logs_path }.to raise_error ActionController::ParameterMissing + it "returns bad request if selected ids are not provided" do + post delete_logs_lettings_logs_path + expect(response).to have_http_status(:bad_request) end it "calls the filter service with the filters in the session and the search term from the query params" do @@ -120,7 +121,8 @@ RSpec.describe "DeleteLogs", type: :request do end it "requires delete logs form data to be provided" do - expect { post delete_logs_confirmation_lettings_logs_path }.to raise_error(ActionController::ParameterMissing) + post delete_logs_confirmation_lettings_logs_path + expect(response).to have_http_status(:bad_request) end it "shows the correct title" do @@ -346,8 +348,9 @@ RSpec.describe "DeleteLogs", type: :request do allow(FilterManager).to receive(:filter_logs).and_return SalesLog.all end - it "throws an error if selected ids are not provided" do - expect { post delete_logs_sales_logs_path }.to raise_error ActionController::ParameterMissing + it "returns bad request if selected ids are not provided" do + post delete_logs_sales_logs_path + expect(response).to have_http_status(:bad_request) end it "calls the filter service with the filters in the session and the search term from the query params" do @@ -405,7 +408,8 @@ RSpec.describe "DeleteLogs", type: :request do end it "requires delete logs form data to be provided" do - expect { post delete_logs_confirmation_sales_logs_path }.to raise_error(ActionController::ParameterMissing) + post delete_logs_confirmation_sales_logs_path + expect(response).to have_http_status(:bad_request) end it "shows the correct title" do @@ -635,8 +639,9 @@ RSpec.describe "DeleteLogs", type: :request do allow(FilterManager).to receive(:filter_logs).and_return LettingsLog.all end - it "throws an error if selected ids are not provided" do - expect { post delete_lettings_logs_organisation_path(id: organisation) }.to raise_error ActionController::ParameterMissing + it "returns bad request if selected ids are not provided" do + post delete_lettings_logs_organisation_path(id: organisation) + expect(response).to have_http_status(:bad_request) end it "calls the filter service with the filters in the session and the search term from the query params" do @@ -694,7 +699,8 @@ RSpec.describe "DeleteLogs", type: :request do end it "requires delete logs form data to be provided" do - expect { post delete_lettings_logs_confirmation_organisation_path(id: organisation) }.to raise_error(ActionController::ParameterMissing) + post delete_lettings_logs_confirmation_organisation_path(id: organisation) + expect(response).to have_http_status(:bad_request) end it "shows the correct title" do @@ -858,8 +864,9 @@ RSpec.describe "DeleteLogs", type: :request do allow(FilterManager).to receive(:filter_logs).and_return SalesLog.all end - it "throws an error if selected ids are not provided" do - expect { post delete_sales_logs_organisation_path(id: organisation) }.to raise_error ActionController::ParameterMissing + it "returns bad request if selected ids are not provided" do + post delete_sales_logs_organisation_path(id: organisation) + expect(response).to have_http_status(:bad_request) end it "calls the filter service with the filters in the session and the search term from the query params" do @@ -917,7 +924,8 @@ RSpec.describe "DeleteLogs", type: :request do end it "requires delete logs form data to be provided" do - expect { post delete_sales_logs_confirmation_organisation_path(id: organisation) }.to raise_error(ActionController::ParameterMissing) + post delete_sales_logs_confirmation_organisation_path + expect(response).to have_http_status(:bad_request) end it "shows the correct title" do diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 0cbec27d2..6ab49e302 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -1159,7 +1159,6 @@ RSpec.describe FormController, type: :request do it "displays a success banner" do follow_redirect! - follow_redirect! expect(response.body).to include("You have successfully updated Q31: lead tenant’s age") end @@ -1182,7 +1181,6 @@ RSpec.describe FormController, type: :request do end it "displays a success banner without crashing" do - follow_redirect! follow_redirect! expect(response.body).to include("You have successfully updated") end diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index b902305ad..14cd3095c 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -81,7 +81,7 @@ RSpec.describe LettingsLogsController, type: :request do it "validates lettings log parameters" do json_response = JSON.parse(response.body) - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(json_response["errors"]).to match_array([["offered", [I18n.t("validations.shared.numeric.within_range", field: "Times previously offered since becoming available", min: 0, max: 20)]], ["age1", [I18n.t("validations.shared.numeric.within_range", field: "Lead tenant’s age", min: 16, max: 120)]]]) end end @@ -1612,7 +1612,7 @@ RSpec.describe LettingsLogsController, type: :request do let(:params) { { age1: 200 } } it "returns 422" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) end it "returns an error message" do diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 6de8e7d33..9afdc94f2 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1192,7 +1192,7 @@ RSpec.describe LocationsController, type: :request do end it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.startdate_invalid")) end end @@ -1266,7 +1266,7 @@ RSpec.describe LocationsController, type: :request do end it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.startdate_invalid")) end end @@ -1702,7 +1702,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { "deactivation_date": "" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.not_selected")) end end @@ -1711,7 +1711,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -1720,7 +1720,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.out_of_range", date: "1 April 2022")) end end @@ -1729,7 +1729,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -1738,7 +1738,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -1747,7 +1747,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -1758,7 +1758,7 @@ RSpec.describe LocationsController, type: :request do let(:add_deactivations) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 10, 12), location:) } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.deactivation.during_deactivated_period")) end end @@ -2110,7 +2110,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { "reactivation_date": "" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.not_selected")) end end @@ -2119,7 +2119,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "10", "reactivation_date(2i)": "44", "reactivation_date(1i)": "2022" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -2128,7 +2128,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "10", "reactivation_date(2i)": "4", "reactivation_date(1i)": "2020" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.out_of_range", date: "1 April 2022")) end end @@ -2137,7 +2137,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "", "reactivation_date(2i)": "2", "reactivation_date(1i)": "2022" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -2146,7 +2146,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "2", "reactivation_date(2i)": "", "reactivation_date(1i)": "2022" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -2155,7 +2155,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "2", "reactivation_date(2i)": "2", "reactivation_date(1i)": "" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid")) end end @@ -2165,7 +2165,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "8", "reactivation_date(2i)": "9", "reactivation_date(1i)": "2022" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.location.reactivation.before_deactivation", date: "10 October 2022")) end end diff --git a/spec/requests/merge_requests_controller_spec.rb b/spec/requests/merge_requests_controller_spec.rb index 074d2186c..4c07dbfb7 100644 --- a/spec/requests/merge_requests_controller_spec.rb +++ b/spec/requests/merge_requests_controller_spec.rb @@ -95,7 +95,7 @@ RSpec.describe MergeRequestsController, type: :request do end it "displays the page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Another merge request records #{another_organisation.name} as merging into #{other_merge_request.absorbing_organisation&.name} on 4 May 2022. Select another organisation or remove this organisation from the other merge request.") end end @@ -113,7 +113,7 @@ RSpec.describe MergeRequestsController, type: :request do it "does not update the merge request" do merge_request.reload expect(merge_request.merging_organisations.count).to eq(0) - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.merge_request.organisation_part_of_another_merge")) end end @@ -159,7 +159,7 @@ RSpec.describe MergeRequestsController, type: :request do it "does not update the merge request" do merge_request.reload expect(merge_request.merging_organisations.count).to eq(0) - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.merge_request.organisation_not_selected")) end end @@ -174,7 +174,7 @@ RSpec.describe MergeRequestsController, type: :request do it "does not update the merge request" do merge_request.reload expect(merge_request.merging_organisations.count).to eq(0) - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.merge_request.organisation_not_selected")) end end @@ -363,7 +363,7 @@ RSpec.describe MergeRequestsController, type: :request do it "renders the error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Enter a merge date") end @@ -385,7 +385,7 @@ RSpec.describe MergeRequestsController, type: :request do it "displays the page with an error message" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Enter a valid merge date") end end @@ -426,7 +426,7 @@ RSpec.describe MergeRequestsController, type: :request do it "displays the page with an error message" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("The merge date must not be later than a year from today’s date.") end end @@ -467,7 +467,7 @@ RSpec.describe MergeRequestsController, type: :request do it "renders the error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("You must answer absorbing organisation already active?") end @@ -490,7 +490,7 @@ RSpec.describe MergeRequestsController, type: :request do it "renders the error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("You must answer was this merge reported by a helpdesk ticket?") end @@ -511,7 +511,7 @@ RSpec.describe MergeRequestsController, type: :request do it "renders the error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("You must answer the ticket number") end diff --git a/spec/requests/notifications_controller_spec.rb b/spec/requests/notifications_controller_spec.rb index 0982057ab..367c64550 100644 --- a/spec/requests/notifications_controller_spec.rb +++ b/spec/requests/notifications_controller_spec.rb @@ -37,7 +37,7 @@ RSpec.describe NotificationsController, type: :request do it "gives an error response" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index af9027753..0a5614be3 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -1889,7 +1889,7 @@ RSpec.describe OrganisationsController, type: :request do it "displays the form with an error message" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.organisation.name_missing")) expect(page).to have_content(I18n.t("validations.organisation.provider_type_missing")) end @@ -2055,7 +2055,7 @@ RSpec.describe OrganisationsController, type: :request do end it "has clear filters link" do - expect(page).to have_link("Clear", href: clear_filters_path(filter_type: "lettings_logs", path_params: { organisation_id: organisation.id })) + expect(page).to have_link("Clear", href: clear_filters_path(filter_type: "lettings_logs", filter_path_params: { organisation_id: organisation.id })) end end end @@ -2417,7 +2417,7 @@ RSpec.describe OrganisationsController, type: :request do it "displays an error" do post "/organisations/#{organisation.id}/schemes/duplicates", headers: headers, params: params - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("You must resolve all duplicates or indicate that there are no duplicates") end end diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb index 840613458..06461bf4f 100644 --- a/spec/requests/sales_logs_controller_spec.rb +++ b/spec/requests/sales_logs_controller_spec.rb @@ -92,7 +92,7 @@ RSpec.describe SalesLogsController, type: :request do it "validates sales log parameters" do json_response = JSON.parse(response.body) - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(json_response["errors"]).to match_array([["beds", ["Number of bedrooms must be 1 if the property is a bedsit."]], ["proptype", ["Answer cannot be 'Bedsit' if the property has 2 or more bedrooms."]]]) end end diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 2eb2330c8..713e54142 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -1057,7 +1057,7 @@ RSpec.describe SchemesController, type: :request do it "renders the same page with error message" do post "/schemes", params: params - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Create a new supported housing scheme") expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) @@ -1185,7 +1185,7 @@ RSpec.describe SchemesController, type: :request do it "renders the same page with error message" do post "/schemes", params: params - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Create a new supported housing scheme") expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) @@ -1318,7 +1318,7 @@ RSpec.describe SchemesController, type: :request do it "renders the same page with error message" do post "/schemes", params: params - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Create a new supported housing scheme") expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.invalid")) @@ -1334,7 +1334,7 @@ RSpec.describe SchemesController, type: :request do it "displays the new page with an error message" do post "/schemes", params: params - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Enter an organisation that owns housing stock") end end @@ -1375,7 +1375,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme: { owning_organisation_id: user.organisation.id, arrangement_type: nil, confirmed: true, page: "check-answers" } } } it "does not allow the scheme to be confirmed" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid")) end end @@ -1417,7 +1417,7 @@ RSpec.describe SchemesController, type: :request do end it "renders the same page with error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Create a new supported housing scheme") expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.scheme_type.invalid")) @@ -1684,7 +1684,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme: { owning_organisation_id: user.organisation.id, arrangement_type: nil, confirmed: true, page: "check-answers" } } } it "does not allow the scheme to be confirmed" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid")) end end @@ -1728,7 +1728,7 @@ RSpec.describe SchemesController, type: :request do end it "renders the same page with error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Create a new supported housing scheme") expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.invalid")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.service_name.invalid")) @@ -2895,7 +2895,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme_deactivation_period: { "deactivation_date": "" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.not_selected")) end end @@ -2904,7 +2904,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "44", "deactivation_date(1i)": "2022" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid")) end end @@ -2913,7 +2913,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } } it "displays the new page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.out_of_range", date: "1 April 2022")) end end @@ -2922,7 +2922,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "", "deactivation_date(2i)": "2", "deactivation_date(1i)": "2022" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid")) end end @@ -2931,7 +2931,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "", "deactivation_date(1i)": "2022" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid")) end end @@ -2940,7 +2940,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "2", "deactivation_date(2i)": "2", "deactivation_date(1i)": "" } } } it "displays page with an error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid")) end end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 12418d532..257bd681a 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -67,7 +67,7 @@ RSpec.describe UsersController, type: :request do end it "shows an error on the same page if passwords don't match" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_css("h1", class: "govuk-heading-l", text: "Change your password") expect(page).to have_selector(".govuk-error-summary__title") expect(page).to have_content("passwords you entered do not match") @@ -349,7 +349,7 @@ RSpec.describe UsersController, type: :request do end it "show an error" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) end end @@ -377,7 +377,7 @@ RSpec.describe UsersController, type: :request do end it "shows an error if passwords don't match" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_selector(".govuk-error-summary__title") end end @@ -792,9 +792,8 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do it "there is no route" do - expect { - get "/users/#{other_user.id}/password/edit", headers:, params: {} - }.to raise_error(ActionController::RoutingError) + get "/users/#{other_user.id}/password/edit", headers:, params: {} + expect(response).to have_http_status(:not_found) end end end @@ -840,7 +839,7 @@ RSpec.describe UsersController, type: :request do end it "shows an error if passwords don't match" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_selector(".govuk-error-summary__title") end end @@ -955,7 +954,7 @@ RSpec.describe UsersController, type: :request do end it "show an error" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) end end @@ -976,7 +975,7 @@ RSpec.describe UsersController, type: :request do let(:phone) { "" } it "validates telephone number" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.blank")) end end @@ -985,7 +984,7 @@ RSpec.describe UsersController, type: :request do let(:phone) { "randomstring" } it "validates telephone number" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid")) end end @@ -994,7 +993,7 @@ RSpec.describe UsersController, type: :request do let(:phone) { "123" } it "validates telephone number" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid")) end end @@ -1075,7 +1074,7 @@ RSpec.describe UsersController, type: :request do it "shows an error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.email.taken")) end end @@ -1093,7 +1092,7 @@ RSpec.describe UsersController, type: :request do it "shows an error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("validations.role.invalid")) end end @@ -1111,7 +1110,7 @@ RSpec.describe UsersController, type: :request do it "shows an error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.name.blank")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.email.blank")) end @@ -1131,7 +1130,7 @@ RSpec.describe UsersController, type: :request do it "validates telephone number" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid")) end end @@ -1141,7 +1140,7 @@ RSpec.describe UsersController, type: :request do it "validates telephone number" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid")) end end @@ -1748,9 +1747,8 @@ RSpec.describe UsersController, type: :request do context "when the current user does not match the user ID" do it "there is no route" do - expect { - get "/users/#{other_user.id}/password/edit", headers:, params: {} - }.to raise_error(ActionController::RoutingError) + get "/users/#{other_user.id}/password/edit", headers:, params: {} + expect(response).to have_http_status(:not_found) end end end @@ -1912,7 +1910,7 @@ RSpec.describe UsersController, type: :request do end it "shows an error if passwords don't match" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_selector(".govuk-error-summary__title") end end @@ -1928,7 +1926,7 @@ RSpec.describe UsersController, type: :request do let(:params) { { id: user.id, user: { organisation_id: "" } } } it "does not update the organisation" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_selector(".govuk-error-summary__title") end end @@ -2097,7 +2095,7 @@ RSpec.describe UsersController, type: :request do let(:params) { { id: other_user.id, user: { organisation_id: "" } } } it "does not update the organisation" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_selector(".govuk-error-summary__title") end end @@ -2136,7 +2134,7 @@ RSpec.describe UsersController, type: :request do end it "displays the error message" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("Select if you want to reassign logs") end end @@ -2184,7 +2182,7 @@ RSpec.describe UsersController, type: :request do end it "required the new org to have stock owner relationship with the current user org" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("New org must be a stock owner of #{other_user.organisation_name} to make this change.") end end @@ -2198,7 +2196,7 @@ RSpec.describe UsersController, type: :request do end it "required the new org to have stock owner relationship with the managing organisations" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("New org must be a stock owner of #{other_user.organisation_name}, #{new_organisation_2.name}, and #{new_organisation_3.name} to make this change.") end end @@ -2215,7 +2213,7 @@ RSpec.describe UsersController, type: :request do end it "required the new org to have managing agent relationship with the current user org" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("New org must be a managing agent of #{other_user.organisation_name} to make this change.") end end @@ -2229,7 +2227,7 @@ RSpec.describe UsersController, type: :request do end it "required the new org to have managing agent relationship with owning organisations" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content("New org must be a managing agent of #{other_user.organisation.name}, #{new_organisation_2.name}, and #{new_organisation_3.name} to make this change.") end end @@ -2246,7 +2244,7 @@ RSpec.describe UsersController, type: :request do end it "show an error" do - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) end end end @@ -2309,7 +2307,7 @@ RSpec.describe UsersController, type: :request do it "shows an error messages for all failed validations" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.name.blank")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.email.blank")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.organisation_id.blank")) @@ -2324,7 +2322,7 @@ RSpec.describe UsersController, type: :request do it "shows an error" do request - expect(response).to have_http_status(:unprocessable_entity) + expect(response).to have_http_status(:unprocessable_content) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.email.taken")) end end diff --git a/spec/services/merge/merge_organisations_service_spec.rb b/spec/services/merge/merge_organisations_service_spec.rb index fbb52c2a5..f20e16a16 100644 --- a/spec/services/merge/merge_organisations_service_spec.rb +++ b/spec/services/merge/merge_organisations_service_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "when merging a single organisation into an existing organisation" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: nil) } let(:absorbing_organisation) { create(:organisation, holds_own_stock: false, name: "absorbing org") } let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) } @@ -53,7 +53,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -97,7 +97,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -134,7 +134,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -327,7 +327,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and deactivation is after the merge date and before an open collection window" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.today - 6.years) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.today - 6.years) } let!(:scheme) { create(:scheme, owning_organisation: merging_organisation, old_id: "scheme_old_id", old_visible_id: "scheme_old_visible_id", startdate: nil) } let!(:location) { create(:location, scheme:, old_id: "location_old_id", old_visible_id: "location_old_visible_id", startdate: nil) } @@ -551,7 +551,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -584,7 +584,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -596,7 +596,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "with merge date in closed collection year" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.local(2021, 3, 3)) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.local(2021, 3, 3)) } it "does not validate saledate for closed collection years" do sales_log.saledate = Time.zone.local(2022, 5, 1) @@ -611,7 +611,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and merge date is provided" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.yesterday) } it "sets merge date on merged organisation" do merge_organisations_service.call @@ -646,7 +646,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -682,7 +682,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -706,7 +706,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "with merge date in closed collection year" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.local(2021, 3, 3)) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.local(2021, 3, 3)) } it "does not validate startdate for closed collection years" do owned_lettings_log.startdate = Time.zone.local(2022, 4, 1) @@ -825,7 +825,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -842,7 +842,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and absorbing_organisation_active_from_merge_date is true" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday, absorbing_organisation_active_from_merge_date: true) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.yesterday, absorbing_organisation_active_from_merge_date: true) } it "sets available from to merge_date for absorbing organisation" do merge_organisations_service.call @@ -854,7 +854,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and absorbing_organisation_active_from_merge_date is true" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], absorbing_organisation_active_from_merge_date: true) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, absorbing_organisation_active_from_merge_date: true) } it "sets available from to merge_date (today) for absorbing organisation" do merge_organisations_service.call @@ -910,7 +910,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "when merging a multiple organisations into an existing organisation" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: nil) } let(:absorbing_organisation) { create(:organisation, holds_own_stock: false, name: "absorbing org") } let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) } @@ -944,7 +944,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1069,7 +1069,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1086,7 +1086,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and merge date is provided" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.yesterday) } it "sets merge date and absorbing organisation on merged organisations" do merge_organisations_service.call @@ -1102,7 +1102,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "when merging a single organisation into a new organisation" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids:, merge_date: nil) } let(:new_absorbing_organisation) { create(:organisation, :without_dpc, holds_own_stock: false) } let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) } @@ -1139,7 +1139,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1183,7 +1183,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1220,7 +1220,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1325,7 +1325,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1357,7 +1357,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1370,7 +1370,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and merge date is provided" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.yesterday) } it "sets merge date on merged organisation" do merge_organisations_service.call @@ -1396,7 +1396,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1432,7 +1432,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1538,7 +1538,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1555,7 +1555,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and absorbing_organisation_active_from_merge_date is true" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday, absorbing_organisation_active_from_merge_date: true) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.yesterday, absorbing_organisation_active_from_merge_date: true) } it "sets available from to merge_date for absorbing organisation" do merge_organisations_service.call @@ -1567,7 +1567,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and absorbing_organisation_active_from_merge_date is true" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], absorbing_organisation_active_from_merge_date: true) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids:, absorbing_organisation_active_from_merge_date: true) } it "sets available from to merge_date (today) for absorbing organisation" do merge_organisations_service.call @@ -1579,7 +1579,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "when merging multiple organisations into a new organisation" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids:, merge_date: nil) } let(:new_absorbing_organisation) { create(:organisation, :without_dpc, holds_own_stock: false) } let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) } @@ -1628,7 +1628,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1670,7 +1670,7 @@ RSpec.describe Merge::MergeOrganisationsService do end it "rolls back if there's an error" do - allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids)) + allow(Organisation).to receive(:find).with(merging_organisation_ids).and_return(Organisation.find(merging_organisation_ids)) allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") @@ -1687,7 +1687,7 @@ RSpec.describe Merge::MergeOrganisationsService do end context "and merge date is provided" do - subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) } + subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids:, merge_date: Time.zone.yesterday) } it "sets merge date and absorbing organisation on merged organisations" do merge_organisations_service.call