Add InstancesIndex coverage (#38129)
This commit is contained in:
parent
c6322d8007
commit
f6ea52e822
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
|
example.run
|
||||||
end
|
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
|
config.before :each, type: :cli do
|
||||||
stub_reset_connection_pools
|
stub_reset_connection_pools
|
||||||
end
|
end
|
||||||
|
|||||||
@ -20,6 +20,7 @@ RSpec.configure do |config|
|
|||||||
def search_indices
|
def search_indices
|
||||||
[
|
[
|
||||||
AccountsIndex,
|
AccountsIndex,
|
||||||
|
InstancesIndex,
|
||||||
PublicStatusesIndex,
|
PublicStatusesIndex,
|
||||||
StatusesIndex,
|
StatusesIndex,
|
||||||
TagsIndex,
|
TagsIndex,
|
||||||
|
|||||||
@ -7,7 +7,17 @@ RSpec.describe Scheduler::InstanceRefreshScheduler do
|
|||||||
|
|
||||||
describe 'perform' do
|
describe 'perform' do
|
||||||
it 'runs without error' 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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user