Remove Reactions::BustReactableCacheJob & spec (#6060)

This commit is contained in:
Alex 2020-02-13 08:58:47 -08:00 committed by GitHub
parent bc9fc6ee3b
commit 611706f3f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 52 deletions

View file

@ -1,18 +0,0 @@
module Reactions
class BustReactableCacheJob < ApplicationJob
queue_as :bust_reactable_cache
def perform(reaction_id, cache_buster = CacheBuster)
reaction = Reaction.find_by(id: reaction_id)
return unless reaction&.reactable
cache_buster.bust reaction.user.path
if reaction.reactable_type == "Article"
cache_buster.bust "/reactions?article_id=#{reaction.reactable_id}"
elsif reaction.reactable_type == "Comment"
path = "/reactions?commentable_id=#{reaction.reactable.commentable_id}&commentable_type=#{reaction.reactable.commentable_type}"
cache_buster.bust(path)
end
end
end
end

View file

@ -1,34 +0,0 @@
require "rails_helper"
RSpec.describe Reactions::BustReactableCacheJob, type: :job do
include_examples "#enqueues_job", "bust_reactable_cache", 2
describe "#perform_now" do
let(:user) { create(:user) }
let(:article) { create(:article) }
let(:reaction) { create(:reaction, reactable: article, user: user) }
let(:comment) { create(:comment, commentable: article) }
let(:comment_reaction) { create(:reaction, reactable: comment, user: user) }
let(:buster) { double }
before do
allow(buster).to receive(:bust)
end
it "busts the reactable article cache" do
described_class.perform_now(reaction.id, buster)
expect(buster).to have_received(:bust).with(user.path).once
expect(buster).to have_received(:bust).with("/reactions?article_id=#{article.id}").once
end
it "busts the reactable comment cache" do
described_class.perform_now(comment_reaction.id, buster)
expect(buster).to have_received(:bust).with(user.path).once
expect(buster).to have_received(:bust).with("/reactions?commentable_id=#{article.id}&commentable_type=Article").once
end
it "doesn't fail if a reaction doesn't exist" do
described_class.perform_now(Reaction.maximum(:id).to_i + 1)
end
end
end