docbrown/spec/services/organizations/delete_spec.rb
Anna Buianova ce46ea2378
Organizations delete optimizations and refactoring (#13610)
* Delete org notifications in batches before org destroy

* Moved on destroy callbacks to a service for org delete

* Be consistent with org_id in specs

* Removed irrelevant code

* Moved article_ids to initializer for Organizations::Delete

* Update articles cached_organization explicitly after deleting an org
2021-05-11 12:14:55 +03:00

38 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe Organizations::Delete, type: :service do
let(:org) { create(:organization) }
let(:org_id) { org.id }
it "deletes an organization" do
described_class.call(org)
expect(Organization.find_by(id: org_id)).to be_nil
end
it "deletes notifications" do
create_list(:notification, 5, organization_id: org_id)
expect(Notification.where(organization_id: org_id).count).to eq(5)
described_class.call(org)
expect(Notification.where(organization_id: org_id).count).to eq(0)
end
context "with articles" do
let!(:article) { create(:article, organization_id: org_id) }
it "syncs articles" do
expect(article.cached_organization.name).to eq(org.name)
described_class.call(org)
article.reload
expect(article.cached_organization).to be_nil
end
it "removes the organization name from the .reading_list_document after destroy" do
org.update(name: "ACME")
expect(article.reload.reading_list_document).to include("acme")
described_class.call(org)
expect(article.reload.reading_list_document).not_to include("acme")
end
end
end