docbrown/spec/services/organizations/delete_spec.rb
Fernando Valverde c24e227f55
Extract Organization#conditionally_update_articles to worker (#18956)
* Extract conditionally_update_articles to worker

* Split to individual articles on workergits

* Fix some failed specs

* Fix another spec
2023-01-18 11:58:57 -06:00

41 lines
1.2 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")
sidekiq_perform_enqueued_jobs
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