FIX: when blocking a user results in hiding their posts, only hide posts made in the last 24 hours
This commit is contained in:
parent
99f9adaf50
commit
6b93b09404
|
@ -31,8 +31,8 @@ class UserBlocker
|
|||
def hide_posts
|
||||
return unless @user.trust_level == TrustLevel[0]
|
||||
|
||||
Post.where(user_id: @user.id).update_all(["hidden = true, hidden_reason_id = COALESCE(hidden_reason_id, ?)", Post.hidden_reasons[:new_user_spam_threshold_reached]])
|
||||
topic_ids = Post.where(user_id: @user.id, post_number: 1).pluck(:topic_id)
|
||||
Post.where(user_id: @user.id).where("created_at > ?", 24.hours.ago).update_all(["hidden = true, hidden_reason_id = COALESCE(hidden_reason_id, ?)", Post.hidden_reasons[:new_user_spam_threshold_reached]])
|
||||
topic_ids = Post.where(user_id: @user.id, post_number: 1).where("created_at > ?", 24.hours.ago).pluck(:topic_id)
|
||||
Topic.where(id: topic_ids).update_all(visible: false) unless topic_ids.empty?
|
||||
end
|
||||
|
||||
|
|
|
@ -118,6 +118,16 @@ describe UserBlocker do
|
|||
expect(post.reload).to_not be_hidden
|
||||
expect(post.topic.reload).to be_visible
|
||||
end
|
||||
|
||||
it "only hides posts from the past 24 hours" do
|
||||
old_post = Fabricate(:post, user: user, created_at: 2.days.ago)
|
||||
subject.block
|
||||
expect(post.reload).to be_hidden
|
||||
expect(post.topic.reload).to_not be_visible
|
||||
old_post.reload
|
||||
expect(old_post).to_not be_hidden
|
||||
expect(old_post.topic).to be_visible
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue