From e639c5c8618286e2f081a2a3b25a909567b8c7dc Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:19:36 +0100 Subject: [PATCH 1/2] CLDC-3558 Display correct orgs data protection confirmation (#2511) * Display correct orgs data protection confirmation * Remove binding --- app/controllers/organisations_controller.rb | 2 +- .../requests/organisations_controller_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 138baa78c..dfe50fa22 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -238,7 +238,7 @@ class OrganisationsController < ApplicationController end def data_sharing_agreement - @data_protection_confirmation = current_user.organisation.data_protection_confirmation + @data_protection_confirmation = @organisation.data_protection_confirmation end def confirm_data_sharing_agreement diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index e6fb20ac7..4b6cefe5f 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -2099,6 +2099,25 @@ RSpec.describe OrganisationsController, type: :request do expect(response).to have_http_status(:ok) end end + + context "when signed in as support" do + let(:support_user) { create(:user, :support, with_dsa: false) } + + before do + organisation.data_protection_confirmation.update!(signed_at: Time.zone.local(2001, 3, 2), organisation_name: "Org name") + allow(support_user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in support_user + end + + context "and viewing other org dsa" do + it "shows correct org data and dates" do + get "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers + expect(response).to have_http_status(:ok) + expect(page).to have_content("This agreement is made the 2nd day of March 2001") + expect(page).to have_content("1) Org name") + end + end + end end describe "POST #data_sharing_agreement" do From d2964d73db4f276f1db841a282ed3b0dfe34b225 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Thu, 18 Jul 2024 13:01:55 +0100 Subject: [PATCH 2/2] CLDC-3549: Ensure location page routing is updated when log is changed (#2502) --- .../lettings_log_variables.rb | 4 +- spec/models/lettings_log_spec.rb | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index e316d6efd..91e645c47 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -31,8 +31,8 @@ module DerivedVariables::LettingsLogVariables def scheme_has_multiple_locations? return false unless scheme - @scheme_locations_count ||= scheme.locations.active_in_2_weeks.size - @scheme_locations_count > 1 + scheme_locations_count = scheme.locations.active_in_2_weeks.size + scheme_locations_count > 1 end def set_derived_fields! diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 2f4576719..5c40fbe08 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -486,18 +486,56 @@ RSpec.describe LettingsLog do end describe "when changing a log's scheme and hence calling reset_scheme_location!" do - let(:scheme) { FactoryBot.create(:scheme) } - let(:invalid_location_1) { FactoryBot.create(:location, scheme:, startdate: Time.zone.today + 3.weeks) } - let(:valid_location) { FactoryBot.create(:location, scheme:, startdate: Time.zone.yesterday) } - let(:invalid_location_2) { FactoryBot.create(:location, scheme:, startdate: Time.zone.today + 3.weeks) } + before do + Timecop.return + Singleton.__init__(FormHandler) + end context "when there is one valid location and many invalid locations in the new scheme" do + let(:scheme) { create(:scheme) } + let(:invalid_location_1) { create(:location, scheme:, startdate: Time.zone.today + 3.weeks) } + let(:valid_location) { create(:location, scheme:, startdate: Time.zone.yesterday) } + let(:invalid_location_2) { create(:location, scheme:, startdate: Time.zone.today + 3.weeks) } let(:log) { create(:lettings_log, scheme: nil, location_id: nil, startdate: Time.zone.today) } it "infers that the log is for the valid location" do expect { log.update!(scheme:) }.to change(log, :location_id).from(nil).to(valid_location.id) end end + + context "when there are many valid locations in the new scheme" do + let(:old_scheme) { create(:scheme, owning_organisation:) } + let(:old_location) { create(:location, scheme: old_scheme) } + let(:new_scheme) { create(:scheme, owning_organisation:) } + + before do + create_list(:location, 2, scheme: new_scheme) + end + + context "with a 2023 log" do + let(:log) { create(:lettings_log, :completed, :sh, :ignore_validation_errors, startdate: Time.zone.local(2024, 1, 1), owning_organisation:, scheme_id: old_scheme.id, location_id: old_location.id) } + + it "clears the location set on the log" do + expect { log.update!(scheme: new_scheme) }.to change(log, :location_id).from(old_location.id).to(nil) + end + + it "recalculates the log status" do + expect { log.update!(scheme: new_scheme) }.to change(log, :status).from("completed").to("in_progress") + end + end + + context "with a current year log" do + let(:log) { create(:lettings_log, :completed, :sh, :startdate_today, owning_organisation:, scheme_id: old_scheme.id, location_id: old_location.id) } + + it "clears the location set on the log" do + expect { log.update!(scheme: new_scheme) }.to change(log, :location_id).from(old_location.id).to(nil) + end + + it "recalculates the log status" do + expect { log.update!(scheme: new_scheme) }.to change(log, :status).from("completed").to("in_progress") + end + end + end end context "and a scheme with a single log is selected" do