feat(settings): Add a way to force the update of index settings
This commit is contained in:
parent
75231a3fda
commit
4793b54aeb
@ -19,6 +19,7 @@ Here is the list of command line options you can pass to the `jekyll algolia` co
|
||||
| `--config ./_config.yml` | You can here specify the config file to use. Default is `_config.yml` |
|
||||
| `--dry-run` or `-n` | Do a dry run, do not actually push anything to your index |
|
||||
| `--verbose` | Display more information about what is going to be indexed |
|
||||
| `--force-settings` | Force update of the index settings |
|
||||
|
||||
|
||||
## Environment variables
|
||||
|
||||
@ -215,6 +215,16 @@ module Jekyll
|
||||
false
|
||||
end
|
||||
|
||||
# Public: Returns true if the command should always update the settings
|
||||
#
|
||||
# When set to true, the index settings will always be updated, no matter
|
||||
# if they've been modified or not
|
||||
def self.force_settings?
|
||||
value = get('force_settings')
|
||||
return true if value == true
|
||||
false
|
||||
end
|
||||
|
||||
# Public: Disable features from other Jekyll plugins that might interfere
|
||||
# with the indexing
|
||||
def self.disable_other_plugins(config)
|
||||
|
||||
@ -162,9 +162,11 @@ module Jekyll
|
||||
settings = Configurator.settings
|
||||
setting_id = local_setting_id
|
||||
|
||||
are_settings_forced = Configurator.force_settings?
|
||||
|
||||
# The config we're about to push is the same we pushed previously. We
|
||||
# won't push again.
|
||||
if setting_id == remote_setting_id
|
||||
if setting_id == remote_setting_id && !are_settings_forced
|
||||
Logger.log('I:Settings are already up to date.')
|
||||
# Check if remote config has been changed outside of the plugin, so we
|
||||
# can warn users that they should not alter their config from outside
|
||||
@ -180,7 +182,8 @@ module Jekyll
|
||||
|
||||
# Settings have changed, we push them
|
||||
settings['userData'] = {
|
||||
'settingID' => setting_id
|
||||
'settingID' => setting_id,
|
||||
'pluginVersion' => VERSION
|
||||
}
|
||||
|
||||
Logger.log("I:Updating settings of index #{index.name}")
|
||||
|
||||
@ -21,6 +21,9 @@ module Jekyll
|
||||
command.option 'verbose',
|
||||
'--verbose',
|
||||
'Display more information on what is indexed'
|
||||
command.option 'force_settings',
|
||||
'--force-settings',
|
||||
'Force updating of the index settings'
|
||||
|
||||
command.action do |_, options|
|
||||
configuration = configuration_from_options(options)
|
||||
|
||||
@ -343,6 +343,31 @@ describe(Jekyll::Algolia::Configurator) do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'force_settings?' do
|
||||
subject { current.force_settings? }
|
||||
|
||||
before do
|
||||
allow(current).to receive(:get).with('force_settings').and_return(value)
|
||||
end
|
||||
|
||||
context 'when no value passed' do
|
||||
let(:value) { nil }
|
||||
it { should eq false }
|
||||
end
|
||||
context 'when passed true' do
|
||||
let(:value) { true }
|
||||
it { should eq true }
|
||||
end
|
||||
context 'when passed false' do
|
||||
let(:value) { false }
|
||||
it { should eq false }
|
||||
end
|
||||
context 'when passed invalid value' do
|
||||
let(:value) { 'chunky bacon' }
|
||||
it { should eq false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.warn_of_deprecated_options' do
|
||||
context 'using indexing_mode' do
|
||||
before do
|
||||
|
||||
@ -247,14 +247,20 @@ describe(Jekyll::Algolia::Indexer) do
|
||||
end
|
||||
|
||||
describe '.update_settings' do
|
||||
let(:pluginVersion) { nil }
|
||||
let(:diff_keys) { nil }
|
||||
let(:force_settings) { nil }
|
||||
|
||||
before do
|
||||
stub_const('Jekyll::Algolia::VERSION', pluginVersion)
|
||||
allow(utils).to receive(:diff_keys).and_return(diff_keys)
|
||||
allow(configurator)
|
||||
.to receive(:force_settings?)
|
||||
.and_return(force_settings)
|
||||
allow(current).to receive(:set_settings)
|
||||
allow(current).to receive(:warn_of_manual_dashboard_editing)
|
||||
allow(current).to receive(:local_setting_id).and_return(local_setting_id)
|
||||
allow(current).to receive(:remote_settings).and_return(remote_settings)
|
||||
allow(utils).to receive(:diff_keys).and_return(diff_keys)
|
||||
allow(current)
|
||||
.to receive(:index)
|
||||
.and_return(double('Algolia::index', name: 'my_index'))
|
||||
@ -279,6 +285,16 @@ describe(Jekyll::Algolia::Indexer) do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'should always update if --force-settings' do
|
||||
let(:local_setting_id) { 'foo' }
|
||||
let(:remote_settings) { { 'userData' => { 'settingID' => 'foo' } } }
|
||||
let(:force_settings) { true }
|
||||
it do
|
||||
expect(current)
|
||||
.to have_received(:set_settings)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'should update settings if no remote settingID' do
|
||||
let(:local_setting_id) { 'foo' }
|
||||
let(:remote_settings) { { 'userData' => {} } }
|
||||
@ -319,7 +335,24 @@ describe(Jekyll::Algolia::Indexer) do
|
||||
expect(current)
|
||||
.to have_received(:set_settings)
|
||||
.with(
|
||||
hash_including('userData' => { 'settingID' => 'foo' })
|
||||
hash_including(
|
||||
'userData' => hash_including('settingID' => 'foo')
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'should update settings with new version' do
|
||||
let(:local_setting_id) { 'foo' }
|
||||
let(:remote_settings) { { 'userData' => { 'settingID' => 'bar' } } }
|
||||
let(:pluginVersion) { 'pluginVersion' }
|
||||
it do
|
||||
expect(current)
|
||||
.to have_received(:set_settings)
|
||||
.with(
|
||||
hash_including(
|
||||
'userData' => hash_including('pluginVersion' => 'pluginVersion')
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user