2018-06-03 15:24:35 +00:00
|
|
|
require 'rake'
|
|
|
|
|
2019-07-04 13:23:58 +00:00
|
|
|
# if you make changes, then please also change this file 'spec/support/searchindex_backend.rb'
|
|
|
|
# this is required as long as our test suite is made of RSpec and MiniTest
|
2018-06-03 15:24:35 +00:00
|
|
|
module SearchindexHelper
|
|
|
|
|
|
|
|
def self.included(base)
|
|
|
|
|
|
|
|
base.teardown do
|
|
|
|
next if ENV['ES_URL'].blank?
|
|
|
|
|
|
|
|
Rake::Task['searchindex:drop'].execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure_elasticsearch(required: false)
|
|
|
|
if ENV['ES_URL'].blank?
|
|
|
|
return if !required
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-03 15:24:35 +00:00
|
|
|
raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
|
|
|
end
|
|
|
|
|
|
|
|
Setting.set('es_url', ENV['ES_URL'])
|
|
|
|
|
|
|
|
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
|
|
|
# Setting.set('es_index', 'estest.local_zammad')
|
|
|
|
# Setting.set('es_user', 'elasticsearch')
|
|
|
|
# Setting.set('es_password', 'zammad')
|
|
|
|
|
|
|
|
if ENV['ES_INDEX_RAND'].present?
|
2018-06-22 12:23:23 +00:00
|
|
|
rand_id = ENV.fetch('CI_JOB_ID', "r#{rand(999)}")
|
|
|
|
test_method_name = method_name.gsub(/[^\w]/, '_')
|
|
|
|
ENV['ES_INDEX'] = "es_index_#{test_method_name}_#{rand_id}_#{rand(999_999_999)}"
|
2018-06-03 15:24:35 +00:00
|
|
|
end
|
|
|
|
if ENV['ES_INDEX'].blank?
|
|
|
|
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-03 15:24:35 +00:00
|
|
|
Setting.set('es_index', ENV['ES_INDEX'])
|
|
|
|
|
|
|
|
# set max attachment size in mb
|
|
|
|
Setting.set('es_attachment_max_size_in_mb', 1)
|
|
|
|
|
|
|
|
yield if block_given?
|
|
|
|
end
|
|
|
|
|
|
|
|
def rebuild_searchindex
|
|
|
|
Rake::Task.clear
|
|
|
|
Zammad::Application.load_tasks
|
2018-07-16 05:39:24 +00:00
|
|
|
Rake::Task['searchindex:rebuild'].execute
|
2018-06-03 15:24:35 +00:00
|
|
|
end
|
2018-06-22 12:23:23 +00:00
|
|
|
|
2018-06-03 15:24:35 +00:00
|
|
|
end
|