mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add basic ES-enabled index/service coverage (#38097)
This commit is contained in:
@@ -3,6 +3,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
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
|
||||
before do
|
||||
mock_elasticsearch_response(described_class, raw_response)
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
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
|
||||
before do
|
||||
mock_elasticsearch_response(described_class, raw_response)
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
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
|
||||
before do
|
||||
mock_elasticsearch_response(described_class, raw_response)
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
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
|
||||
before do
|
||||
mock_elasticsearch_response(described_class, raw_response)
|
||||
|
||||
@@ -86,4 +86,16 @@ RSpec.describe AccountSearchService do
|
||||
expect(results).to eq []
|
||||
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
|
||||
|
||||
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
|
||||
describe '#call' do
|
||||
let!(:one) { Fabricate(:tag, name: 'one') }
|
||||
let(:results) { subject.call('#one', limit: 5) }
|
||||
|
||||
before { Fabricate(:tag, name: 'two') }
|
||||
|
||||
it 'runs a search for tags' do
|
||||
results = subject.call('#one', limit: 5)
|
||||
context 'with postgres search' do
|
||||
it 'runs a search for tags' do
|
||||
expect(results)
|
||||
.to have_attributes(
|
||||
size: 1,
|
||||
first: eq(one)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
expect(results)
|
||||
.to have_attributes(
|
||||
size: 1,
|
||||
first: eq(one)
|
||||
)
|
||||
context 'when elasticsearch is enabled', :search do
|
||||
it 'runs a search for tags' do
|
||||
expect(results)
|
||||
.to have_attributes(
|
||||
size: 1,
|
||||
first: eq(one)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user