expires debate cache after a new flag

This commit is contained in:
rgarcia
2015-09-07 17:24:53 +02:00
parent f11220206a
commit 6606d776f8
3 changed files with 18 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
class Flag < ActiveRecord::Base
belongs_to :user
belongs_to :flaggable, polymorphic: true, counter_cache: true
belongs_to :flaggable, polymorphic: true, counter_cache: true, touch: true
scope(:by_user_and_flaggable, lambda do |user, flaggable|
where(user_id: user.id,

View File

@@ -77,6 +77,13 @@ FactoryGirl.define do
trait :with_hot_score do
before(:save) { |d| d.calculate_hot_score }
end
trait :conflictive do
after :create do |debate|
Flag.flag(FactoryGirl.create(:user), debate)
4.times { create(:vote, votable: debate) }
end
end
end
factory :vote do
@@ -88,6 +95,11 @@ FactoryGirl.define do
end
end
factory :flag do
association :flaggable, factory: :debate
association :user, factory: :user
end
factory :comment do
association :commentable, factory: :debate
user

View File

@@ -281,6 +281,11 @@ describe Debate do
.to change { debate.updated_at }
end
it "should expire cache when it has a new flag", :focus do
expect { create(:flag, flaggable: debate) }
.to change { debate.reload.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 }