Rename FetchRemoteResourceService to ResolveURLService (#6328)
The service used to be named FetchRemoteResourceService resolves local URL as well.
This commit is contained in:
parent
8cc65cde27
commit
17cecd75ca
@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FetchRemoteResourceService < BaseService
|
class ResolveURLService < BaseService
|
||||||
include JsonLdHelper
|
include JsonLdHelper
|
||||||
|
|
||||||
attr_reader :url
|
attr_reader :url
|
@ -8,7 +8,7 @@ class SearchService < BaseService
|
|||||||
|
|
||||||
default_results.tap do |results|
|
default_results.tap do |results|
|
||||||
if url_query?
|
if url_query?
|
||||||
results.merge!(remote_resource_results) unless remote_resource.nil?
|
results.merge!(url_resource_results) unless url_resource.nil?
|
||||||
elsif query.present?
|
elsif query.present?
|
||||||
results[:accounts] = AccountSearchService.new.call(query, limit, account, resolve: resolve)
|
results[:accounts] = AccountSearchService.new.call(query, limit, account, resolve: resolve)
|
||||||
results[:hashtags] = Tag.search_for(query.gsub(/\A#/, ''), limit) unless query.start_with?('@')
|
results[:hashtags] = Tag.search_for(query.gsub(/\A#/, ''), limit) unless query.start_with?('@')
|
||||||
@ -24,15 +24,15 @@ class SearchService < BaseService
|
|||||||
query =~ /\Ahttps?:\/\//
|
query =~ /\Ahttps?:\/\//
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_resource_results
|
def url_resource_results
|
||||||
{ remote_resource_symbol => [remote_resource] }
|
{ url_resource_symbol => [url_resource] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_resource
|
def url_resource
|
||||||
@_remote_resource ||= FetchRemoteResourceService.new.call(query)
|
@_url_resource ||= ResolveURLService.new.call(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_resource_symbol
|
def url_resource_symbol
|
||||||
remote_resource.class.name.downcase.pluralize.to_sym
|
url_resource.class.name.downcase.pluralize.to_sym
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe FetchRemoteResourceService do
|
describe ResolveURLService do
|
||||||
subject { described_class.new }
|
subject { described_class.new }
|
||||||
|
|
||||||
describe '#call' do
|
describe '#call' do
|
@ -26,7 +26,7 @@ describe SearchService do
|
|||||||
context 'that does not find anything' do
|
context 'that does not find anything' do
|
||||||
it 'returns the empty results' do
|
it 'returns the empty results' do
|
||||||
service = double(call: nil)
|
service = double(call: nil)
|
||||||
allow(FetchRemoteResourceService).to receive(:new).and_return(service)
|
allow(ResolveURLService).to receive(:new).and_return(service)
|
||||||
results = subject.call(@query, 10)
|
results = subject.call(@query, 10)
|
||||||
|
|
||||||
expect(service).to have_received(:call).with(@query)
|
expect(service).to have_received(:call).with(@query)
|
||||||
@ -38,7 +38,7 @@ describe SearchService do
|
|||||||
it 'includes the account in the results' do
|
it 'includes the account in the results' do
|
||||||
account = Account.new
|
account = Account.new
|
||||||
service = double(call: account)
|
service = double(call: account)
|
||||||
allow(FetchRemoteResourceService).to receive(:new).and_return(service)
|
allow(ResolveURLService).to receive(:new).and_return(service)
|
||||||
|
|
||||||
results = subject.call(@query, 10)
|
results = subject.call(@query, 10)
|
||||||
expect(service).to have_received(:call).with(@query)
|
expect(service).to have_received(:call).with(@query)
|
||||||
@ -50,7 +50,7 @@ describe SearchService do
|
|||||||
it 'includes the status in the results' do
|
it 'includes the status in the results' do
|
||||||
status = Status.new
|
status = Status.new
|
||||||
service = double(call: status)
|
service = double(call: status)
|
||||||
allow(FetchRemoteResourceService).to receive(:new).and_return(service)
|
allow(ResolveURLService).to receive(:new).and_return(service)
|
||||||
|
|
||||||
results = subject.call(@query, 10)
|
results = subject.call(@query, 10)
|
||||||
expect(service).to have_received(:call).with(@query)
|
expect(service).to have_received(:call).with(@query)
|
||||||
|
Loading…
Reference in New Issue
Block a user