|
@@ -1,5 +1,21 @@
|
|
|
|
+require 'rake'
|
|
|
|
+
|
|
|
|
+# if you make changes, then please also change this file 'test/support/searchindex_helper.rb'
|
|
|
|
+# this is required as long as our test suite is made of RSpec and MiniTest
|
|
module SearchindexBackendHelper
|
|
module SearchindexBackendHelper
|
|
|
|
|
|
|
|
+ def self.included(base)
|
|
|
|
+ # Execute in RSpec class context
|
|
|
|
+ base.class_exec do
|
|
|
|
+
|
|
|
|
+ after(:each) do
|
|
|
|
+ next if ENV['ES_URL'].blank?
|
|
|
|
+
|
|
|
|
+ Rake::Task['searchindex:drop'].execute
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+
|
|
def configure_elasticsearch(required: false)
|
|
def configure_elasticsearch(required: false)
|
|
if ENV['ES_URL'].blank?
|
|
if ENV['ES_URL'].blank?
|
|
return if !required
|
|
return if !required
|
|
@@ -16,7 +32,7 @@ module SearchindexBackendHelper
|
|
|
|
|
|
if ENV['ES_INDEX_RAND'].present?
|
|
if ENV['ES_INDEX_RAND'].present?
|
|
rand_id = ENV.fetch('CI_JOB_ID', "r#{rand(999)}")
|
|
rand_id = ENV.fetch('CI_JOB_ID', "r#{rand(999)}")
|
|
- test_method_name = subject.gsub(/[^\w]/, '_')
|
|
|
|
|
|
+ test_method_name = self.class.description.gsub(/[^\w]/, '_')
|
|
ENV['ES_INDEX'] = "es_index_#{test_method_name}_#{rand_id}_#{rand(999_999_999)}"
|
|
ENV['ES_INDEX'] = "es_index_#{test_method_name}_#{rand_id}_#{rand(999_999_999)}"
|
|
end
|
|
end
|
|
if ENV['ES_INDEX'].blank?
|
|
if ENV['ES_INDEX'].blank?
|
|
@@ -32,21 +48,11 @@ module SearchindexBackendHelper
|
|
end
|
|
end
|
|
|
|
|
|
def rebuild_searchindex
|
|
def rebuild_searchindex
|
|
|
|
+ Rake::Task.clear
|
|
|
|
+ Zammad::Application.load_tasks
|
|
Rake::Task['searchindex:rebuild'].execute
|
|
Rake::Task['searchindex:rebuild'].execute
|
|
end
|
|
end
|
|
|
|
|
|
- def self.included(base)
|
|
|
|
-
|
|
|
|
- # Execute in RSpec class context
|
|
|
|
- base.class_exec do
|
|
|
|
-
|
|
|
|
- after(:each) do
|
|
|
|
- next if ENV['ES_URL'].blank?
|
|
|
|
-
|
|
|
|
- Rake::Task['searchindex:drop'].execute
|
|
|
|
- end
|
|
|
|
- end
|
|
|
|
- end
|
|
|
|
end
|
|
end
|
|
|
|
|
|
RSpec.configure do |config|
|
|
RSpec.configure do |config|
|