Skip to content

Commit

Permalink
Don't employ the "too many replies" if the user is staff, or if they …
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Jan 2, 2014
1 parent aefad6a commit f145060
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ def private_topics_count
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

Expand Down
30 changes: 30 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,36 @@

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") }
Expand Down

0 comments on commit f145060

Please sign in to comment.