feat(user-agent): Send the plugin name and version in the UA
This commit is contained in:
parent
c0db6f4908
commit
ecd4c67f06
@ -124,8 +124,15 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
|
|||||||
index.set_settings(settings)
|
index.set_settings(settings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Change the User-Agent header to isolate calls from this plugin
|
||||||
|
def set_user_agent_header
|
||||||
|
version = Gem::Specification.load('algoliasearch-jekyll.gemspec').version
|
||||||
|
Algolia.set_extra_header('User-Agent', "Algolia for Jekyll #{version}")
|
||||||
|
end
|
||||||
|
|
||||||
# Create an index to push our data
|
# Create an index to push our data
|
||||||
def create_index(index_name)
|
def create_index(index_name)
|
||||||
|
set_user_agent_header
|
||||||
index = Algolia::Index.new(index_name)
|
index = Algolia::Index.new(index_name)
|
||||||
configure_index(index) unless @is_dry_run
|
configure_index(index) unless @is_dry_run
|
||||||
index
|
index
|
||||||
|
|||||||
@ -184,6 +184,29 @@ describe(AlgoliaSearchJekyllPush) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'set_user_agent_header' do
|
||||||
|
it 'should set a User-Agent with the plugin name and version' do
|
||||||
|
# Given
|
||||||
|
expected = '48.1516.2342'
|
||||||
|
spec = Gem::Specification.load('algoliasearch-jekyll.gemspec')
|
||||||
|
spec.version = expected
|
||||||
|
allow(Algolia).to receive(:set_extra_header)
|
||||||
|
|
||||||
|
# When
|
||||||
|
push.set_user_agent_header
|
||||||
|
|
||||||
|
# Then
|
||||||
|
expect(Algolia).to have_received(:set_extra_header).with(
|
||||||
|
'User-Agent',
|
||||||
|
/Jekyll/
|
||||||
|
)
|
||||||
|
expect(Algolia).to have_received(:set_extra_header).with(
|
||||||
|
'User-Agent',
|
||||||
|
/#{expected}/
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'push' do
|
describe 'push' do
|
||||||
let(:index_double) { double('Algolia Index').as_null_object }
|
let(:index_double) { double('Algolia Index').as_null_object }
|
||||||
let(:config) do
|
let(:config) do
|
||||||
@ -199,6 +222,7 @@ describe(AlgoliaSearchJekyllPush) do
|
|||||||
# Mock all calls to not send anything
|
# Mock all calls to not send anything
|
||||||
allow_any_instance_of(AlgoliaSearchCredentialChecker)
|
allow_any_instance_of(AlgoliaSearchCredentialChecker)
|
||||||
.to receive(:assert_valid)
|
.to receive(:assert_valid)
|
||||||
|
allow(Algolia).to receive(:set_extra_header)
|
||||||
allow(Algolia).to receive(:init)
|
allow(Algolia).to receive(:init)
|
||||||
allow(Algolia).to receive(:move_index)
|
allow(Algolia).to receive(:move_index)
|
||||||
allow(Algolia::Index).to receive(:new).and_return(index_double)
|
allow(Algolia::Index).to receive(:new).and_return(index_double)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user