expires debate cache after a new flag
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user