diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 490a5cfd1..8798f4935 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -36,4 +36,34 @@ describe Comment do expect(comment).to be_as_moderator end end + + describe "cache" do + let(:comment) { create(:comment) } + + it "should expire cache when it has a new vote" do + expect { create(:vote, votable: comment) } + .to change { comment.updated_at } + end + + it "should expire cache when hidden" do + expect { comment.hide } + .to change { comment.updated_at } + end + + it "should expire cache when the author is hidden" do + expect { comment.user.hide } + .to change { comment.reload.updated_at } + end + + it "should expire cache when the author changes" do + expect { comment.user.update(username: "Isabel") } + .to change { comment.reload.updated_at } + end + + it "should expire cache when the author's organization get verified" do + create(:organization, user: comment.user) + expect { comment.user.organization.verify } + .to change { comment.reload.updated_at} + end + end end diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 25e878d18..951837956 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -268,4 +268,34 @@ describe Debate do end end + describe "cache" do + let(:debate) { create(:debate) } + + it "should expire cache when it has a new comment" do + expect { create(:comment, commentable: debate) } + .to change { debate.updated_at } + end + + it "should expire cache when it has a new vote" do + expect { create(:vote, votable: debate) } + .to change { debate.updated_at } + end + + it "should expire cache when it has a new tag" do + expect { debate.update(tag_list: "new tag") } + .to change { debate.updated_at } + end + + it "should expire cache when its author changes" do + expect { debate.author.update(username: "Eva") } + .to change { debate.reload.updated_at } + end + + it "should expire cache when the author's organization get verified" do + create(:organization, user: debate.author) + expect { debate.author.organization.verify } + .to change { debate.reload.updated_at} + end + end + end \ No newline at end of file diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 282d8d615..f9c24ec4d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -299,4 +299,25 @@ describe User do end end + describe "cache" do + let(:user) { create(:user) } + + it "should expire cache with becoming a moderator" do + expect { create(:moderator, user: user) } + .to change { user.updated_at} + end + + it "should expire cache with becoming an admin" do + expect { create(:administrator, user: user) } + .to change { user.updated_at} + end + + it "should expire cache with becoming a veridied organization" do + create(:organization, user: user) + expect { user.organization.verify } + .to change { user.reload.updated_at} + end + + end + end