PERF: avoid checking for consecutive replies in test

PERF: avoid checking for consecutive replies in test

This check can issue up to 2 queries per post created, we have specific tests for it so we can avoid.

This also rolls back #4da6ca4d

diff --git a/config/environments/test.rb b/config/environments/test.rb
index 9186e92..e140ec5 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -63,6 +63,7 @@ Discourse::Application.configure do
       s.set_regardless_of_locale(:crawl_images, false)
       s.set_regardless_of_locale(:download_remote_images_to_local, false)
       s.set_regardless_of_locale(:unique_posts_mins, 0)
+      s.set_regardless_of_locale(:max_consecutive_replies, 0)
       # disable plugins
       if ENV['LOAD_PLUGINS'] == '1'
         s.set_regardless_of_locale(:discourse_narrative_bot_enabled, false)
diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb
index ebfd343..cdc2395 100644
--- a/spec/components/post_revisor_spec.rb
+++ b/spec/components/post_revisor_spec.rb
@@ -102,7 +102,7 @@ describe PostRevisor do
   end
 
   context 'revise' do
-    let(:post) { Fabricate(:post_with_validation, post_args) }
+    let(:post) { Fabricate(:post, post_args) }
     let(:first_version_at) { post.last_version_at }
 
     subject { PostRevisor.new(post) }
diff --git a/spec/fabricators/post_fabricator.rb b/spec/fabricators/post_fabricator.rb
index dfa1b1c..219a165 100644
--- a/spec/fabricators/post_fabricator.rb
+++ b/spec/fabricators/post_fabricator.rb
@@ -4,14 +4,9 @@ Fabricator(:post) do
   user
   topic { |attrs| Fabricate(:topic, user: attrs[:user]) }
   raw "Hello world"
-  skip_validation true
   post_type Post.types[:regular]
 end
 
-Fabricator(:post_with_validation, from: :post) do
-  skip_validation false
-end
-
 Fabricator(:post_with_long_raw_content, from: :post) do
   raw 'This is a sample post with semi-long raw content. The raw content is also more than
       two hundred characters to satisfy any test conditions that require content longer
diff --git a/spec/integration/watched_words_spec.rb b/spec/integration/watched_words_spec.rb
index 126fff6..d8d127e 100644
--- a/spec/integration/watched_words_spec.rb
+++ b/spec/integration/watched_words_spec.rb
@@ -63,7 +63,7 @@ describe WatchedWord do
     end
 
     it "blocks on revisions" do
-      post = Fabricate(:post_with_validation, topic: Fabricate(:topic, user: tl2_user), user: tl2_user)
+      post = Fabricate(:post, topic: Fabricate(:topic, user: tl2_user), user: tl2_user)
       expect {
         PostRevisor.new(post).revise!(post.user, { raw: "Want some #{block_word.word} for cheap?" }, revised_at: post.updated_at + 10.seconds)
         expect(post.errors).to be_present
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 261cc51..b6edeb6 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -57,7 +57,7 @@ describe Post do
   def post_with_body(body, user = nil)
     args = post_args.merge(raw: body)
     args[:user] = user if user.present?
-    Fabricate.build(:post_with_validation, args)
+    Fabricate.build(:post, args)
   end
 
   it { is_expected.to validate_presence_of :raw }
@@ -79,7 +79,7 @@ describe Post do
     describe '#by_newest' do
       it 'returns posts ordered by created_at desc' do
         2.times do |t|
-          Fabricate(:post_with_validation, created_at: t.seconds.from_now)
+          Fabricate(:post, created_at: t.seconds.from_now)
         end
         expect(Post.by_newest.first.created_at).to be > Post.by_newest.last.created_at
       end
@@ -87,7 +87,7 @@ describe Post do
 
     describe '#with_user' do
       it 'gives you a user' do
-        Fabricate(:post_with_validation, user: Fabricate.build(:user))
+        Fabricate(:post, user: Fabricate.build(:user))
         expect(Post.with_user.first.user).to be_a User
       end
     end
@@ -97,7 +97,7 @@ describe Post do
   describe "revisions and deleting/recovery" do
 
     context 'a post without links' do
-      let(:post) { Fabricate(:post_with_validation, post_args) }
+      let(:post) { Fabricate(:post, post_args) }
 
       before do
         post.trash!
@@ -137,7 +137,7 @@ describe Post do
 
     context 'a post with notices' do
       let(:post) {
-        post = Fabricate(:post_with_validation, post_args)
+        post = Fabricate(:post, post_args)
         post.custom_fields["notice_type"] = Post.notices[:returning_user]
         post.custom_fields["notice_args"] = 1.day.ago
         post.save_custom_fields
@@ -155,7 +155,7 @@ describe Post do
   end
 
   describe 'flagging helpers' do
-    fab!(:post) { Fabricate(:post_with_validation) }
+    fab!(:post) { Fabricate(:post) }
     fab!(:user) { Fabricate(:coding_horror) }
     fab!(:admin) { Fabricate(:admin) }
 
@@ -198,7 +198,7 @@ describe Post do
 
   describe "maximum images" do
     fab!(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
-    let(:post_no_images) { Fabricate.build(:post_with_validation, post_args.merge(user: newuser)) }
+    let(:post_no_images) { Fabricate.build(:post, post_args.merge(user: newuser)) }
     let(:post_one_image) { post_with_body("![sherlock](http://bbc.co.uk/sherlock.jpg)", newuser) }
     let(:post_two_images) { post_with_body("<img src='http://discourse.org/logo.png'> <img src='http://bbc.co.uk/sherlock.jpg'>", newuser) }
     let(:post_with_avatars) { post_with_body('<img alt="smiley" title=":smiley:" src="/assets/emoji/smiley.png" class="avatar"> <img alt="wink" title=":wink:" src="/assets/emoji/wink.png" class="avatar">', newuser) }
@@ -210,7 +210,7 @@ describe Post do
     let(:post_with_two_classy_images) { post_with_body("<img src='http://discourse.org/logo.png' class='classy'> <img src='http://bbc.co.uk/sherlock.jpg' class='classy'>", newuser) }
 
     it "returns 0 images for an empty post" do
-      expect(Fabricate.build(:post_with_validation).image_count).to eq(0)
+      expect(Fabricate.build(:post).image_count).to eq(0)
     end
 
     it "finds images from markdown" do
@@ -312,12 +312,12 @@ describe Post do
 
   describe "maximum attachments" do
     fab!(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
-    let(:post_no_attachments) { Fabricate.build(:post_with_validation, post_args.merge(user: newuser)) }
+    let(:post_no_attachments) { Fabricate.build(:post, post_args.merge(user: newuser)) }
     let(:post_one_attachment) { post_with_body('<a class="attachment" href="/uploads/default/1/2082985.txt">file.txt</a>', newuser) }
     let(:post_two_attachments) { post_with_body('<a class="attachment" href="/uploads/default/2/20947092.log">errors.log</a> <a class="attachment" href="/uploads/default/3/283572385.3ds">model.3ds</a>', newuser) }
 
     it "returns 0 attachments for an empty post" do
-      expect(Fabricate.build(:post_with_validation).attachment_count).to eq(0)
+      expect(Fabricate.build(:post).attachment_count).to eq(0)
     end
 
     it "finds attachments from HTML" do
@@ -431,7 +431,7 @@ describe Post do
     let(:post_with_mentions) { post_with_body("hello @#{newuser.username} how are you doing?", newuser) }
 
     it "returns 0 links for an empty post" do
-      expect(Fabricate.build(:post_with_validation).link_count).to eq(0)
+      expect(Fabricate.build(:post).link_count).to eq(0)
     end
 
     it "returns 0 links for a post with mentions" do
@@ -503,44 +503,44 @@ describe Post do
     context 'raw_mentions' do
 
       it "returns an empty array with no matches" do
-        post = Fabricate.build(:post_with_validation, post_args.merge(raw: "Hello Jake and Finn!"))
+        post = Fabricate.build(:post, post_args.merge(raw: "Hello Jake and Finn!"))
         expect(post.raw_mentions).to eq([])
       end
 
       it "returns lowercase unique versions of the mentions" do
-        post = Fabricate.build(:post_with_validation, post_args.merge(raw: "@Jake @Finn @Jake"))
+        post = Fabricate.build(:post, post_args.merge(raw: "@Jake @Finn @Jake"))
         expect(post.raw_mentions).to eq(['jake', 'finn'])
       end
 
       it "ignores pre" do
         # we need to force an inline
-        post = Fabricate.build(:post_with_validation, post_args.merge(raw: "p <pre>@Jake</pre> @Finn"))

[... diff too long, it was truncated ...]

GitHub sha: 88650a12

1 Like