Browse Source

Allow discarding users for merged orgs (#2518)

pull/2520/head^2
kosiakkatrina 6 months ago committed by GitHub
parent
commit
a08f6a6ca8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      app/models/user.rb
  2. 21
      spec/models/organisation_spec.rb

3
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

21
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

Loading…
Cancel
Save