Skip to content
Permalink
Browse files

FEATURE: Do not check consecutive replies for original poster. (#6714)

  • Loading branch information...
nbianca authored and coding-horror committed Dec 3, 2018
1 parent 142361d commit 3f8fa4ad4e6e27070b213d52618fd66054ab71fb
Showing with 13 additions and 0 deletions.
  1. +1 −0 lib/validators/post_validator.rb
  2. +12 −0 spec/components/validators/post_validator_spec.rb
@@ -146,6 +146,7 @@ def force_edit_last_validator(post)
return if SiteSetting.max_consecutive_replies == 0 || post.id || post.acting_user&.staff? || private_message?(post)

topic = post.topic
return if topic.posts.first&.user == post.user

last_posts_count = DB.query_single(<<~SQL, topic_id: post.topic_id, user_id: post.acting_user.id, max_replies: SiteSetting.max_consecutive_replies).first
SELECT COUNT(*)
@@ -229,7 +229,19 @@
SiteSetting.max_consecutive_replies = 2
end

it "should always allow posting" do
[user, user, user, other_user, user, user, user].each_with_index do |u, i|
post = Post.new(user: user, topic: topic, raw: "post number #{i}")

This comment has been minimized.

Copy link
@tgxworld

tgxworld Dec 3, 2018

Member

This test doesn't look right, it is always create a post with user instead of u

validator.force_edit_last_validator(post)
expect(post.errors.count).to eq(0)
post.save

This comment has been minimized.

Copy link
@tgxworld

tgxworld Dec 3, 2018

Member

post.save! will be better since we will immediately know what went wrong if the post fails to save.

end
end

it "should not allow posting more than 2 consecutive replies" do
post = Post.new(user: other_user, topic: topic, raw: "post number 0")

This comment has been minimized.

Copy link
@tgxworld

tgxworld Dec 3, 2018

Member

You can use Post.create so that you don't have to call Post.new(...).save

post.save

1.upto(3).each do |i|
post = Post.new(user: user, topic: topic, raw: "post number #{i}")
validator.force_edit_last_validator(post)

1 comment on commit 3f8fa4a

@discoursebot

This comment has been minimized.

Copy link

commented on 3f8fa4a Dec 3, 2018

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/nomethoderror-in-force-edit-last-validator/103378/1

Please sign in to comment.
You can’t perform that action at this time.