From e0d0fd6c96d9f78989fcd2900520344f6499d668 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 29 Dec 2020 03:48:36 -0500 Subject: [PATCH] Update bust_organization to EdgeCache::BustOrganization (#12048) * Update bust_organization to service * Add spec for nil slug * Update argument check --- app/workers/organizations/bust_cache_worker.rb | 4 +++- ...01026155851_resave_to_bust_cache_for_imgproxy.rb | 2 +- .../workers/organizations/bust_cache_worker_spec.rb | 13 ++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/workers/organizations/bust_cache_worker.rb b/app/workers/organizations/bust_cache_worker.rb index cda584e49..5eed2ae04 100644 --- a/app/workers/organizations/bust_cache_worker.rb +++ b/app/workers/organizations/bust_cache_worker.rb @@ -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 diff --git a/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb b/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb index 15198d11f..a97e56cc6 100644 --- a/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb +++ b/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb @@ -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) diff --git a/spec/workers/organizations/bust_cache_worker_spec.rb b/spec/workers/organizations/bust_cache_worker_spec.rb index 3b5592251..950c0efab 100644 --- a/spec/workers/organizations/bust_cache_worker_spec.rb +++ b/spec/workers/organizations/bust_cache_worker_spec.rb @@ -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