Configure elastic search integration with rspec tag (#27882)
This commit is contained in:
parent
297839c10c
commit
e892efbc40
|
@ -227,7 +227,7 @@ jobs:
|
||||||
path: tmp/screenshots/
|
path: tmp/screenshots/
|
||||||
|
|
||||||
test-search:
|
test-search:
|
||||||
name: Testing search
|
name: Elastic Search integration testing
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
needs:
|
needs:
|
||||||
|
@ -314,7 +314,7 @@ jobs:
|
||||||
- name: Load database schema
|
- name: Load database schema
|
||||||
run: './bin/rails db:create db:schema:load db:seed'
|
run: './bin/rails db:create db:schema:load db:seed'
|
||||||
|
|
||||||
- run: bundle exec rake spec:search
|
- run: bin/rspec --tag search
|
||||||
|
|
||||||
- name: Archive logs
|
- name: Archive logs
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
|
|
|
@ -9,13 +9,3 @@ if Rake::Task.task_defined?('spec:system')
|
||||||
|
|
||||||
Rake::Task['spec:system'].enhance ['spec:enable_system_specs']
|
Rake::Task['spec:system'].enhance ['spec:enable_system_specs']
|
||||||
end
|
end
|
||||||
|
|
||||||
if Rake::Task.task_defined?('spec:search')
|
|
||||||
namespace :spec do
|
|
||||||
task :enable_search_specs do # rubocop:disable Rails/RakeEnvironment
|
|
||||||
ENV['RUN_SEARCH_SPECS'] = 'true'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Rake::Task['spec:search'].enhance ['spec:enable_search_specs']
|
|
||||||
end
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ ENV['RAILS_ENV'] ||= 'test'
|
||||||
|
|
||||||
# This needs to be defined before Rails is initialized
|
# This needs to be defined before Rails is initialized
|
||||||
RUN_SYSTEM_SPECS = ENV.fetch('RUN_SYSTEM_SPECS', false)
|
RUN_SYSTEM_SPECS = ENV.fetch('RUN_SYSTEM_SPECS', false)
|
||||||
RUN_SEARCH_SPECS = ENV.fetch('RUN_SEARCH_SPECS', false)
|
|
||||||
|
|
||||||
if RUN_SYSTEM_SPECS
|
if RUN_SYSTEM_SPECS
|
||||||
STREAMING_PORT = ENV.fetch('TEST_STREAMING_PORT', '4020')
|
STREAMING_PORT = ENV.fetch('TEST_STREAMING_PORT', '4020')
|
||||||
|
@ -55,20 +54,28 @@ RSpec.configure do |config|
|
||||||
case type
|
case type
|
||||||
when :system
|
when :system
|
||||||
!RUN_SYSTEM_SPECS
|
!RUN_SYSTEM_SPECS
|
||||||
when :search
|
|
||||||
!RUN_SEARCH_SPECS
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# By default, skip the elastic search integration specs
|
||||||
|
config.filter_run_excluding search: true
|
||||||
|
|
||||||
config.fixture_path = Rails.root.join('spec', 'fixtures')
|
config.fixture_path = Rails.root.join('spec', 'fixtures')
|
||||||
config.use_transactional_fixtures = true
|
config.use_transactional_fixtures = true
|
||||||
config.order = 'random'
|
config.order = 'random'
|
||||||
config.infer_spec_type_from_file_location!
|
config.infer_spec_type_from_file_location!
|
||||||
config.filter_rails_from_backtrace!
|
config.filter_rails_from_backtrace!
|
||||||
|
|
||||||
|
# Set type to `cli` for all CLI specs
|
||||||
config.define_derived_metadata(file_path: Regexp.new('spec/lib/mastodon/cli')) do |metadata|
|
config.define_derived_metadata(file_path: Regexp.new('spec/lib/mastodon/cli')) do |metadata|
|
||||||
metadata[:type] = :cli
|
metadata[:type] = :cli
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set `search` metadata true for all specs in spec/search/
|
||||||
|
config.define_derived_metadata(file_path: Regexp.new('spec/search/*')) do |metadata|
|
||||||
|
metadata[:search] = true
|
||||||
|
end
|
||||||
|
|
||||||
config.include Devise::Test::ControllerHelpers, type: :controller
|
config.include Devise::Test::ControllerHelpers, type: :controller
|
||||||
config.include Devise::Test::ControllerHelpers, type: :helper
|
config.include Devise::Test::ControllerHelpers, type: :helper
|
||||||
config.include Devise::Test::ControllerHelpers, type: :view
|
config.include Devise::Test::ControllerHelpers, type: :view
|
||||||
|
|
|
@ -60,7 +60,7 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
config.around :each, type: :search do |example|
|
config.around :each, :search do |example|
|
||||||
search_data_manager.populate_indexes
|
search_data_manager.populate_indexes
|
||||||
example.run
|
example.run
|
||||||
search_data_manager.remove_indexes
|
search_data_manager.remove_indexes
|
||||||
|
@ -73,6 +73,6 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_examples_present?
|
def search_examples_present?
|
||||||
RUN_SEARCH_SPECS
|
RSpec.world.filtered_examples.values.flatten.any? { |example| example.metadata[:search] == true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue