New users can only post newuser_max_replies_per_topic times per topic.

This commit is contained in:
Robin Ward
2013-12-19 13:45:55 -05:00
parent 39e711783d
commit 1cac9fa257
8 changed files with 68 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ describe ComposerMessagesFinder do
it "calls all the message finders" do
finder.expects(:check_education_message).once
finder.expects(:check_new_user_many_replies).once
finder.expects(:check_avatar_notification).once
finder.expects(:check_sequential_replies).once
finder.expects(:check_dominating_topic).once
@@ -56,6 +57,24 @@ describe ComposerMessagesFinder do
finder.check_education_message.should be_blank
end
end
end
context '.check_new_user_many_replies' do
let(:user) { Fabricate.build(:user) }
context 'replying' do
let(:finder) { ComposerMessagesFinder.new(user, composerAction: 'reply') }
it "has no message when `posted_too_much_in_topic?` is false" do
user.expects(:posted_too_much_in_topic?).returns(false)
finder.check_new_user_many_replies.should be_blank
end
it "has a message when a user has posted too much" do
user.expects(:posted_too_much_in_topic?).returns(true)
finder.check_new_user_many_replies.should be_present
end
end
end

View File

@@ -24,6 +24,20 @@ describe Validators::PostValidator do
end
end
context "too_many_posts" do
it "should be invalid when the user has posted too much" do
post.user.expects(:posted_too_much_in_topic?).returns(true)
validator.max_posts_validator(post)
expect(post.errors.count).to be > 0
end
it "should be valid when the user hasn't posted too much" do
post.user.expects(:posted_too_much_in_topic?).returns(false)
validator.max_posts_validator(post)
expect(post.errors.count).to be(0)
end
end
context "invalid post" do
it "should be invalid" do
validator.validate(post)