Add new public status index (#26344)
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com> Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
96bcee66fb
commit
30c191aaa0
28 changed files with 584 additions and 87 deletions
31
spec/chewy/public_statuses_index_spec.rb
Normal file
31
spec/chewy/public_statuses_index_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PublicStatusesIndex do
|
||||
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: 'status' })
|
||||
|
||||
expect(results).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
def raw_response
|
||||
{
|
||||
took: 3,
|
||||
hits: {
|
||||
hits: [
|
||||
{
|
||||
_id: '0',
|
||||
_score: 1.6375021,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
16
spec/lib/importer/public_statuses_index_importer_spec.rb
Normal file
16
spec/lib/importer/public_statuses_index_importer_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Importer::PublicStatusesIndexImporter do
|
||||
describe 'import!' do
|
||||
let(:pool) { Concurrent::FixedThreadPool.new(5) }
|
||||
let(:importer) { described_class.new(batch_size: 123, executor: pool) }
|
||||
|
||||
before { Fabricate(:status, account: Fabricate(:account, indexable: true)) }
|
||||
|
||||
it 'indexes relevant statuses' do
|
||||
expect { importer.import! }.to update_index(PublicStatusesIndex)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,8 +9,8 @@ describe SearchQueryTransformer do
|
|||
it 'sets attributes' do
|
||||
transformer = described_class.new.apply(parser)
|
||||
|
||||
expect(transformer.should_clauses.first).to be_a(SearchQueryTransformer::TermClause)
|
||||
expect(transformer.must_clauses.first).to be_nil
|
||||
expect(transformer.should_clauses.first).to be_nil
|
||||
expect(transformer.must_clauses.first).to be_a(SearchQueryTransformer::TermClause)
|
||||
expect(transformer.must_not_clauses.first).to be_nil
|
||||
expect(transformer.filter_clauses.first).to be_nil
|
||||
end
|
||||
|
|
66
spec/models/concerns/account_statuses_search_spec.rb
Normal file
66
spec/models/concerns/account_statuses_search_spec.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountStatusesSearch do
|
||||
let(:account) { Fabricate(:account, indexable: indexable) }
|
||||
|
||||
before do
|
||||
allow(Chewy).to receive(:enabled?).and_return(true)
|
||||
end
|
||||
|
||||
describe '#enqueue_update_public_statuses_index' do
|
||||
before do
|
||||
allow(account).to receive(:enqueue_add_to_public_statuses_index)
|
||||
allow(account).to receive(:enqueue_remove_from_public_statuses_index)
|
||||
end
|
||||
|
||||
context 'when account is indexable' do
|
||||
let(:indexable) { true }
|
||||
|
||||
it 'enqueues add_to_public_statuses_index and not to remove_from_public_statuses_index' do
|
||||
account.enqueue_update_public_statuses_index
|
||||
expect(account).to have_received(:enqueue_add_to_public_statuses_index)
|
||||
expect(account).to_not have_received(:enqueue_remove_from_public_statuses_index)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not indexable' do
|
||||
let(:indexable) { false }
|
||||
|
||||
it 'enqueues remove_from_public_statuses_index and not to add_to_public_statuses_index' do
|
||||
account.enqueue_update_public_statuses_index
|
||||
expect(account).to have_received(:enqueue_remove_from_public_statuses_index)
|
||||
expect(account).to_not have_received(:enqueue_add_to_public_statuses_index)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#enqueue_add_to_public_statuses_index' do
|
||||
let(:indexable) { true }
|
||||
let(:worker) { AddToPublicStatusesIndexWorker }
|
||||
|
||||
before do
|
||||
allow(worker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
it 'enqueues AddToPublicStatusesIndexWorker' do
|
||||
account.enqueue_add_to_public_statuses_index
|
||||
expect(worker).to have_received(:perform_async).with(account.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#enqueue_remove_from_public_statuses_index' do
|
||||
let(:indexable) { false }
|
||||
let(:worker) { RemoveFromPublicStatusesIndexWorker }
|
||||
|
||||
before do
|
||||
allow(worker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
it 'enqueues RemoveFromPublicStatusesIndexWorker' do
|
||||
account.enqueue_remove_from_public_statuses_index
|
||||
expect(worker).to have_received(:perform_async).with(account.id)
|
||||
end
|
||||
end
|
||||
end
|
42
spec/workers/add_to_public_statuses_index_worker_spec.rb
Normal file
42
spec/workers/add_to_public_statuses_index_worker_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe AddToPublicStatusesIndexWorker do
|
||||
describe '#perform' do
|
||||
let(:account) { Fabricate(:account, indexable: indexable) }
|
||||
let(:account_id) { account.id }
|
||||
|
||||
before do
|
||||
allow(Account).to receive(:find).with(account_id).and_return(account) unless account.nil?
|
||||
allow(account).to receive(:add_to_public_statuses_index!) unless account.nil?
|
||||
end
|
||||
|
||||
context 'when account is indexable' do
|
||||
let(:indexable) { true }
|
||||
|
||||
it 'adds the account to the public statuses index' do
|
||||
subject.perform(account_id)
|
||||
expect(account).to have_received(:add_to_public_statuses_index!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not indexable' do
|
||||
let(:indexable) { false }
|
||||
|
||||
it 'does not add the account to public statuses index' do
|
||||
subject.perform(account_id)
|
||||
expect(account).to_not have_received(:add_to_public_statuses_index!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account does not exist' do
|
||||
let(:account) { nil }
|
||||
let(:account_id) { 999 }
|
||||
|
||||
it 'does not raise an error' do
|
||||
expect { subject.perform(account_id) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe RemoveFromPublicStatusesIndexWorker do
|
||||
describe '#perform' do
|
||||
let(:account) { Fabricate(:account, indexable: indexable) }
|
||||
let(:account_id) { account.id }
|
||||
|
||||
before do
|
||||
allow(Account).to receive(:find).with(account_id).and_return(account) unless account.nil?
|
||||
allow(account).to receive(:remove_from_public_statuses_index!) unless account.nil?
|
||||
end
|
||||
|
||||
context 'when account is not indexable' do
|
||||
let(:indexable) { false }
|
||||
|
||||
it 'removes the account from public statuses index' do
|
||||
subject.perform(account_id)
|
||||
expect(account).to have_received(:remove_from_public_statuses_index!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is indexable' do
|
||||
let(:indexable) { true }
|
||||
|
||||
it 'does not remove the account from public statuses index' do
|
||||
subject.perform(account_id)
|
||||
expect(account).to_not have_received(:remove_from_public_statuses_index!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account does not exist' do
|
||||
let(:account) { nil }
|
||||
let(:account_id) { 999 }
|
||||
|
||||
it 'does not raise an error' do
|
||||
expect { subject.perform(account_id) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue