Add InstancesIndex coverage (#38129)

This commit is contained in:
Matt Jankowski
2026-03-10 10:45:17 -04:00
committed by GitHub
parent c6322d8007
commit f6ea52e822
4 changed files with 57 additions and 7 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -20,6 +20,7 @@ RSpec.configure do |config|
def search_indices
[
AccountsIndex,
InstancesIndex,
PublicStatusesIndex,
StatusesIndex,
TagsIndex,

View File

@@ -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