From f14506031520a3b8ab83aa25ee576d0c1b515ff9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 2 Jan 2014 12:57:40 -0500 Subject: [PATCH] Don't employ the "too many replies" if the user is staff, or if they created the topic. See: http://meta.discourse.org/t/what-is-the-point-of-limiting-new-users-to-three-replies-per-topic/11696 --- app/models/user.rb | 4 ++++ spec/models/user_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 6cee6fb91bb..c4eb54a9046 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -354,6 +354,10 @@ class User < ActiveRecord::Base end def posted_too_much_in_topic?(topic_id) + + # Does not apply to staff or your own topics + return false if staff? || Topic.where(id: topic_id, user_id: id).exists? + trust_level == TrustLevel.levels[:newuser] && (Post.where(topic_id: topic_id, user_id: id).count >= SiteSetting.newuser_max_replies_per_topic) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index baebd4898b6..3d9b81521df 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -903,6 +903,36 @@ describe User do end + describe "posted too much in topic" do + let!(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) } + let!(:topic) { Fabricate(:post).topic } + + before do + # To make testing easier, say 1 reply is too much + SiteSetting.stubs(:newuser_max_replies_per_topic).returns(1) + end + + context "for a user who didn't create the topic" do + let!(:post) { Fabricate(:post, topic: topic, user: user) } + + it "does not return true for staff" do + user.stubs(:staff?).returns(true) + user.posted_too_much_in_topic?(topic.id).should be_false + end + + it "returns true when the user has posted too much" do + user.posted_too_much_in_topic?(topic.id).should be_true + end + end + + it "returns false for a user who created the topic" do + topic_user = topic.user + topic_user.trust_level = TrustLevel.levels[:newuser] + topic.user.posted_too_much_in_topic?(topic.id).should be_false + end + + end + describe "#find_email" do let(:user) { Fabricate(:user, email: "bob@example.com") }