forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard bust_comment against nil commentable (forem#2991)
- Loading branch information
1 parent
c510f15
commit a99c072
Showing
2 changed files
with
44 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe CacheBuster do | ||
let(:cache_buster) { described_class.new } | ||
let(:user) { create(:user) } | ||
let(:article) { create(:article, user_id: user.id) } | ||
let(:comment) { create(:comment, user_id: user.id, commentable_id: article.id) } | ||
|
||
it "busts comment" do | ||
commentable = Article.find(comment.commentable_id) | ||
username = User.find(comment.user_id).username | ||
described_class.new.bust_comment(commentable, username) | ||
end | ||
describe "#bust_comment" do | ||
it "busts comment" do | ||
cache_buster.bust_comment(comment.commentable, user.username) | ||
end | ||
|
||
it "works if commentable is missing" do | ||
cache_buster.bust_comment(nil, user.username) | ||
end | ||
|
||
it "busts article" do | ||
described_class.new.bust_article(article) | ||
it "works if username is missing" do | ||
cache_buster.bust_comment(comment.commentable, "") | ||
end | ||
end | ||
|
||
it "busts featured article" do | ||
article.update(featured: true) | ||
described_class.new.bust_article(article) | ||
describe "#bust_article" do | ||
it "busts article" do | ||
cache_buster.bust_article(article) | ||
end | ||
|
||
it "busts featured article" do | ||
article.update_columns(featured: true) | ||
cache_buster.bust_article(article) | ||
end | ||
end | ||
end |