Browse Source

Update some tests

pull/2856/head
Kat 8 months ago
parent
commit
3115fcef62
  1. 2
      app/components/search_component.html.erb
  2. 12
      app/controllers/sessions_controller.rb
  3. 4
      app/helpers/filters_helper.rb
  4. 17
      config/locales/test.en.yml
  5. 2
      spec/controllers/errors_controller_spec.rb
  6. 6
      spec/features/organisation_spec.rb
  7. 4
      spec/features/schemes_spec.rb
  8. 6
      spec/features/user_spec.rb
  9. 2
      spec/requests/auth/passwords_controller_spec.rb
  10. 32
      spec/requests/delete_logs_controller_spec.rb
  11. 2
      spec/requests/form_controller_spec.rb
  12. 4
      spec/requests/lettings_logs_controller_spec.rb
  13. 32
      spec/requests/locations_controller_spec.rb
  14. 20
      spec/requests/merge_requests_controller_spec.rb
  15. 2
      spec/requests/notifications_controller_spec.rb
  16. 6
      spec/requests/organisations_controller_spec.rb
  17. 2
      spec/requests/sales_logs_controller_spec.rb
  18. 28
      spec/requests/schemes_controller_spec.rb
  19. 58
      spec/requests/users_controller_spec.rb
  20. 70
      spec/services/merge/merge_organisations_service_spec.rb

2
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| %>
<div class="app-search govuk-!-margin-bottom-4"> <div class="app-search govuk-!-margin-bottom-4">
<%= f.govuk_text_field :search, <%= f.govuk_text_field :search,
form_group: { form_group: {

12
app/controllers/sessions_controller.rb

@ -1,20 +1,20 @@
class SessionsController < ApplicationController class SessionsController < ApplicationController
def clear_filters def clear_filters
session[session_name_for(params[:filter_type])] = "{}" session[session_name_for(params[:filter_type])] = "{}"
path_params = params[:path_params].presence || {} filter_path_params = params[:filter_path_params].presence || {}
if path_params[:organisation_id].present? if filter_path_params[:organisation_id].present?
redirect_to send("#{params[:filter_type]}_organisation_path", id: path_params[:organisation_id], scheme_id: path_params[:scheme_id], search: path_params[:search]) redirect_to send("#{params[:filter_type]}_organisation_path", id: filter_path_params[:organisation_id], scheme_id: filter_path_params[:scheme_id], search: filter_path_params[:search])
elsif params[:filter_type].include?("bulk_uploads") elsif params[:filter_type].include?("bulk_uploads")
bulk_upload_type = params[:filter_type].split("_").first bulk_upload_type = params[:filter_type].split("_").first
uploading_organisation = params[:organisation_id].presence uploading_organisation = params[:organisation_id].presence
if uploading_organisation.present? if uploading_organisation.present?
redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: path_params[:search], uploading_organisation:) redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: filter_path_params[:search], uploading_organisation:)
else else
redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: path_params[:search]) redirect_to send("bulk_uploads_#{bulk_upload_type}_logs_path", search: filter_path_params[:search])
end end
else else
redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search]) redirect_to send("#{params[:filter_type]}_path", scheme_id: filter_path_params[:scheme_id], search: filter_path_params[:search])
end end
end end

4
app/helpers/filters_helper.rb

@ -165,9 +165,9 @@ module FiltersHelper
applied_filters_count(filter_type).zero? ? "No filters applied" : "#{pluralize(applied_filters_count(filter_type), 'filter')} applied" applied_filters_count(filter_type).zero? ? "No filters applied" : "#{pluralize(applied_filters_count(filter_type), 'filter')} applied"
end end
def reset_filters_link(filter_type, path_params = {}) def reset_filters_link(filter_type, filter_path_params = {})
if applied_filters_count(filter_type).positive? if applied_filters_count(filter_type).positive?
govuk_link_to "Clear", clear_filters_path(filter_type:, path_params:) govuk_link_to "Clear", clear_filters_path(filter_type:, filter_path_params:)
end end
end end

17
config/locales/test.en.yml

@ -0,0 +1,17 @@
en:
forms:
2021:
lettings:
guidance:
what_counts_as_income:
title: "What counts as income?"
content: "What counts as income?"
finding_scheme:
title: "Can’t find your scheme?"
content: "<p>Schemes are attached to the organisation that owns the property. Check you have correctly answered question 1 \"Which organisation owns this property?\"</p>
<p>If your organisation’s schemes were migrated from old CORE, they may have new names and codes. Search by postcode to find your scheme.</p>"
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"

2
spec/controllers/errors_controller_spec.rb

@ -18,7 +18,7 @@ RSpec.describe ErrorsController, type: :controller do
describe "GET #unprocessable_entity" do describe "GET #unprocessable_entity" do
it "returns unprocessable_entity" do it "returns unprocessable_entity" do
get :unprocessable_entity get :unprocessable_entity
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_content)
end end
end end
end end

6
spec/features/organisation_spec.rb

@ -206,14 +206,14 @@ RSpec.describe "User Features" do
it "can filter lettings logs by year" do it "can filter lettings logs by year" do
check("years-2022-field") check("years-2022-field")
click_button("Apply filters") 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}" expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}"
end end
it "can filter lettings logs by needstype" do it "can filter lettings logs by needstype" do
check("needstypes-1-field") check("needstypes-1-field")
click_button("Apply filters") 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| 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}" expect(page).to have_link general_needs_log.id.to_s, href: "/lettings-logs/#{general_needs_log.id}"
end end
@ -256,7 +256,7 @@ RSpec.describe "User Features" do
end end
check("years-2022-field") check("years-2022-field")
click_button("Apply filters") 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}" expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}"
end end
end end

4
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 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_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 end
context "when clearing the filters" do 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 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_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 end
context "when clearing the filters" do context "when clearing the filters" do

6
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 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_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 end
context "when clearing the filters" do context "when clearing the filters" do
@ -678,7 +678,7 @@ RSpec.describe "User Features" do
fill_in("code", with: otp) fill_in("code", with: otp)
click_button("Submit") click_button("Submit")
expect(page).to have_content("Check your email") 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_title("Error")
expect(page).to have_selector(".govuk-error-summary__title") expect(page).to have_selector(".govuk-error-summary__title")
end end
@ -691,7 +691,7 @@ RSpec.describe "User Features" do
fill_in("code", with: otp) fill_in("code", with: otp)
click_button("Submit") click_button("Submit")
expect(page).to have_content("Check your email") 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_title("Error")
expect(page).to have_selector(".govuk-error-summary__title") expect(page).to have_selector(".govuk-error-summary__title")
end end

2
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 it "shows an error on the same page" do
put "/account/password", headers: headers, params: params 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_css("h1", text: "Reset your password")
expect(page).to have_content("passwords you entered do not match") expect(page).to have_content("passwords you entered do not match")
end end

32
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 allow(FilterManager).to receive(:filter_logs).and_return LettingsLog.all
end end
it "throws an error if selected ids are not provided" do it "returns bad request if selected ids are not provided" do
expect { post delete_logs_lettings_logs_path }.to raise_error ActionController::ParameterMissing post delete_logs_lettings_logs_path
expect(response).to have_http_status(:bad_request)
end end
it "calls the filter service with the filters in the session and the search term from the query params" do 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 end
it "requires delete logs form data to be provided" do 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 end
it "shows the correct title" do 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 allow(FilterManager).to receive(:filter_logs).and_return SalesLog.all
end end
it "throws an error if selected ids are not provided" do it "returns bad request if selected ids are not provided" do
expect { post delete_logs_sales_logs_path }.to raise_error ActionController::ParameterMissing post delete_logs_sales_logs_path
expect(response).to have_http_status(:bad_request)
end end
it "calls the filter service with the filters in the session and the search term from the query params" do 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 end
it "requires delete logs form data to be provided" do 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 end
it "shows the correct title" do 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 allow(FilterManager).to receive(:filter_logs).and_return LettingsLog.all
end end
it "throws an error if selected ids are not provided" do it "returns bad request if selected ids are not provided" do
expect { post delete_lettings_logs_organisation_path(id: organisation) }.to raise_error ActionController::ParameterMissing post delete_lettings_logs_organisation_path(id: organisation)
expect(response).to have_http_status(:bad_request)
end end
it "calls the filter service with the filters in the session and the search term from the query params" do 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 end
it "requires delete logs form data to be provided" do 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 end
it "shows the correct title" do 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 allow(FilterManager).to receive(:filter_logs).and_return SalesLog.all
end end
it "throws an error if selected ids are not provided" do it "returns bad request if selected ids are not provided" do
expect { post delete_sales_logs_organisation_path(id: organisation) }.to raise_error ActionController::ParameterMissing post delete_sales_logs_organisation_path(id: organisation)
expect(response).to have_http_status(:bad_request)
end end
it "calls the filter service with the filters in the session and the search term from the query params" do 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 end
it "requires delete logs form data to be provided" do 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 end
it "shows the correct title" do it "shows the correct title" do

2
spec/requests/form_controller_spec.rb

@ -1159,7 +1159,6 @@ RSpec.describe FormController, type: :request do
it "displays a success banner" do it "displays a success banner" do
follow_redirect! follow_redirect!
follow_redirect!
expect(response.body).to include("You have successfully updated Q31: lead tenant’s age") expect(response.body).to include("You have successfully updated Q31: lead tenant’s age")
end end
@ -1182,7 +1181,6 @@ RSpec.describe FormController, type: :request do
end end
it "displays a success banner without crashing" do it "displays a success banner without crashing" do
follow_redirect!
follow_redirect! follow_redirect!
expect(response.body).to include("You have successfully updated") expect(response.body).to include("You have successfully updated")
end end

4
spec/requests/lettings_logs_controller_spec.rb

@ -81,7 +81,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "validates lettings log parameters" do it "validates lettings log parameters" do
json_response = JSON.parse(response.body) 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)]]]) 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
end end
@ -1612,7 +1612,7 @@ RSpec.describe LettingsLogsController, type: :request do
let(:params) { { age1: 200 } } let(:params) { { age1: 200 } }
it "returns 422" do it "returns 422" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_content)
end end
it "returns an error message" do it "returns an error message" do

32
spec/requests/locations_controller_spec.rb

@ -1192,7 +1192,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "displays the new page with an error message" do 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")) expect(page).to have_content(I18n.t("validations.location.startdate_invalid"))
end end
end end
@ -1266,7 +1266,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "displays the new page with an error message" do 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")) expect(page).to have_content(I18n.t("validations.location.startdate_invalid"))
end end
end end
@ -1702,7 +1702,7 @@ RSpec.describe LocationsController, type: :request do
let(:params) { { location_deactivation_period: { "deactivation_date": "" } } } let(:params) { { location_deactivation_period: { "deactivation_date": "" } } }
it "displays the new page with an error message" do 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.not_selected"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.out_of_range", date: "1 April 2022"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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)": "" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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:) } 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 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")) expect(page).to have_content(I18n.t("validations.location.deactivation.during_deactivated_period"))
end end
end end
@ -2110,7 +2110,7 @@ RSpec.describe LocationsController, type: :request do
let(:params) { { location_deactivation_period: { "reactivation_date": "" } } } let(:params) { { location_deactivation_period: { "reactivation_date": "" } } }
it "displays the new page with an error message" do 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.not_selected"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.out_of_range", date: "1 April 2022"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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)": "" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.toggle_date.invalid"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.location.reactivation.before_deactivation", date: "10 October 2022"))
end end
end end

20
spec/requests/merge_requests_controller_spec.rb

@ -95,7 +95,7 @@ RSpec.describe MergeRequestsController, type: :request do
end end
it "displays the page with an error message" do 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.") 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
end end
@ -113,7 +113,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "does not update the merge request" do it "does not update the merge request" do
merge_request.reload merge_request.reload
expect(merge_request.merging_organisations.count).to eq(0) 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")) expect(page).to have_content(I18n.t("validations.merge_request.organisation_part_of_another_merge"))
end end
end end
@ -159,7 +159,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "does not update the merge request" do it "does not update the merge request" do
merge_request.reload merge_request.reload
expect(merge_request.merging_organisations.count).to eq(0) 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")) expect(page).to have_content(I18n.t("validations.merge_request.organisation_not_selected"))
end end
end end
@ -174,7 +174,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "does not update the merge request" do it "does not update the merge request" do
merge_request.reload merge_request.reload
expect(merge_request.merging_organisations.count).to eq(0) 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")) expect(page).to have_content(I18n.t("validations.merge_request.organisation_not_selected"))
end end
end end
@ -363,7 +363,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "renders the error" do it "renders the error" do
request 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") expect(page).to have_content("Enter a merge date")
end end
@ -385,7 +385,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "displays the page with an error message" do it "displays the page with an error message" do
request 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") expect(page).to have_content("Enter a valid merge date")
end end
end end
@ -426,7 +426,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "displays the page with an error message" do it "displays the page with an error message" do
request 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.") expect(page).to have_content("The merge date must not be later than a year from today’s date.")
end end
end end
@ -467,7 +467,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "renders the error" do it "renders the error" do
request 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?") expect(page).to have_content("You must answer absorbing organisation already active?")
end end
@ -490,7 +490,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "renders the error" do it "renders the error" do
request 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?") expect(page).to have_content("You must answer was this merge reported by a helpdesk ticket?")
end end
@ -511,7 +511,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "renders the error" do it "renders the error" do
request 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") expect(page).to have_content("You must answer the ticket number")
end end

2
spec/requests/notifications_controller_spec.rb

@ -37,7 +37,7 @@ RSpec.describe NotificationsController, type: :request do
it "gives an error response" do it "gives an error response" do
request request
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_content)
end end
end end

6
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 it "displays the form with an error message" do
request 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.name_missing"))
expect(page).to have_content(I18n.t("validations.organisation.provider_type_missing")) expect(page).to have_content(I18n.t("validations.organisation.provider_type_missing"))
end end
@ -2055,7 +2055,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "has clear filters link" do 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 end
end end
@ -2417,7 +2417,7 @@ RSpec.describe OrganisationsController, type: :request do
it "displays an error" do it "displays an error" do
post "/organisations/#{organisation.id}/schemes/duplicates", headers: headers, params: params 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") expect(page).to have_content("You must resolve all duplicates or indicate that there are no duplicates")
end end
end end

2
spec/requests/sales_logs_controller_spec.rb

@ -92,7 +92,7 @@ RSpec.describe SalesLogsController, type: :request do
it "validates sales log parameters" do it "validates sales log parameters" do
json_response = JSON.parse(response.body) 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."]]]) 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
end end

28
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 it "renders the same page with error message" do
post "/schemes", params: params 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("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.scheme_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.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 it "renders the same page with error message" do
post "/schemes", params: params 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("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.scheme_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.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 it "renders the same page with error message" do
post "/schemes", params: params 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("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.scheme_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.registered_under_care_act.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 it "displays the new page with an error message" do
post "/schemes", params: params 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") expect(page).to have_content("Enter an organisation that owns housing stock")
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid"))
end end
end end
@ -1417,7 +1417,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "renders the same page with error message" do 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("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.service_name.invalid"))
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.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" } } } 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 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid"))
end end
end end
@ -1728,7 +1728,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "renders the same page with error message" do 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("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.owning_organisation_id.invalid"))
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.service_name.invalid"))
@ -2895,7 +2895,7 @@ RSpec.describe SchemesController, type: :request do
let(:params) { { scheme_deactivation_period: { "deactivation_date": "" } } } let(:params) { { scheme_deactivation_period: { "deactivation_date": "" } } }
it "displays the new page with an error message" do 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")) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.not_selected"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.out_of_range", date: "1 April 2022"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid"))
end end
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" } } } 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 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")) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid"))
end end
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)": "" } } } 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 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")) expect(page).to have_content(I18n.t("validations.scheme.toggle_date.invalid"))
end end
end end

58
spec/requests/users_controller_spec.rb

@ -67,7 +67,7 @@ RSpec.describe UsersController, type: :request do
end end
it "shows an error on the same page if passwords don't match" do 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_css("h1", class: "govuk-heading-l", text: "Change your password")
expect(page).to have_selector(".govuk-error-summary__title") expect(page).to have_selector(".govuk-error-summary__title")
expect(page).to have_content("passwords you entered do not match") expect(page).to have_content("passwords you entered do not match")
@ -349,7 +349,7 @@ RSpec.describe UsersController, type: :request do
end end
it "show an error" do it "show an error" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_content)
end end
end end
@ -377,7 +377,7 @@ RSpec.describe UsersController, type: :request do
end end
it "shows an error if passwords don't match" do 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") expect(page).to have_selector(".govuk-error-summary__title")
end end
end end
@ -792,9 +792,8 @@ RSpec.describe UsersController, type: :request do
context "when the current user does not match the user ID" do context "when the current user does not match the user ID" do
it "there is no route" do it "there is no route" do
expect { get "/users/#{other_user.id}/password/edit", headers:, params: {}
get "/users/#{other_user.id}/password/edit", headers:, params: {} expect(response).to have_http_status(:not_found)
}.to raise_error(ActionController::RoutingError)
end end
end end
end end
@ -840,7 +839,7 @@ RSpec.describe UsersController, type: :request do
end end
it "shows an error if passwords don't match" do 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") expect(page).to have_selector(".govuk-error-summary__title")
end end
end end
@ -955,7 +954,7 @@ RSpec.describe UsersController, type: :request do
end end
it "show an error" do it "show an error" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_content)
end end
end end
@ -976,7 +975,7 @@ RSpec.describe UsersController, type: :request do
let(:phone) { "" } let(:phone) { "" }
it "validates telephone number" do 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.blank"))
end end
end end
@ -985,7 +984,7 @@ RSpec.describe UsersController, type: :request do
let(:phone) { "randomstring" } let(:phone) { "randomstring" }
it "validates telephone number" do 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
end end
end end
@ -994,7 +993,7 @@ RSpec.describe UsersController, type: :request do
let(:phone) { "123" } let(:phone) { "123" }
it "validates telephone number" do 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
end end
end end
@ -1075,7 +1074,7 @@ RSpec.describe UsersController, type: :request do
it "shows an error" do it "shows an error" do
request 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")) expect(page).to have_content(I18n.t("validations.email.taken"))
end end
end end
@ -1093,7 +1092,7 @@ RSpec.describe UsersController, type: :request do
it "shows an error" do it "shows an error" do
request 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")) expect(page).to have_content(I18n.t("validations.role.invalid"))
end end
end end
@ -1111,7 +1110,7 @@ RSpec.describe UsersController, type: :request do
it "shows an error" do it "shows an error" do
request 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.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.email.blank"))
end end
@ -1131,7 +1130,7 @@ RSpec.describe UsersController, type: :request do
it "validates telephone number" do it "validates telephone number" do
request 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
end end
end end
@ -1141,7 +1140,7 @@ RSpec.describe UsersController, type: :request do
it "validates telephone number" do it "validates telephone number" do
request 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
end end
end end
@ -1748,9 +1747,8 @@ RSpec.describe UsersController, type: :request do
context "when the current user does not match the user ID" do context "when the current user does not match the user ID" do
it "there is no route" do it "there is no route" do
expect { get "/users/#{other_user.id}/password/edit", headers:, params: {}
get "/users/#{other_user.id}/password/edit", headers:, params: {} expect(response).to have_http_status(:not_found)
}.to raise_error(ActionController::RoutingError)
end end
end end
end end
@ -1912,7 +1910,7 @@ RSpec.describe UsersController, type: :request do
end end
it "shows an error if passwords don't match" do 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") expect(page).to have_selector(".govuk-error-summary__title")
end end
end end
@ -1928,7 +1926,7 @@ RSpec.describe UsersController, type: :request do
let(:params) { { id: user.id, user: { organisation_id: "" } } } let(:params) { { id: user.id, user: { organisation_id: "" } } }
it "does not update the organisation" do 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") expect(page).to have_selector(".govuk-error-summary__title")
end end
end end
@ -2097,7 +2095,7 @@ RSpec.describe UsersController, type: :request do
let(:params) { { id: other_user.id, user: { organisation_id: "" } } } let(:params) { { id: other_user.id, user: { organisation_id: "" } } }
it "does not update the organisation" do 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") expect(page).to have_selector(".govuk-error-summary__title")
end end
end end
@ -2136,7 +2134,7 @@ RSpec.describe UsersController, type: :request do
end end
it "displays the error message" do 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") expect(page).to have_content("Select if you want to reassign logs")
end end
end end
@ -2184,7 +2182,7 @@ RSpec.describe UsersController, type: :request do
end end
it "required the new org to have stock owner relationship with the current user org" do 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.") expect(page).to have_content("New org must be a stock owner of #{other_user.organisation_name} to make this change.")
end end
end end
@ -2198,7 +2196,7 @@ RSpec.describe UsersController, type: :request do
end end
it "required the new org to have stock owner relationship with the managing organisations" do 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.") 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
end end
@ -2215,7 +2213,7 @@ RSpec.describe UsersController, type: :request do
end end
it "required the new org to have managing agent relationship with the current user org" do 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.") expect(page).to have_content("New org must be a managing agent of #{other_user.organisation_name} to make this change.")
end end
end end
@ -2229,7 +2227,7 @@ RSpec.describe UsersController, type: :request do
end end
it "required the new org to have managing agent relationship with owning organisations" do 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.") 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
end end
@ -2246,7 +2244,7 @@ RSpec.describe UsersController, type: :request do
end end
it "show an error" do it "show an error" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_content)
end end
end end
end end
@ -2309,7 +2307,7 @@ RSpec.describe UsersController, type: :request do
it "shows an error messages for all failed validations" do it "shows an error messages for all failed validations" do
request 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.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.email.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.organisation_id.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 it "shows an error" do
request 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")) expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.email.taken"))
end end
end end

70
spec/services/merge/merge_organisations_service_spec.rb

@ -16,7 +16,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "when merging a single organisation into an existing organisation" do 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) { create(:organisation, holds_own_stock: false, name: "absorbing org") }
let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) } let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) }
@ -53,7 +53,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -97,7 +97,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -134,7 +134,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -327,7 +327,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and deactivation is after the merge date and before an open collection window" do 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!(: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) } 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 end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -584,7 +584,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -596,7 +596,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "with merge date in closed collection year" do 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 it "does not validate saledate for closed collection years" do
sales_log.saledate = Time.zone.local(2022, 5, 1) sales_log.saledate = Time.zone.local(2022, 5, 1)
@ -611,7 +611,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and merge date is provided" do 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 it "sets merge date on merged organisation" do
merge_organisations_service.call merge_organisations_service.call
@ -646,7 +646,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -682,7 +682,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -706,7 +706,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "with merge date in closed collection year" do 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 it "does not validate startdate for closed collection years" do
owned_lettings_log.startdate = Time.zone.local(2022, 4, 1) owned_lettings_log.startdate = Time.zone.local(2022, 4, 1)
@ -825,7 +825,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -842,7 +842,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and absorbing_organisation_active_from_merge_date is true" do 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 it "sets available from to merge_date for absorbing organisation" do
merge_organisations_service.call merge_organisations_service.call
@ -854,7 +854,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and absorbing_organisation_active_from_merge_date is true" do 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 it "sets available from to merge_date (today) for absorbing organisation" do
merge_organisations_service.call merge_organisations_service.call
@ -910,7 +910,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "when merging a multiple organisations into an existing organisation" do 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) { create(:organisation, holds_own_stock: false, name: "absorbing org") }
let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) } let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) }
@ -944,7 +944,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1069,7 +1069,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1086,7 +1086,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and merge date is provided" do 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 it "sets merge date and absorbing organisation on merged organisations" do
merge_organisations_service.call merge_organisations_service.call
@ -1102,7 +1102,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "when merging a single organisation into a new organisation" do 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) { create(:organisation, :without_dpc, holds_own_stock: false) }
let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) } let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) }
@ -1139,7 +1139,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1183,7 +1183,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1220,7 +1220,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1325,7 +1325,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1357,7 +1357,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1370,7 +1370,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and merge date is provided" do 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 it "sets merge date on merged organisation" do
merge_organisations_service.call merge_organisations_service.call
@ -1396,7 +1396,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1432,7 +1432,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1538,7 +1538,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1555,7 +1555,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and absorbing_organisation_active_from_merge_date is true" do 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 it "sets available from to merge_date for absorbing organisation" do
merge_organisations_service.call merge_organisations_service.call
@ -1567,7 +1567,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and absorbing_organisation_active_from_merge_date is true" do 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 it "sets available from to merge_date (today) for absorbing organisation" do
merge_organisations_service.call merge_organisations_service.call
@ -1579,7 +1579,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "when merging multiple organisations into a new organisation" do 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) { create(:organisation, :without_dpc, holds_own_stock: false) }
let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) } let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) }
@ -1628,7 +1628,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1670,7 +1670,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
it "rolls back if there's an error" do 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(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) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
@ -1687,7 +1687,7 @@ RSpec.describe Merge::MergeOrganisationsService do
end end
context "and merge date is provided" do 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 it "sets merge date and absorbing organisation on merged organisations" do
merge_organisations_service.call merge_organisations_service.call

Loading…
Cancel
Save