diff --git a/app/controllers/admin/tools_controller.rb b/app/controllers/admin/tools_controller.rb index db9de65b7..c6313a0c0 100644 --- a/app/controllers/admin/tools_controller.rb +++ b/app/controllers/admin/tools_controller.rb @@ -36,7 +36,7 @@ module Admin def handle_article_cache article = Article.find(params[:bust_article].to_i) article.touch(:last_commented_at) - CacheBuster.bust_article(article) + EdgeCache::BustArticle.call(article) end def bust_link(link) diff --git a/app/services/users/delete_articles.rb b/app/services/users/delete_articles.rb index 3c14ff23d..d3b2c4f7c 100644 --- a/app/services/users/delete_articles.rb +++ b/app/services/users/delete_articles.rb @@ -21,7 +21,7 @@ module Users article.purge end virtual_articles.each do |article| - cache_buster.bust_article(article) + EdgeCache::BustArticle.call(article) end end end diff --git a/app/workers/articles/bust_cache_worker.rb b/app/workers/articles/bust_cache_worker.rb index e825d6a35..2802a15e8 100644 --- a/app/workers/articles/bust_cache_worker.rb +++ b/app/workers/articles/bust_cache_worker.rb @@ -1,9 +1,11 @@ module Articles class BustCacheWorker < BustCacheBaseWorker - def perform(article_id, cache_buster = "CacheBuster") + def perform(article_id) article = Article.find_by(id: article_id) - cache_buster.constantize.bust_article(article) if article + return unless article + + EdgeCache::BustArticle.call(article) end end end diff --git a/spec/services/users/delete_articles_spec.rb b/spec/services/users/delete_articles_spec.rb index eb092d725..1817209da 100644 --- a/spec/services/users/delete_articles_spec.rb +++ b/spec/services/users/delete_articles_spec.rb @@ -27,7 +27,7 @@ RSpec.describe Users::DeleteArticles, type: :service do before do allow(EdgeCache::BustComment).to receive(:call) - allow(buster).to receive(:bust_article) + allow(EdgeCache::BustArticle).to receive(:call) allow(buster).to receive(:bust_user) create_list(:comment, 2, commentable: article, user: user2) @@ -50,7 +50,7 @@ RSpec.describe Users::DeleteArticles, type: :service do described_class.call(user, buster) expect(EdgeCache::BustComment).to have_received(:call).with(article).twice expect(buster).to have_received(:bust_user).with(user2).at_least(:once) - expect(buster).to have_received(:bust_article).with(article) + expect(EdgeCache::BustArticle).to have_received(:call).with(article) end it "removes comments from Elasticsearch", :aggregate_failures do diff --git a/spec/workers/articles/bust_cache_worker_spec.rb b/spec/workers/articles/bust_cache_worker_spec.rb index 83dd19f0a..be304e991 100644 --- a/spec/workers/articles/bust_cache_worker_spec.rb +++ b/spec/workers/articles/bust_cache_worker_spec.rb @@ -1,9 +1,5 @@ require "rails_helper" -class NewBuster - def self.bust_article(*); end -end - RSpec.describe Articles::BustCacheWorker, type: :worker do include_examples "#enqueues_on_correct_queue", "high_priority", 1 @@ -16,30 +12,27 @@ RSpec.describe Articles::BustCacheWorker, type: :worker do before do allow(Article).to receive(:find_by).with(id: article_id).and_return(article) + allow(EdgeCache::BustArticle).to receive(:call).with(article) end - it "with cache buster defined busts cache with defined buster" do - allow(NewBuster).to receive(:bust_article) - worker.perform(article_id, "NewBuster") - expect(NewBuster).to have_received(:bust_article).with(article) - end - - it "without cache buster defined busts cache with default" do - allow(CacheBuster).to receive(:bust_article) + it "busts the cache" do worker.perform(article_id) - expect(CacheBuster).to have_received(:bust_article).with(article) + expect(EdgeCache::BustArticle).to have_received(:call).with(article) end end context "without article" do + before do + allow(EdgeCache::BustArticle).to receive(:call) + end + it "does not error" do - expect { worker.perform(nil, "CacheBuster") }.not_to raise_error + expect { worker.perform(nil) }.not_to raise_error end it "does not bust cache" do - allow(CacheBuster).to receive(:bust_article) worker.perform(nil) - expect(CacheBuster).not_to have_received(:bust_article) + expect(EdgeCache::BustArticle).not_to have_received(:call) end end end