Update bust_user to EdgeCache::BustUser (#12051)
This commit is contained in:
parent
2a345d5214
commit
eca7be8201
6 changed files with 15 additions and 18 deletions
|
|
@ -53,7 +53,7 @@ class OrganizationsController < ApplicationController
|
|||
authorize organization
|
||||
if organization.destroy
|
||||
current_user.touch(:organization_info_updated_at)
|
||||
CacheBuster.bust_user(current_user)
|
||||
EdgeCache::BustUser.call(current_user)
|
||||
flash[:settings_notice] = "Your organization: \"#{organization.name}\" was successfully deleted."
|
||||
redirect_to user_settings_path(:organization)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ module Users
|
|||
module DeleteArticles
|
||||
module_function
|
||||
|
||||
def call(user, cache_buster = CacheBuster)
|
||||
def call(user)
|
||||
return if user.articles.blank?
|
||||
|
||||
virtual_articles = user.articles.map { |article| Article.new(article.attributes) }
|
||||
|
|
@ -12,7 +12,7 @@ module Users
|
|||
article.comments.includes(:user).find_each do |comment|
|
||||
comment.reactions.delete_all
|
||||
EdgeCache::BustComment.call(comment.commentable)
|
||||
cache_buster.bust_user(comment.user)
|
||||
EdgeCache::BustUser.call(comment.user)
|
||||
comment.remove_from_elasticsearch
|
||||
comment.delete
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ module Users
|
|||
module DeleteComments
|
||||
module_function
|
||||
|
||||
def call(user, cache_buster = CacheBuster)
|
||||
def call(user)
|
||||
return unless user.comments.any?
|
||||
|
||||
user.comments.find_each do |comment|
|
||||
|
|
@ -12,7 +12,7 @@ module Users
|
|||
comment.remove_from_elasticsearch
|
||||
comment.delete
|
||||
end
|
||||
cache_buster.bust_user(user)
|
||||
EdgeCache::BustUser.call(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ module DataUpdateScripts
|
|||
return unless ENV["FOREM_CONTEXT"] == "forem_cloud"
|
||||
|
||||
User.find_each do |user|
|
||||
CacheBuster.bust_user(user)
|
||||
EdgeCache::BustUser.call(user)
|
||||
end
|
||||
|
||||
Organization.find_each do |organization|
|
||||
|
|
|
|||
|
|
@ -23,12 +23,10 @@ RSpec.describe Users::DeleteArticles, type: :service do
|
|||
end
|
||||
|
||||
context "with comments" do
|
||||
let(:buster) { double }
|
||||
|
||||
before do
|
||||
allow(EdgeCache::BustComment).to receive(:call)
|
||||
allow(EdgeCache::BustArticle).to receive(:call)
|
||||
allow(buster).to receive(:bust_user)
|
||||
allow(EdgeCache::BustUser).to receive(:call)
|
||||
|
||||
create_list(:comment, 2, commentable: article, user: user2)
|
||||
end
|
||||
|
|
@ -47,9 +45,9 @@ RSpec.describe Users::DeleteArticles, type: :service do
|
|||
end
|
||||
|
||||
it "busts cache" do
|
||||
described_class.call(user, buster)
|
||||
described_class.call(user)
|
||||
expect(EdgeCache::BustComment).to have_received(:call).with(article).twice
|
||||
expect(buster).to have_received(:bust_user).with(user2).at_least(:once)
|
||||
expect(EdgeCache::BustUser).to have_received(:call).with(user2).at_least(:once)
|
||||
expect(EdgeCache::BustArticle).to have_received(:call).with(article)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,18 +5,17 @@ RSpec.describe Users::DeleteComments, type: :service do
|
|||
let(:trusted_user) { create(:user, :trusted) }
|
||||
let(:article) { create(:article) }
|
||||
let(:comment) { create(:comment, user: user, commentable: article) }
|
||||
let(:buster) { double }
|
||||
|
||||
before do
|
||||
create_list(:comment, 2, commentable: article, user: user)
|
||||
|
||||
allow(EdgeCache::BustComment).to receive(:call)
|
||||
allow(buster).to receive(:bust_user)
|
||||
allow(EdgeCache::BustUser).to receive(:call)
|
||||
end
|
||||
|
||||
it "destroys user comments" do
|
||||
comment
|
||||
described_class.call(user, buster)
|
||||
described_class.call(user)
|
||||
expect(Comment.where(user_id: user.id).any?).to be false
|
||||
end
|
||||
|
||||
|
|
@ -24,19 +23,19 @@ RSpec.describe Users::DeleteComments, type: :service do
|
|||
comment
|
||||
sidekiq_perform_enqueued_jobs
|
||||
expect(comment.elasticsearch_doc).not_to be_nil
|
||||
sidekiq_perform_enqueued_jobs { described_class.call(user, buster) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.call(user) }
|
||||
expect { comment.elasticsearch_doc }.to raise_error(Search::Errors::Transport::NotFound)
|
||||
end
|
||||
|
||||
it "busts cache" do
|
||||
described_class.call(user, buster)
|
||||
described_class.call(user)
|
||||
expect(EdgeCache::BustComment).to have_received(:call).with(article).at_least(:once)
|
||||
expect(buster).to have_received(:bust_user).with(user)
|
||||
expect(EdgeCache::BustUser).to have_received(:call).with(user)
|
||||
end
|
||||
|
||||
it "destroys moderation notifications properly" do
|
||||
create(:notification, notifiable: comment, action: "Moderation", user: trusted_user)
|
||||
described_class.call(user, buster)
|
||||
described_class.call(user)
|
||||
expect(Notification.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue