Create services for busting pages, tags, events, and podcasts (#11812)

* Create bust_page service and spec

* Specify spec with .once

* Create bust_tag service and spec

* Create bust_event service and spec

* Create bust_podcast service and spec
This commit is contained in:
Alex 2020-12-09 10:37:02 -05:00 committed by GitHub
parent 67342a4edf
commit 8598ed090e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 151 additions and 0 deletions

View file

@ -0,0 +1,8 @@
module EdgeCache
class BustEvents < Bust
def self.call
bust("/events")
bust("/events?i=i")
end
end
end

View file

@ -0,0 +1,12 @@
module EdgeCache
class BustPage < Bust
def self.call(slug)
return unless slug
bust("/page/#{slug}")
bust("/page/#{slug}?i=i")
bust("/#{slug}")
bust("/#{slug}?i=i")
end
end
end

View file

@ -0,0 +1,9 @@
module EdgeCache
class BustPodcast < Bust
def self.call(path)
return unless path
bust("/#{path}")
end
end
end

View file

@ -0,0 +1,15 @@
module EdgeCache
class BustTag < Bust
def self.call(tag)
return unless tag
tag.purge
bust("/t/#{tag.name}")
bust("/t/#{tag.name}?i=i")
bust("/t/#{tag.name}/?i=i")
bust("/t/#{tag.name}/")
bust("/tags")
end
end
end

View file

@ -0,0 +1,24 @@
require "rails_helper"
RSpec.describe EdgeCache::BustEvents, type: :service do
let(:paths) do
[
"/events",
"/events?i=i",
]
end
before do
paths.each do |path|
allow(described_class).to receive(:bust).with(path).once
end
end
it "busts the cache" do
described_class.call
paths.each do |path|
expect(described_class).to have_received(:bust).with(path).once
end
end
end

View file

@ -0,0 +1,27 @@
require "rails_helper"
RSpec.describe EdgeCache::BustPage, type: :service do
let(:slug) { "slug" }
let(:paths) do
[
"/page/#{slug}",
"/page/#{slug}?i=i",
"/#{slug}",
"/#{slug}?i=i",
]
end
before do
paths.each do |path|
allow(described_class).to receive(:bust).with(path).once
end
end
it "busts the cache" do
described_class.call(slug)
paths.each do |path|
expect(described_class).to have_received(:bust).with(path).once
end
end
end

View file

@ -0,0 +1,24 @@
require "rails_helper"
RSpec.describe EdgeCache::BustPodcast, type: :service do
let(:podcast_path) { "podcast_path" }
let(:paths) do
[
"/#{podcast_path}",
]
end
before do
paths.each do |path|
allow(described_class).to receive(:bust).with(path).once
end
end
it "busts the cache" do
described_class.call(podcast_path)
paths.each do |path|
expect(described_class).to have_received(:bust).with(path).once
end
end
end

View file

@ -0,0 +1,32 @@
require "rails_helper"
RSpec.describe EdgeCache::BustTag, type: :service do
let(:tag) { create(:tag) }
let(:paths) do
[
"/t/#{tag.name}",
"/t/#{tag.name}?i=i",
"/t/#{tag.name}/?i=i",
"/t/#{tag.name}/",
"/tags",
]
end
before do
paths.each do |path|
allow(described_class).to receive(:bust).with(path).once
end
allow(tag).to receive(:purge).once
end
it "busts the cache" do
described_class.call(tag)
paths.each do |path|
expect(described_class).to have_received(:bust).with(path).once
end
expect(tag).to have_received(:purge).once
end
end