diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index 5c5dab1efb0..184f0235792 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -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 diff --git a/spec/components/validators/post_validator_spec.rb b/spec/components/validators/post_validator_spec.rb index e1a5ed725ea..28484400f9f 100644 --- a/spec/components/validators/post_validator_spec.rb +++ b/spec/components/validators/post_validator_spec.rb @@ -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)