Browse Source

Merge branch 'main' into FixTestsForHardYearEnd

pull/2509/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
06d0530365
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/controllers/organisations_controller.rb
  2. 4
      app/models/derived_variables/lettings_log_variables.rb
  3. 46
      spec/models/lettings_log_spec.rb
  4. 19
      spec/requests/organisations_controller_spec.rb

2
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

4
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!

46
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

19
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

Loading…
Cancel
Save