mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add InstancesIndex coverage (#38129)
This commit is contained in:
45
spec/chewy/instances_index_spec.rb
Normal file
45
spec/chewy/instances_index_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -20,6 +20,7 @@ RSpec.configure do |config|
|
||||
def search_indices
|
||||
[
|
||||
AccountsIndex,
|
||||
InstancesIndex,
|
||||
PublicStatusesIndex,
|
||||
StatusesIndex,
|
||||
TagsIndex,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user