Add basic ES-enabled index/service coverage (#38097)
This commit is contained in:
parent
eb848d082a
commit
2ad0b32dd5
@ -3,6 +3,15 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe AccountsIndex do
|
RSpec.describe AccountsIndex do
|
||||||
|
context 'when elasticsearch is enabled', :search do
|
||||||
|
describe 'indexing records' do
|
||||||
|
it 'indexes records from scope' do
|
||||||
|
expect { Fabricate :account }
|
||||||
|
.to change(described_class, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'Searching the index' do
|
describe 'Searching the index' do
|
||||||
before do
|
before do
|
||||||
mock_elasticsearch_response(described_class, raw_response)
|
mock_elasticsearch_response(described_class, raw_response)
|
||||||
|
|||||||
@ -3,6 +3,15 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe PublicStatusesIndex do
|
RSpec.describe PublicStatusesIndex do
|
||||||
|
context 'when elasticsearch is enabled', :search do
|
||||||
|
describe 'indexing records' do
|
||||||
|
it 'indexes records from scope' do
|
||||||
|
expect { Fabricate :status, visibility: :public }
|
||||||
|
.to change(described_class, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'Searching the index' do
|
describe 'Searching the index' do
|
||||||
before do
|
before do
|
||||||
mock_elasticsearch_response(described_class, raw_response)
|
mock_elasticsearch_response(described_class, raw_response)
|
||||||
|
|||||||
@ -3,6 +3,15 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe StatusesIndex do
|
RSpec.describe StatusesIndex do
|
||||||
|
context 'when elasticsearch is enabled', :search do
|
||||||
|
describe 'indexing records' do
|
||||||
|
it 'indexes records from scope' do
|
||||||
|
expect { Fabricate :status }
|
||||||
|
.to change(described_class, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'Searching the index' do
|
describe 'Searching the index' do
|
||||||
before do
|
before do
|
||||||
mock_elasticsearch_response(described_class, raw_response)
|
mock_elasticsearch_response(described_class, raw_response)
|
||||||
|
|||||||
@ -3,6 +3,15 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe TagsIndex do
|
RSpec.describe TagsIndex do
|
||||||
|
context 'when elasticsearch is enabled', :search do
|
||||||
|
describe 'indexing records' do
|
||||||
|
it 'indexes records from scope' do
|
||||||
|
expect { Fabricate :tag, listable: true }
|
||||||
|
.to change(described_class, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'Searching the index' do
|
describe 'Searching the index' do
|
||||||
before do
|
before do
|
||||||
mock_elasticsearch_response(described_class, raw_response)
|
mock_elasticsearch_response(described_class, raw_response)
|
||||||
|
|||||||
@ -86,4 +86,16 @@ RSpec.describe AccountSearchService do
|
|||||||
expect(results).to eq []
|
expect(results).to eq []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when elasticsearch is enabled', :search do
|
||||||
|
it 'returns matching accounts' do
|
||||||
|
account = Fabricate(:account, username: 'matchingusername')
|
||||||
|
|
||||||
|
AccountsIndex.import!
|
||||||
|
|
||||||
|
results = subject.call('match', nil, limit: 5)
|
||||||
|
|
||||||
|
expect(results).to eq [account]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
22
spec/services/statuses_search_service_spec.rb
Normal file
22
spec/services/statuses_search_service_spec.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe StatusesSearchService do
|
||||||
|
describe '#call' do
|
||||||
|
let!(:status) { Fabricate(:status, text: 'status number one') }
|
||||||
|
let(:results) { subject.call('one', status.account, limit: 5) }
|
||||||
|
|
||||||
|
before { Fabricate(:status, text: 'status number two') }
|
||||||
|
|
||||||
|
context 'when elasticsearch is enabled', :search do
|
||||||
|
it 'runs a search for statuses' do
|
||||||
|
expect(results)
|
||||||
|
.to have_attributes(
|
||||||
|
size: 1,
|
||||||
|
first: eq(status)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -5,17 +5,28 @@ require 'rails_helper'
|
|||||||
RSpec.describe TagSearchService do
|
RSpec.describe TagSearchService do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
let!(:one) { Fabricate(:tag, name: 'one') }
|
let!(:one) { Fabricate(:tag, name: 'one') }
|
||||||
|
let(:results) { subject.call('#one', limit: 5) }
|
||||||
|
|
||||||
before { Fabricate(:tag, name: 'two') }
|
before { Fabricate(:tag, name: 'two') }
|
||||||
|
|
||||||
it 'runs a search for tags' do
|
context 'with postgres search' do
|
||||||
results = subject.call('#one', limit: 5)
|
it 'runs a search for tags' do
|
||||||
|
expect(results)
|
||||||
|
.to have_attributes(
|
||||||
|
size: 1,
|
||||||
|
first: eq(one)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
expect(results)
|
context 'when elasticsearch is enabled', :search do
|
||||||
.to have_attributes(
|
it 'runs a search for tags' do
|
||||||
size: 1,
|
expect(results)
|
||||||
first: eq(one)
|
.to have_attributes(
|
||||||
)
|
size: 1,
|
||||||
|
first: eq(one)
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user