fix(object_id): Actually check for index .empty? instead of exist

This commit is contained in:
Pixelastic 2018-04-26 17:16:18 +02:00
parent f0e120b264
commit e5b2588f45
3 changed files with 14 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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'