From e5b2588f458cb33e7b48b56df524c41e65731e1f Mon Sep 17 00:00:00 2001 From: Pixelastic Date: Thu, 26 Apr 2018 17:16:18 +0200 Subject: [PATCH] fix(object_id): Actually check for index .empty? instead of exist --- lib/jekyll/algolia/indexer.rb | 5 ++--- spec/integration/object_ids_spec.rb | 4 ++-- spec/jekyll/algolia/indexer_spec.rb | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/jekyll/algolia/indexer.rb b/lib/jekyll/algolia/indexer.rb index 7d2fe72..8bb731f 100644 --- a/lib/jekyll/algolia/indexer.rb +++ b/lib/jekyll/algolia/indexer.rb @@ -142,10 +142,9 @@ module Jekyll def self.remote_object_ids Logger.log('I:Getting list of existing records') - # No main index, the list is empty no matter what (we don't use the + # Main index empty, the list is empty no matter what (we don't use the # dedicated index in that case) - has_index = index_exist?(index) - return [] unless has_index + return [] if record_count(index).zero? # Fast version, using the dedicated index has_object_id_index = index_exist?(index_object_ids) diff --git a/spec/integration/object_ids_spec.rb b/spec/integration/object_ids_spec.rb index c49cf41..635d628 100644 --- a/spec/integration/object_ids_spec.rb +++ b/spec/integration/object_ids_spec.rb @@ -84,10 +84,10 @@ describe('storing object ids') do end end - describe 'deleting the main index should force its recreation' do + describe 'clearing the main index should force its recreation' do before do indexer.update_records(records) - indexer.index.delete_index! + indexer.index.clear_index! indexer.update_records(records) @index = indexer.index end diff --git a/spec/jekyll/algolia/indexer_spec.rb b/spec/jekyll/algolia/indexer_spec.rb index fb1c385..0cb412b 100644 --- a/spec/jekyll/algolia/indexer_spec.rb +++ b/spec/jekyll/algolia/indexer_spec.rb @@ -287,41 +287,41 @@ describe(Jekyll::Algolia::Indexer) do allow(current).to receive(:index_object_ids).and_return('dedicated_index') allow(current).to receive(:index).and_return('main_index') allow(current) - .to receive(:index_exist?) + .to receive(:record_count) .with('main_index') - .and_return(main_index_exist) + .and_return(main_record_count) allow(current) .to receive(:index_exist?) .with('dedicated_index') .and_return(dedicated_index_exist) end - describe 'no index exists' do - let(:main_index_exist) { false } + describe 'no index is available' do + let(:main_record_count) { 0 } let(:dedicated_index_exist) { false } it 'should return an empty list' do should eq [] end end - describe 'only main index exists' do - let(:main_index_exist) { true } + describe 'only main index is available' do + let(:main_record_count) { 42 } let(:dedicated_index_exist) { false } it 'should get objectIds from it' do should eq 'main_results' end end - describe 'only dedicated index exists' do - let(:main_index_exist) { false } + describe 'main index is unavailable' do + let(:main_record_count) { 0 } let(:dedicated_index_exist) { true } it 'should not use objectIDs from it' do should eq [] end end - describe 'both index exist' do - let(:main_index_exist) { true } + describe 'both index are available' do + let(:main_record_count) { 42 } let(:dedicated_index_exist) { true } it 'should use objectIDs from the dedicated index' do should eq 'dedicated_results'