Skip to content

Commit 4ac1236

Browse files
committed
Updates indexing spec
Updates usage of client
1 parent 157a7b3 commit 4ac1236

File tree

1 file changed

+9
-43
lines changed

1 file changed

+9
-43
lines changed

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

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ class NotFound < Exception; end
125125
end
126126

127127
context 'when the \'include_type_name\' option is specified' do
128-
129128
let(:mappings) do
130129
Elasticsearch::Model::Indexing::Mappings.new(include_type_name: true)
131130
end
@@ -164,7 +163,6 @@ class NotFound < Exception; end
164163
end
165164

166165
context 'when specific mappings are defined' do
167-
168166
let(:mappings) do
169167
Elasticsearch::Model::Indexing::Mappings.new(include_type_name: true)
170168
end
@@ -608,7 +606,7 @@ def changes
608606
end
609607
end
610608

611-
context 'when the index does not exists' do
609+
context 'when the index does not exist' do
612610
let(:client) do
613611
double('client', indices: double('indices', exists: false))
614612
end
@@ -634,19 +632,7 @@ class ::DummyIndexingModelForRecreate
634632

635633
context 'when the index is not found' do
636634
let(:logger) { nil }
637-
let(:transport) do
638-
Elastic::Transport::Client.new(logger: logger)
639-
end
640-
641-
let(:client) do
642-
double('client', indices: indices, transport: transport)
643-
end
644-
645-
let(:indices) do
646-
double('indices').tap do |ind|
647-
expect(ind).to receive(:delete).and_raise(NotFound)
648-
end
649-
end
635+
let(:client) { Elasticsearch::Client.new(logger: logger) }
650636

651637
before do
652638
expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client)
@@ -662,16 +648,12 @@ class ::DummyIndexingModelForRecreate
662648
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
663649
end
664650

665-
let(:client) do
666-
double('client', indices: indices, transport: transport)
667-
end
668-
669651
it 'deletes the index without raising an exception' do
670652
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
671653
end
672654

673655
it 'logs the message that the index is not found' do
674-
expect(logger).to receive(:debug)
656+
expect(logger).to receive(:debug).at_least(:once)
675657
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
676658
end
677659
end
@@ -681,7 +663,7 @@ class ::DummyIndexingModelForRecreate
681663
it 'raises an exception' do
682664
expect {
683665
DummyIndexingModelForRecreate.delete_index!
684-
}.to raise_exception(NotFound)
666+
}.to raise_exception(Elastic::Transport::Transport::Errors::NotFound)
685667
end
686668
end
687669

@@ -750,14 +732,12 @@ class ::DummyIndexingModelForCreate
750732
end
751733

752734
context 'when the index does not exist' do
753-
754735
before do
755736
expect(DummyIndexingModelForCreate).to receive(:client).and_return(client)
756737
expect(DummyIndexingModelForCreate).to receive(:index_exists?).and_return(false)
757738
end
758739

759740
context 'when options are not provided' do
760-
761741
let(:expected_body) do
762742
{ mappings: { properties: { foo: { analyzer: 'keyword',
763743
type: 'text' } } },
@@ -774,7 +754,6 @@ class ::DummyIndexingModelForCreate
774754
end
775755

776756
context 'when options are provided' do
777-
778757
let(:expected_body) do
779758
{ mappings: { foobar: { properties: { foo: { analyzer: 'bar' } } } },
780759
settings: { index: { number_of_shards: 3 } } }
@@ -795,7 +774,6 @@ class ::DummyIndexingModelForCreate
795774
end
796775

797776
context 'when the index exists' do
798-
799777
before do
800778
expect(DummyIndexingModelForCreate).to receive(:index_exists?).and_return(true)
801779
expect(indices).to receive(:create).never
@@ -864,15 +842,7 @@ class ::DummyIndexingModelForRefresh
864842
end
865843

866844
let(:client) do
867-
double('client', indices: indices, transport: transport)
868-
end
869-
870-
let(:transport) do
871-
Elastic::Transport::Client.new(logger: nil)
872-
end
873-
874-
let(:indices) do
875-
double('indices')
845+
Elasticsearch::Client.new(logger: nil)
876846
end
877847

878848
before do
@@ -882,7 +852,7 @@ class ::DummyIndexingModelForRefresh
882852
context 'when the force option is true' do
883853
context 'when the operation raises a NotFound exception' do
884854
before do
885-
expect(indices).to receive(:refresh).and_raise(NotFound)
855+
expect(client).to receive_message_chain(:indices, :refresh).and_raise(NotFound)
886856
end
887857

888858
it 'does not raise an exception' do
@@ -895,11 +865,7 @@ class ::DummyIndexingModelForRefresh
895865
end
896866

897867
let(:client) do
898-
double('client', indices: indices, transport: transport)
899-
end
900-
901-
let(:transport) do
902-
Elastic::Transport::Client.new(logger: logger)
868+
Elasticsearch::Client.new(logger: logger)
903869
end
904870

905871
it 'does not raise an exception' do
@@ -915,7 +881,7 @@ class ::DummyIndexingModelForRefresh
915881

916882
context 'when the operation raises another type of exception' do
917883
before do
918-
expect(indices).to receive(:refresh).and_raise(Exception)
884+
expect(client).to receive_message_chain(:indices, :refresh).and_raise(Exception)
919885
end
920886

921887
it 'does not raise an exception' do
@@ -928,7 +894,7 @@ class ::DummyIndexingModelForRefresh
928894

929895
context 'when an index name is provided in the options' do
930896
before do
931-
expect(indices).to receive(:refresh).with(index: 'custom-foo')
897+
expect(client).to receive_message_chain(:indices, :refresh).with(index: 'custom-foo')
932898
end
933899

934900
it 'uses the index name' do

0 commit comments

Comments
 (0)