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:
parent
67342a4edf
commit
8598ed090e
8 changed files with 151 additions and 0 deletions
8
app/services/edge_cache/bust_events.rb
Normal file
8
app/services/edge_cache/bust_events.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
module EdgeCache
|
||||
class BustEvents < Bust
|
||||
def self.call
|
||||
bust("/events")
|
||||
bust("/events?i=i")
|
||||
end
|
||||
end
|
||||
end
|
||||
12
app/services/edge_cache/bust_page.rb
Normal file
12
app/services/edge_cache/bust_page.rb
Normal 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
|
||||
9
app/services/edge_cache/bust_podcast.rb
Normal file
9
app/services/edge_cache/bust_podcast.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
module EdgeCache
|
||||
class BustPodcast < Bust
|
||||
def self.call(path)
|
||||
return unless path
|
||||
|
||||
bust("/#{path}")
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/services/edge_cache/bust_tag.rb
Normal file
15
app/services/edge_cache/bust_tag.rb
Normal 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
|
||||
24
spec/services/edge_cache/bust_events_spec.rb
Normal file
24
spec/services/edge_cache/bust_events_spec.rb
Normal 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
|
||||
27
spec/services/edge_cache/bust_page_spec.rb
Normal file
27
spec/services/edge_cache/bust_page_spec.rb
Normal 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
|
||||
24
spec/services/edge_cache/bust_podcast_spec.rb
Normal file
24
spec/services/edge_cache/bust_podcast_spec.rb
Normal 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
|
||||
32
spec/services/edge_cache/bust_tag_spec.rb
Normal file
32
spec/services/edge_cache/bust_tag_spec.rb
Normal 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
|
||||
Loading…
Add table
Reference in a new issue