FEATURE: Add new setting to force user edit last post. (#6571)

This commit is contained in:
Bianca Nenciu
2018-11-14 16:48:16 +02:00
committed by Régis Hanol
parent d003ae45f9
commit b6576d9473
4 changed files with 72 additions and 0 deletions

View File

@ -219,6 +219,43 @@ describe Validators::PostValidator do
end
end
context "force_edit_last_validator" do
let(:user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
before do
SiteSetting.max_consecutive_replies = 2
end
it "should not allow posting more than 2 consecutive replies" do
1.upto(3).each do |i|
post = Post.new(user: user, topic: topic, raw: "post number #{i}")
validator.force_edit_last_validator(post)
expect(post.errors.count).to eq(i > SiteSetting.max_consecutive_replies ? 1 : 0)
post.save
end
end
it "should always allow editing" do
post = Fabricate(:post, user: user, topic: topic)
post = Fabricate(:post, user: user, topic: topic)
revisor = PostRevisor.new(post)
revisor.revise!(post.user, raw: 'hello world123456789')
end
it "should allow posting more than 2 replies" do
3.times do
post = Fabricate(:post, user: user, topic: topic)
Fabricate(:post, user: other_user, topic: topic)
validator.force_edit_last_validator(post)
expect(post.errors.count).to eq(0)
end
end
end
shared_examples "almost no validations" do
it "skips most validations" do
validator.expects(:stripped_length).never
@ -229,6 +266,7 @@ describe Validators::PostValidator do
validator.expects(:max_attachments_validator).never
validator.expects(:newuser_links_validator).never
validator.expects(:unique_post_validator).never
validator.expects(:force_edit_last_validator).never
validator.validate(post)
end
end