Browse Source

CLDC-3487: Clear location when clearing scheme due to org change

pull/2452/head
Rachael Booth 2 years ago
parent
commit
639265f969
  1. 4
      app/models/lettings_log.rb
  2. 20
      spec/models/lettings_log_spec.rb

4
app/models/lettings_log.rb

@ -715,8 +715,10 @@ private
def reset_scheme def reset_scheme
return unless scheme && owning_organisation return unless scheme && owning_organisation
return unless scheme.owning_organisation != owning_organisation
self.scheme = nil if scheme.owning_organisation != owning_organisation self.scheme = nil
self.location = nil
end end
def reset_invalidated_dependent_fields! def reset_invalidated_dependent_fields!

20
spec/models/lettings_log_spec.rb

@ -949,23 +949,27 @@ RSpec.describe LettingsLog do
context "when the organisation selected doesn't match the scheme set" do context "when the organisation selected doesn't match the scheme set" do
let(:scheme) { create(:scheme, owning_organisation: assigned_to_user.organisation) } let(:scheme) { create(:scheme, owning_organisation: assigned_to_user.organisation) }
let(:location) { create(:location, scheme:) } let(:location) { create_list(:location, 2, scheme:).first }
let(:lettings_log) { create(:lettings_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id) } let(:lettings_log) { create(:lettings_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id, location_id: location.id) }
it "clears the scheme value" do it "clears the scheme and location values" do
lettings_log.update!(owning_organisation: organisation_2) lettings_log.update!(owning_organisation: organisation_2)
expect(lettings_log.reload.scheme).to be nil lettings_log.reload
expect(lettings_log.scheme).to be nil
expect(lettings_log.location).to be nil
end end
end end
context "when the organisation selected still matches the scheme set" do context "when the organisation selected still matches the scheme set" do
let(:scheme) { create(:scheme, owning_organisation: organisation_2) } let(:scheme) { create(:scheme, owning_organisation: organisation_2) }
let(:location) { create(:location, scheme:) } let(:location) { create_list(:location, 2, scheme:).first }
let(:lettings_log) { create(:lettings_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id) } let(:lettings_log) { create(:lettings_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id, location_id: location.id) }
it "does not clear the scheme value" do it "does not clear the scheme or location value" do
lettings_log.update!(owning_organisation: organisation_2) lettings_log.update!(owning_organisation: organisation_2)
expect(lettings_log.reload.scheme_id).to eq(scheme.id) lettings_log.reload
expect(lettings_log.scheme_id).to eq(scheme.id)
expect(lettings_log.location_id).to eq(location.id)
end end
end end
end end

Loading…
Cancel
Save