diff --git a/spec/chewy/instances_index_spec.rb b/spec/chewy/instances_index_spec.rb new file mode 100644 index 0000000000..afd5b70a69 --- /dev/null +++ b/spec/chewy/instances_index_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe InstancesIndex do + context 'when elasticsearch is enabled', :search do + describe 'indexing records' do + before do + Fabricate :account, domain: 'host.example' + Instance.refresh + end + + it 'indexes records from scope' do + expect { described_class.import } + .to change(described_class, :count).by(1) + end + end + end + + describe 'Searching the index' do + before do + mock_elasticsearch_response(described_class, raw_response) + end + + it 'returns results from a query' do + results = described_class.query(match: { name: 'account' }) + + expect(results).to eq [] + end + end + + def raw_response + { + took: 3, + hits: { + hits: [ + { + _id: '0', + _score: 1.6375021, + }, + ], + }, + } + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 48a3268bf0..31487cc3ef 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -138,12 +138,6 @@ RSpec.configure do |config| example.run end - config.around(:each, type: :search) do |example| - Chewy.settings[:enabled] = true - example.run - Chewy.settings[:enabled] = false - end - config.before :each, type: :cli do stub_reset_connection_pools end diff --git a/spec/support/search.rb b/spec/support/search.rb index adf99caf9e..159068c1c5 100644 --- a/spec/support/search.rb +++ b/spec/support/search.rb @@ -20,6 +20,7 @@ RSpec.configure do |config| def search_indices [ AccountsIndex, + InstancesIndex, PublicStatusesIndex, StatusesIndex, TagsIndex, diff --git a/spec/workers/scheduler/instance_refresh_scheduler_spec.rb b/spec/workers/scheduler/instance_refresh_scheduler_spec.rb index 37682ebb8f..8ddeffa12e 100644 --- a/spec/workers/scheduler/instance_refresh_scheduler_spec.rb +++ b/spec/workers/scheduler/instance_refresh_scheduler_spec.rb @@ -7,7 +7,17 @@ RSpec.describe Scheduler::InstanceRefreshScheduler do describe 'perform' do it 'runs without error' do - expect { worker.perform }.to_not raise_error + expect { worker.perform } + .to_not raise_error + end + end + + context 'with elasticsearch enabled', :search do + before { Fabricate :remote_account } + + it 'updates search indexes' do + expect { worker.perform } + .to change(InstancesIndex, :count).by(1) end end end