A platform for community discussion. Free, open, simple.
DEV: Disable SearchIndexer after fabrication (#21378)
Alan Guo Xiang Tanafc1611be72e
diff --git a/spec/jobs/create_recent_post_search_indexes_spec.rb b/spec/jobs/create_recent_post_search_indexes_spec.rbindex 1d350d254b4..5c5f85dfda3 100644--- a/spec/jobs/create_recent_post_search_indexes_spec.rb+++ b/spec/jobs/create_recent_post_search_indexes_spec.rb@@ -3,15 +3,8 @@RSpec.describe Jobs::CreateRecentPostSearchIndexes dosubject { described_class.new }- fab!(:post) do- SearchIndexer.enable- Fabricate(:post)- end-- fab!(:post_2) do- SearchIndexer.enable- Fabricate(:post)- end+ fab!(:post) { with_search_indexer_enabled { Fabricate(:post) } }+ fab!(:post_2) { with_search_indexer_enabled { Fabricate(:post) } }before { SearchIndexer.enable }diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex 2304fae1fd5..1bc71fa6334 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -653,8 +653,9 @@ RSpec.describe Topic docontext "with a similar topic" dofab!(:post) do- SearchIndexer.enable- create_post(title: "Evil trout is the dude who posted this topic")+ with_search_indexer_enabled do+ create_post(title: "Evil trout is the dude who posted this topic")+ endendlet(:topic) { post.topic }diff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rbindex 5b33b77ea3d..a5ad01a0566 100644--- a/spec/requests/search_controller_spec.rb+++ b/spec/requests/search_controller_spec.rb@@ -10,20 +10,19 @@ RSpec.describe SearchController doendfab!(:awesome_post) do- SearchIndexer.enable- Fabricate(:post, topic: awesome_topic, raw: "this is my really awesome post")+ with_search_indexer_enabled do+ Fabricate(:post, topic: awesome_topic, raw: "this is my really awesome post")+ endendfab!(:awesome_post_2) do- SearchIndexer.enable- Fabricate(:post, raw: "this is my really awesome post 2")+ with_search_indexer_enabled { Fabricate(:post, raw: "this is my really awesome post 2") }end- fab!(:user) { Fabricate(:user) }+ fab!(:user) { with_search_indexer_enabled { Fabricate(:user) } }fab!(:user_post) do- SearchIndexer.enable- Fabricate(:post, raw: "#{user.username} is a cool person")+ with_search_indexer_enabled { Fabricate(:post, raw: "#{user.username} is a cool person") }endcontext "with integration" do@@ -470,35 +469,37 @@ RSpec.describe SearchController dofab!(:very_high_priority_topic) { Fabricate(:topic, category: very_high_priority_category) }fab!(:very_low_priority_post) do- SearchIndexer.enable- Fabricate(:post, topic: very_low_priority_topic, raw: "This is a very Low Priority Post")+ with_search_indexer_enabled do+ Fabricate(:post, topic: very_low_priority_topic, raw: "This is a very Low Priority Post")+ endendfab!(:low_priority_post) do- SearchIndexer.enable-- Fabricate(- :post,- topic: low_priority_topic,- raw: "This is a Low Priority Post",- created_at: 1.day.ago,- )+ with_search_indexer_enabled do+ Fabricate(+ :post,+ topic: low_priority_topic,+ raw: "This is a Low Priority Post",+ created_at: 1.day.ago,+ )+ endendfab!(:high_priority_post) do- SearchIndexer.enable- Fabricate(:post, topic: high_priority_topic, raw: "This is a High Priority Post")+ with_search_indexer_enabled do+ Fabricate(:post, topic: high_priority_topic, raw: "This is a High Priority Post")+ endendfab!(:very_high_priority_post) do- SearchIndexer.enable-- Fabricate(- :post,- topic: very_high_priority_topic,- raw: "This is a Old but Very High Priority Post",- created_at: 2.days.ago,- )+ with_search_indexer_enabled do+ Fabricate(+ :post,+ topic: very_high_priority_topic,+ raw: "This is a Old but Very High Priority Post",+ created_at: 2.days.ago,+ )+ endendit "sort posts with search priority when search term is empty" dodiff --git a/spec/requests/similar_topics_controller_spec.rb b/spec/requests/similar_topics_controller_spec.rbindex b70b90c2742..f71c39cd36c 100644--- a/spec/requests/similar_topics_controller_spec.rb+++ b/spec/requests/similar_topics_controller_spec.rb@@ -18,8 +18,7 @@ RSpec.describe SimilarTopicsController doenddef reindex_posts- SearchIndexer.enable- Jobs::ReindexSearch.new.rebuild_posts+ with_search_indexer_enabled { Jobs::ReindexSearch.new.rebuild_posts }endit "requires a title param" dodiff --git a/spec/support/helpers.rb b/spec/support/helpers.rbindex 6cc73913d98..085a1bb0f54 100644--- a/spec/support/helpers.rb+++ b/spec/support/helpers.rb@@ -202,4 +202,11 @@ module Helpersips.map { |ip| Addrinfo.new([IPAddr.new(ip).ipv6? ? "AF_INET6" : "AF_INET", 80, nil, ip]) },)end++ def with_search_indexer_enabled+ SearchIndexer.enable+ yield+ ensure+ SearchIndexer.disable+ endenddiff --git a/spec/system/user_selector_spec.rb b/spec/system/user_selector_spec.rbindex 3ad50ec0974..689be77791e 100644--- a/spec/system/user_selector_spec.rb+++ b/spec/system/user_selector_spec.rb@@ -4,11 +4,7 @@ describe "User selector", type: :system, js: true dofab!(:topic) { Fabricate(:topic) }fab!(:post) { Fabricate(:post, topic: topic) }fab!(:current_user) { Fabricate(:admin) }-- fab!(:user) do- SearchIndexer.enable- Fabricate(:user, username: "someone")- end+ fab!(:user) { with_search_indexer_enabled { Fabricate(:user, username: "someone") } }before docurrent_user.activate