Update bust_article to BustArticle (#11931)
* Update bust_article to BustArticle * Fix spec
This commit is contained in:
parent
921a76ae30
commit
d03d03bc39
5 changed files with 17 additions and 22 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue