Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added callbacks to purge cache #15092

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/article.rb
Expand Up @@ -101,8 +101,13 @@ class Article < ApplicationRecord
before_save :fetch_video_duration
before_save :set_caches
before_create :create_password
# Purging article edge-cache
after_create :purge_all
before_destroy :before_destroy_actions, prepend: true

after_destroy :purge, :purge_all
after_save :purge

after_save :create_conditional_autovomits
after_save :bust_cache
after_save :notify_slack_channel_about_publication
Expand Down
28 changes: 28 additions & 0 deletions spec/models/article_spec.rb
Expand Up @@ -1373,4 +1373,32 @@ def foo():
expect(another_article.errors.messages[:feed_source_url]).to include(error_message)
end
end

describe "Validating edge-cache purging calls" do
let(:article) { create(:article) }

before do
allow(article).to receive(:purge)
allow(article).to receive(:purge_all)
end

it "invokes :purge_all when a new article is created" do
article.run_callbacks(:create)

expect(article).to have_received(:purge_all).once
end

it "invokes :purge when an article is saved" do
article.run_callbacks(:save)

expect(article).to have_received(:purge).once
end

it "invokes :purge and :purge_all when an article is destroyed" do
article.run_callbacks(:destroy)

expect(article).to have_received(:purge).once
expect(article).to have_received(:purge_all).once
end
end
end