From a08f6a6ca898d2e5811d8df7c2305204cd5948c6 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:40:05 +0100 Subject: [PATCH] Allow discarding users for merged orgs (#2518) --- app/models/user.rb | 3 ++- spec/models/organisation_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 27187529a..d25faaa53 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -264,7 +264,8 @@ class User < ApplicationRecord end def discard! - update!(discarded_at: Time.zone.now) + self.discarded_at = Time.zone.now + save!(validate: false) end protected diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index d00f79039..3964923f0 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -298,4 +298,25 @@ RSpec.describe Organisation, type: :model do expect(organisation.status).to be(:active) end end + + describe "discard" do + let(:organisation) { create(:organisation) } + let!(:user) { create(:user, organisation:) } + let!(:scheme) { create(:scheme, owning_organisation: organisation) } + + context "when merged organisation is discarded" do + before do + organisation.merge_date = Time.zone.yesterday + organisation.absorbing_organisation_id = create(:organisation).id + organisation.save! + end + + it "discards all of the organisation resources" do + organisation.discard! + expect(organisation.status).to eq(:deleted) + expect(user.reload.status).to eq(:deleted) + expect(scheme.reload.status).to eq(:deleted) + end + end + end end