0
0
Fork 0

Add type, limit, offset, min_id, max_id, account_id to search API (#10091)

* Add type, limit, offset, min_id, max_id, account_id to search API

Fix #8939

* Make the offset work on accounts and hashtags search as well

* Assure brakeman we are not doing mass assignment here

* Do not allow paginating unless a type is chosen

* Fix search query and index id field on statuses instead of created_at
This commit is contained in:
Eugen Rochko 2019-02-26 15:21:36 +01:00 committed by GitHub
parent ea58e31822
commit e7f20cc43f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 161 additions and 230 deletions

View file

@ -10,7 +10,7 @@ describe SearchService, type: :service do
it 'returns empty results without searching' do
allow(AccountSearchService).to receive(:new)
allow(Tag).to receive(:search_for)
results = subject.call('', 10)
results = subject.call('', nil, 10)
expect(results).to eq(empty_results)
expect(AccountSearchService).not_to have_received(:new)
@ -27,7 +27,7 @@ describe SearchService, type: :service do
it 'returns the empty results' do
service = double(call: nil)
allow(ResolveURLService).to receive(:new).and_return(service)
results = subject.call(@query, 10)
results = subject.call(@query, nil, 10)
expect(service).to have_received(:call).with(@query, on_behalf_of: nil)
expect(results).to eq empty_results
@ -40,7 +40,7 @@ describe SearchService, type: :service do
service = double(call: account)
allow(ResolveURLService).to receive(:new).and_return(service)
results = subject.call(@query, 10)
results = subject.call(@query, nil, 10)
expect(service).to have_received(:call).with(@query, on_behalf_of: nil)
expect(results).to eq empty_results.merge(accounts: [account])
end
@ -52,7 +52,7 @@ describe SearchService, type: :service do
service = double(call: status)
allow(ResolveURLService).to receive(:new).and_return(service)
results = subject.call(@query, 10)
results = subject.call(@query, nil, 10)
expect(service).to have_received(:call).with(@query, on_behalf_of: nil)
expect(results).to eq empty_results.merge(statuses: [status])
end
@ -67,8 +67,8 @@ describe SearchService, type: :service do
service = double(call: [account])
allow(AccountSearchService).to receive(:new).and_return(service)
results = subject.call(query, 10)
expect(service).to have_received(:call).with(query, 10, nil, resolve: false)
results = subject.call(query, nil, 10)
expect(service).to have_received(:call).with(query, nil, limit: 10, offset: 0, resolve: false)
expect(results).to eq empty_results.merge(accounts: [account])
end
end
@ -77,17 +77,17 @@ describe SearchService, type: :service do
it 'includes the tag in the results' do
query = '#tag'
tag = Tag.new
allow(Tag).to receive(:search_for).with('tag', 10).and_return([tag])
allow(Tag).to receive(:search_for).with('tag', 10, 0).and_return([tag])
results = subject.call(query, 10)
expect(Tag).to have_received(:search_for).with('tag', 10)
results = subject.call(query, nil, 10)
expect(Tag).to have_received(:search_for).with('tag', 10, 0)
expect(results).to eq empty_results.merge(hashtags: [tag])
end
it 'does not include tag when starts with @ character' do
query = '@username'
allow(Tag).to receive(:search_for)
results = subject.call(query, 10)
results = subject.call(query, nil, 10)
expect(Tag).not_to have_received(:search_for)
expect(results).to eq empty_results
end