FIX: Users can edit posts when they've reached the `newuser_max_replies_per_topic` threshold.

This commit is contained in:
Robin Ward 2013-12-20 11:29:44 -05:00
parent 12f89aef95
commit 0c45eba037
2 changed files with 8 additions and 1 deletions

View File

@ -42,7 +42,7 @@ class Validators::PostValidator < ActiveModel::Validator
end
def max_posts_validator(post)
if post.acting_user.present? && post.acting_user.posted_too_much_in_topic?(post.topic_id)
if post.new_record? && post.acting_user.present? && post.acting_user.posted_too_much_in_topic?(post.topic_id)
post.errors.add(:base, I18n.t(:too_many_replies))
end
end

View File

@ -31,6 +31,13 @@ describe Validators::PostValidator do
expect(post.errors.count).to be > 0
end
it "should be allowed to edit when the user has posted too much" do
post.user.stubs(:posted_too_much_in_topic?).returns(true)
post.expects(:new_record?).returns(false)
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)