Skip to content

Commit 8e3d3ab

Browse files
author
Jon Whiteaker
committed
Adds test for skipping empty elasticsearch update
1 parent 8f51b72 commit 8e3d3ab

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,10 @@ def changes
440440
context 'when changes are present' do
441441

442442
before do
443-
expect(instance).to receive(:client).and_return(client)
444-
expect(instance).to receive(:index_name).and_return('foo')
445-
expect(instance).to receive(:document_type).and_return('bar')
446-
expect(instance).to receive(:id).and_return('1')
443+
allow(instance).to receive(:client).and_return(client)
444+
allow(instance).to receive(:index_name).and_return('foo')
445+
allow(instance).to receive(:document_type).and_return('bar')
446+
allow(instance).to receive(:id).and_return('1')
447447
end
448448

449449
context 'when the changes are included in the as_indexed_json representation' do
@@ -474,6 +474,21 @@ def changes
474474
end
475475
end
476476

477+
context 'when none of the changes are included in the as_indexed_json representation' do
478+
479+
let(:instance) do
480+
DummyIndexingModelWithCallbacksAndCustomAsIndexedJson.new
481+
end
482+
483+
before do
484+
instance.instance_variable_set(:@__changed_model_attributes, {'bar' => 'D' })
485+
end
486+
487+
it 'does not update the document' do
488+
expect(instance.update_document).to_not be(true)
489+
end
490+
end
491+
477492
context 'when there are partial updates' do
478493

479494
let(:instance) do

0 commit comments

Comments
 (0)