From 0c45eba037c900b78e5e8c09dcd50e8e997a4337 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 20 Dec 2013 11:29:44 -0500 Subject: [PATCH] FIX: Users can edit posts when they've reached the `newuser_max_replies_per_topic` threshold. --- lib/validators/post_validator.rb | 2 +- spec/components/validators/post_validator_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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)