FIX: should not count disagreed flags

This commit is contained in:
Régis Hanol 2015-02-19 18:11:07 +01:00
parent b2197a754f
commit e74b9ee5da
2 changed files with 56 additions and 32 deletions

View File

@ -683,6 +683,39 @@ class User < ActiveRecord::Base
end
end
def number_of_deleted_posts
Post.with_deleted
.where(user_id: self.id)
.where(user_deleted: false)
.where.not(deleted_by_id: self.id)
.where.not(deleted_at: nil)
.count
end
def number_of_flagged_posts
Post.with_deleted
.where(user_id: self.id)
.where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids)
.where(disagreed_at: nil)
.select(:post_id))
.count
end
def number_of_flags_given
PostAction.where(user_id: self.id)
.where(disagreed_at: nil)
.where(post_action_type_id: PostActionType.notify_flag_type_ids)
.count
end
def number_of_warnings
self.warnings.count
end
def number_of_suspensions
UserHistory.for(self, :suspend_user).count
end
protected
def badge_grant
@ -818,38 +851,6 @@ class User < ActiveRecord::Base
end
end
def number_of_deleted_posts
Post.with_deleted
.where(user_id: self.id)
.where(user_deleted: false)
.where.not(deleted_by_id: self.id)
.where.not(deleted_at: nil)
.count
end
def number_of_flagged_posts
Post.with_deleted
.where(user_id: self.id)
.where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids)
.where(disagreed_at: nil)
.select(:post_id))
.count
end
def number_of_flags_given
PostAction.where(user_id: self.id)
.where(post_action_type_id: PostActionType.notify_flag_type_ids)
.count
end
def number_of_warnings
self.warnings.count
end
def number_of_suspensions
UserHistory.for(self, :suspend_user).count
end
private
def previous_visit_at_update_required?(timestamp)

View File

@ -1219,4 +1219,27 @@ describe User do
end
describe "number_of_flags_given" do
let(:user) { Fabricate(:user) }
let(:moderator) { Fabricate(:moderator) }
it "doesn't count disagreed flags" do
post_agreed = Fabricate(:post)
PostAction.act(user, post_agreed, PostActionType.types[:off_topic])
PostAction.agree_flags!(post_agreed, moderator)
post_deferred = Fabricate(:post)
PostAction.act(user, post_deferred, PostActionType.types[:inappropriate])
PostAction.defer_flags!(post_deferred, moderator)
post_disagreed = Fabricate(:post)
PostAction.act(user, post_disagreed, PostActionType.types[:spam])
PostAction.clear_flags!(post_disagreed, moderator)
expect(user.number_of_flags_given).to eq(2)
end
end
end