FIX: Fixed tests. (#6716)

FIX: Fixed tests. (#6716)

From 1a4676c6e0fff7cba60fc806d04150a848af5595 Mon Sep 17 00:00:00 2001
From: Bianca Nenciu <nbianca@users.noreply.github.com>
Date: Mon, 3 Dec 2018 18:03:11 +0200
Subject: [PATCH] FIX: Fixed tests. (#6716)


diff --git a/spec/components/validators/post_validator_spec.rb b/spec/components/validators/post_validator_spec.rb
index de1df04..f368daf 100644
--- a/spec/components/validators/post_validator_spec.rb
+++ b/spec/components/validators/post_validator_spec.rb
@@ -229,25 +229,23 @@ describe Validators::PostValidator do
       SiteSetting.max_consecutive_replies = 2
     end
 
-    it "should always allow posting" do
+    it "should always allow original poster to post" 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}")
+        post = Post.new(user: u, topic: topic, raw: "post number #{i}")
         validator.force_edit_last_validator(post)
         expect(post.errors.count).to eq(0)
-        post.save
+        post.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")
-      post.save
+      Post.create(user: other_user, topic: topic, raw: "post number 0")
+      Post.create(user: user, topic: topic, raw: "post number 1")
+      Post.create(user: user, topic: topic, raw: "post number 2")
 
-      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
+      post = Post.new(user: user, topic: topic, raw: "post number 3")
+      validator.force_edit_last_validator(post)
+      expect(post.errors.count).to eq(1)
     end
 
     it "should always allow editing" do

GitHub

1 Like