mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 23:35:53 +08:00
FIX: update_counters wasn't properly updating topic counters
This commit is contained in:
parent
380411457a
commit
57fef6864d
@ -331,7 +331,8 @@ class PostAction < ActiveRecord::Base
|
||||
end
|
||||
|
||||
topic_id = Post.with_deleted.where(id: post_id).pluck(:topic_id).first
|
||||
Topic.where(id: topic_id).update_all ["#{column} = ?", count]
|
||||
topic_count = Post.where(topic_id: topic_id).sum(column)
|
||||
Topic.where(id: topic_id).update_all ["#{column} = ?", topic_count]
|
||||
|
||||
if PostActionType.notify_flag_type_ids.include?(post_action_type_id)
|
||||
PostAction.update_flagged_posts_count
|
||||
|
@ -10,6 +10,7 @@ describe PostAction do
|
||||
let(:moderator) { Fabricate(:moderator) }
|
||||
let(:codinghorror) { Fabricate(:coding_horror) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:second_post) { Fabricate(:post, topic_id: post.topic_id) }
|
||||
let(:bookmark) { PostAction.new(user_id: post.user_id, post_action_type_id: PostActionType.types[:bookmark] , post_id: post.id) }
|
||||
|
||||
describe "messaging" do
|
||||
@ -115,6 +116,17 @@ describe PostAction do
|
||||
|
||||
end
|
||||
|
||||
describe "update_counters" do
|
||||
|
||||
it "properly updates topic counters" do
|
||||
PostAction.act(moderator, post, PostActionType.types[:like])
|
||||
PostAction.act(codinghorror, second_post, PostActionType.types[:like])
|
||||
post.topic.reload
|
||||
post.topic.like_count.should == 2
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "when a user bookmarks something" do
|
||||
it "increases the post's bookmark count when saved" do
|
||||
lambda { bookmark.save; post.reload }.should change(post, :bookmark_count).by(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user