Update bust_organization to EdgeCache::BustOrganization (#12048)

* Update bust_organization to service

* Add spec for nil slug

* Update argument check
This commit is contained in:
Alex 2020-12-29 03:48:36 -05:00 committed by GitHub
parent 13f7f9b353
commit e0d0fd6c96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View file

@ -1,11 +1,13 @@
module Organizations
class BustCacheWorker < BustCacheBaseWorker
def perform(organization_id, slug)
return unless organization_id && slug
organization = Organization.find_by(id: organization_id)
return unless organization
CacheBuster.bust_organization(organization, slug)
EdgeCache::BustOrganization.call(organization, slug)
end
end
end

View file

@ -8,7 +8,7 @@ module DataUpdateScripts
end
Organization.find_each do |organization|
CacheBuster.bust_organization(organization, organization.slug)
EdgeCache::BustOrganization.call(organization, organization.slug)
end
Article.find_each(&:save)

View file

@ -6,20 +6,27 @@ RSpec.describe Organizations::BustCacheWorker, type: :worker do
let(:worker) { subject }
before do
allow(CacheBuster).to receive(:bust_organization)
allow(EdgeCache::BustOrganization).to receive(:call)
end
describe "when no organization is found" do
it "doest not call the service" do
allow(Organization).to receive(:find_by).and_return(nil)
worker.perform(789, "SlUg")
expect(CacheBuster).not_to have_received(:bust_organization)
expect(EdgeCache::BustOrganization).not_to have_received(:call)
end
end
describe "when no slug is found" do
it "doest not call the service" do
worker.perform(organization.id, nil)
expect(EdgeCache::BustOrganization).not_to have_received(:call)
end
end
it "busts cache" do
worker.perform(organization.id, "SlUg")
expect(CacheBuster).to have_received(:bust_organization).with(organization, "SlUg")
expect(EdgeCache::BustOrganization).to have_received(:call).with(organization, "SlUg")
end
end
end