elasticsearch-model 6.1.1 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile +18 -1
  4. data/LICENSE.txt +199 -10
  5. data/README.md +47 -48
  6. data/Rakefile +29 -13
  7. data/elasticsearch-model.gemspec +53 -39
  8. data/examples/activerecord_article.rb +17 -0
  9. data/examples/activerecord_associations.rb +34 -1
  10. data/examples/activerecord_custom_analyzer.rb +19 -2
  11. data/examples/activerecord_mapping_completion.rb +17 -0
  12. data/examples/activerecord_mapping_edge_ngram.rb +17 -0
  13. data/examples/couchbase_article.rb +17 -0
  14. data/examples/datamapper_article.rb +17 -0
  15. data/examples/mongoid_article.rb +17 -0
  16. data/examples/ohm_article.rb +17 -0
  17. data/examples/riak_article.rb +17 -0
  18. data/gemfiles/3.0.gemfile +18 -1
  19. data/gemfiles/4.0.gemfile +18 -1
  20. data/gemfiles/5.0.gemfile +18 -1
  21. data/gemfiles/6.0.gemfile +21 -3
  22. data/lib/elasticsearch/model/adapter.rb +17 -0
  23. data/lib/elasticsearch/model/adapters/active_record.rb +17 -0
  24. data/lib/elasticsearch/model/adapters/default.rb +17 -0
  25. data/lib/elasticsearch/model/adapters/mongoid.rb +17 -0
  26. data/lib/elasticsearch/model/adapters/multiple.rb +29 -4
  27. data/lib/elasticsearch/model/callbacks.rb +17 -0
  28. data/lib/elasticsearch/model/client.rb +17 -5
  29. data/lib/elasticsearch/model/ext/active_record.rb +17 -0
  30. data/lib/elasticsearch/model/hash_wrapper.rb +17 -0
  31. data/lib/elasticsearch/model/importing.rb +60 -16
  32. data/lib/elasticsearch/model/indexing.rb +72 -46
  33. data/lib/elasticsearch/model/multimodel.rb +18 -1
  34. data/lib/elasticsearch/model/naming.rb +19 -19
  35. data/lib/elasticsearch/model/proxy.rb +64 -24
  36. data/lib/elasticsearch/model/response/aggregations.rb +17 -0
  37. data/lib/elasticsearch/model/response/base.rb +22 -1
  38. data/lib/elasticsearch/model/response/pagination/kaminari.rb +17 -0
  39. data/lib/elasticsearch/model/response/pagination/will_paginate.rb +17 -0
  40. data/lib/elasticsearch/model/response/pagination.rb +17 -0
  41. data/lib/elasticsearch/model/response/records.rb +17 -1
  42. data/lib/elasticsearch/model/response/result.rb +17 -0
  43. data/lib/elasticsearch/model/response/results.rb +18 -0
  44. data/lib/elasticsearch/model/response/suggestions.rb +17 -0
  45. data/lib/elasticsearch/model/response.rb +17 -0
  46. data/lib/elasticsearch/model/searching.rb +17 -0
  47. data/lib/elasticsearch/model/serializing.rb +17 -0
  48. data/lib/elasticsearch/model/version.rb +18 -1
  49. data/lib/elasticsearch/model.rb +27 -62
  50. data/spec/elasticsearch/model/adapter_spec.rb +17 -0
  51. data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +17 -0
  52. data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +281 -226
  53. data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +17 -0
  54. data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +18 -12
  55. data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +17 -0
  56. data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +18 -1
  57. data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +17 -0
  58. data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +18 -1
  59. data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +17 -0
  60. data/spec/elasticsearch/model/adapters/active_record_spec.rb +17 -0
  61. data/spec/elasticsearch/model/adapters/default_spec.rb +17 -0
  62. data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +17 -0
  63. data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +28 -11
  64. data/spec/elasticsearch/model/adapters/mongoid_spec.rb +17 -0
  65. data/spec/elasticsearch/model/adapters/multiple_spec.rb +17 -0
  66. data/spec/elasticsearch/model/callbacks_spec.rb +17 -0
  67. data/spec/elasticsearch/model/client_spec.rb +20 -3
  68. data/spec/elasticsearch/model/hash_wrapper_spec.rb +17 -0
  69. data/spec/elasticsearch/model/importing_spec.rb +29 -0
  70. data/spec/elasticsearch/model/indexing_spec.rb +127 -56
  71. data/spec/elasticsearch/model/module_spec.rb +19 -26
  72. data/spec/elasticsearch/model/multimodel_spec.rb +17 -0
  73. data/spec/elasticsearch/model/naming_spec.rb +22 -5
  74. data/spec/elasticsearch/model/proxy_spec.rb +26 -1
  75. data/spec/elasticsearch/model/response/aggregations_spec.rb +17 -0
  76. data/spec/elasticsearch/model/response/base_spec.rb +17 -0
  77. data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +85 -23
  78. data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +17 -0
  79. data/spec/elasticsearch/model/response/records_spec.rb +17 -0
  80. data/spec/elasticsearch/model/response/response_spec.rb +17 -0
  81. data/spec/elasticsearch/model/response/result_spec.rb +17 -0
  82. data/spec/elasticsearch/model/response/results_spec.rb +29 -0
  83. data/spec/elasticsearch/model/searching_search_request_spec.rb +17 -0
  84. data/spec/elasticsearch/model/searching_spec.rb +17 -0
  85. data/spec/elasticsearch/model/serializing_spec.rb +17 -0
  86. data/spec/spec_helper.rb +37 -5
  87. data/spec/support/app/answer.rb +18 -1
  88. data/spec/support/app/article.rb +17 -0
  89. data/spec/support/app/article_for_pagination.rb +17 -0
  90. data/spec/support/app/article_no_type.rb +37 -0
  91. data/spec/support/app/article_with_custom_serialization.rb +17 -0
  92. data/spec/support/app/article_with_dynamic_index_name.rb +17 -0
  93. data/spec/support/app/author.rb +17 -0
  94. data/spec/support/app/authorship.rb +17 -0
  95. data/spec/support/app/category.rb +17 -0
  96. data/spec/support/app/comment.rb +17 -0
  97. data/spec/support/app/episode.rb +17 -0
  98. data/spec/support/app/image.rb +17 -0
  99. data/spec/support/app/import_article.rb +17 -0
  100. data/spec/support/app/mongoid_article.rb +17 -0
  101. data/spec/support/app/namespaced_book.rb +17 -0
  102. data/spec/support/app/parent_and_child_searchable.rb +21 -4
  103. data/spec/support/app/post.rb +17 -0
  104. data/spec/support/app/question.rb +17 -0
  105. data/spec/support/app/searchable.rb +17 -0
  106. data/spec/support/app/series.rb +17 -0
  107. data/spec/support/app.rb +27 -2
  108. metadata +42 -56
  109. data/spec/elasticsearch/model/naming_inheritance_spec.rb +0 -184
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Indexing do
@@ -84,10 +101,8 @@ describe Elasticsearch::Model::Indexing do
84
101
  expect(DummyIndexingModel.mappings).to be_a(Elasticsearch::Model::Indexing::Mappings)
85
102
  end
86
103
 
87
- it 'raises an exception when there is no type passed to the #initialize method' do
88
- expect {
89
- Elasticsearch::Model::Indexing::Mappings.new
90
- }.to raise_exception(ArgumentError)
104
+ it 'does not raise an exception when there is no type passed to the #initialize method' do
105
+ expect(Elasticsearch::Model::Indexing::Mappings.new)
91
106
  end
92
107
 
93
108
  it 'should be convertible to a hash' do
@@ -98,7 +113,7 @@ describe Elasticsearch::Model::Indexing do
98
113
  expect(Elasticsearch::Model::Indexing::Mappings.new(:mytype, { foo: 'bar' }).as_json).to eq(expected_mapping_hash)
99
114
  end
100
115
 
101
- context 'when specific mappings are defined' do
116
+ context 'when a type is specified' do
102
117
 
103
118
  let(:mappings) do
104
119
  Elasticsearch::Model::Indexing::Mappings.new(:mytype)
@@ -113,6 +128,65 @@ describe Elasticsearch::Model::Indexing do
113
128
  expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean')
114
129
  end
115
130
 
131
+ it 'uses text as the default field type' do
132
+ expect(mappings.to_hash[:mytype][:properties][:bar][:type]).to eq('text')
133
+ end
134
+
135
+ context 'when the \'include_type_name\' option is specified' do
136
+
137
+ let(:mappings) do
138
+ Elasticsearch::Model::Indexing::Mappings.new(:mytype, include_type_name: true)
139
+ end
140
+
141
+ before do
142
+ mappings.indexes :foo, { type: 'boolean', include_in_all: false }
143
+ end
144
+
145
+ it 'creates the correct mapping definition' do
146
+ expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean')
147
+ end
148
+
149
+ it 'sets the \'include_type_name\' option' do
150
+ expect(mappings.to_hash[:mytype][:include_type_name]).to eq(true)
151
+ end
152
+ end
153
+ end
154
+
155
+ context 'when a type is not specified' do
156
+
157
+ let(:mappings) do
158
+ Elasticsearch::Model::Indexing::Mappings.new
159
+ end
160
+
161
+ before do
162
+ mappings.indexes :foo, { type: 'boolean', include_in_all: false }
163
+ mappings.indexes :bar
164
+ end
165
+
166
+ it 'creates the correct mapping definition' do
167
+ expect(mappings.to_hash[:properties][:foo][:type]).to eq('boolean')
168
+ end
169
+
170
+ it 'uses text as the default type' do
171
+ expect(mappings.to_hash[:properties][:bar][:type]).to eq('text')
172
+ end
173
+ end
174
+
175
+ context 'when specific mappings are defined' do
176
+
177
+ let(:mappings) do
178
+ Elasticsearch::Model::Indexing::Mappings.new(:mytype, include_type_name: true)
179
+ end
180
+
181
+ before do
182
+ mappings.indexes :foo, { type: 'boolean', include_in_all: false }
183
+ mappings.indexes :bar
184
+ end
185
+
186
+ it 'creates the correct mapping definition' do
187
+ expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean')
188
+ end
189
+
116
190
  it 'uses text as the default type' do
117
191
  expect(mappings.to_hash[:mytype][:properties][:bar][:type]).to eq('text')
118
192
  end
@@ -169,6 +243,10 @@ describe Elasticsearch::Model::Indexing do
169
243
  expect(mappings.to_hash[:mytype][:properties][:foo_nested_as_symbol][:properties]).not_to be_nil
170
244
  expect(mappings.to_hash[:mytype][:properties][:foo_nested_as_symbol][:fields]).to be_nil
171
245
  end
246
+
247
+ it 'defines the settings' do
248
+ expect(mappings.to_hash[:mytype][:include_type_name]).to be(true)
249
+ end
172
250
  end
173
251
  end
174
252
 
@@ -180,7 +258,7 @@ describe Elasticsearch::Model::Indexing do
180
258
  end
181
259
 
182
260
  let(:expected_mappings_hash) do
183
- { _doc: { foo: "boo", bar: "bam", properties: {} } }
261
+ { foo: "boo", bar: "bam", properties: {} }
184
262
  end
185
263
 
186
264
  it 'sets the mappings' do
@@ -196,7 +274,25 @@ describe Elasticsearch::Model::Indexing do
196
274
  end
197
275
 
198
276
  it 'sets the mappings' do
199
- expect(DummyIndexingModel.mapping.to_hash[:_doc][:properties][:foo][:type]).to eq('boolean')
277
+ expect(DummyIndexingModel.mapping.to_hash[:properties][:foo][:type]).to eq('boolean')
278
+ end
279
+ end
280
+
281
+ context 'when the class has a document_type' do
282
+
283
+ before do
284
+ DummyIndexingModel.instance_variable_set(:@mapping, nil)
285
+ DummyIndexingModel.document_type(:mytype)
286
+ DummyIndexingModel.mappings(foo: 'boo')
287
+ DummyIndexingModel.mappings(bar: 'bam')
288
+ end
289
+
290
+ let(:expected_mappings_hash) do
291
+ { mytype: { foo: "boo", bar: "bam", properties: {} } }
292
+ end
293
+
294
+ it 'sets the mappings' do
295
+ expect(DummyIndexingModel.mappings.to_hash).to eq(expected_mappings_hash)
200
296
  end
201
297
  end
202
298
  end
@@ -322,7 +418,7 @@ describe Elasticsearch::Model::Indexing do
322
418
  expect(instance).to receive(:client).and_return(client)
323
419
  expect(instance).to receive(:as_indexed_json).and_return('JSON')
324
420
  expect(instance).to receive(:index_name).and_return('foo')
325
- expect(instance).to receive(:document_type).and_return('bar')
421
+ expect(instance).to receive(:document_type).twice.and_return('bar')
326
422
  expect(instance).to receive(:id).and_return('1')
327
423
  end
328
424
 
@@ -362,7 +458,7 @@ describe Elasticsearch::Model::Indexing do
362
458
  before do
363
459
  expect(instance).to receive(:client).and_return(client)
364
460
  expect(instance).to receive(:index_name).and_return('foo')
365
- expect(instance).to receive(:document_type).and_return('bar')
461
+ expect(instance).to receive(:document_type).twice.and_return('bar')
366
462
  expect(instance).to receive(:id).and_return('1')
367
463
  end
368
464
 
@@ -506,7 +602,7 @@ describe Elasticsearch::Model::Indexing do
506
602
  before do
507
603
  expect(instance).to receive(:client).and_return(client)
508
604
  expect(instance).to receive(:index_name).and_return('foo')
509
- expect(instance).to receive(:document_type).and_return('bar')
605
+ expect(instance).to receive(:document_type).twice.and_return('bar')
510
606
  expect(instance).to receive(:id).and_return('1')
511
607
  instance.instance_variable_set(:@__changed_model_attributes, { author: 'john' })
512
608
  end
@@ -563,36 +659,6 @@ describe Elasticsearch::Model::Indexing do
563
659
  expect(DummyIndexingModel.index_exists?).to be(false)
564
660
  end
565
661
  end
566
-
567
- context 'when the index API raises an error' do
568
-
569
- let(:client) do
570
- double('client').tap do |cl|
571
- expect(cl).to receive(:indices).and_raise(StandardError)
572
- end
573
- end
574
-
575
- it 'returns false' do
576
- expect(DummyIndexingModel.index_exists?).to be(false)
577
- end
578
- end
579
-
580
- context 'when the indices.exists API raises an error' do
581
-
582
- let(:client) do
583
- double('client', indices: indices)
584
- end
585
-
586
- let(:indices) do
587
- double('indices').tap do |ind|
588
- expect(ind).to receive(:exists).and_raise(StandardError)
589
- end
590
- end
591
-
592
- it 'returns false' do
593
- expect(DummyIndexingModel.index_exists?).to be(false)
594
- end
595
- end
596
662
  end
597
663
 
598
664
  describe '#delete_index!' do
@@ -610,9 +676,13 @@ describe Elasticsearch::Model::Indexing do
610
676
  end
611
677
 
612
678
  context 'when the index is not found' do
679
+ let(:logger) { nil }
680
+ let(:transport) do
681
+ Elasticsearch::Transport::Client.new(logger: logger)
682
+ end
613
683
 
614
684
  let(:client) do
615
- double('client', indices: indices, transport: double('transport', { logger: nil }))
685
+ double('client', indices: indices, transport: transport)
616
686
  end
617
687
 
618
688
  let(:indices) do
@@ -626,19 +696,17 @@ describe Elasticsearch::Model::Indexing do
626
696
  end
627
697
 
628
698
  context 'when the force option is true' do
629
-
630
699
  it 'deletes the index without raising an exception' do
631
700
  expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
632
701
  end
633
702
 
634
703
  context 'when the client has a logger' do
635
-
636
704
  let(:logger) do
637
705
  Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
638
706
  end
639
707
 
640
708
  let(:client) do
641
- double('client', indices: indices, transport: double('transport', { logger: logger }))
709
+ double('client', indices: indices, transport: transport)
642
710
  end
643
711
 
644
712
  it 'deletes the index without raising an exception' do
@@ -738,8 +806,8 @@ describe Elasticsearch::Model::Indexing do
738
806
  context 'when options are not provided' do
739
807
 
740
808
  let(:expected_body) do
741
- { mappings: { _doc: { properties: { foo: { analyzer: 'keyword',
742
- type: 'text' } } } },
809
+ { mappings: { properties: { foo: { analyzer: 'keyword',
810
+ type: 'text' } } },
743
811
  settings: { index: { number_of_shards: 1 } } }
744
812
  end
745
813
 
@@ -789,8 +857,8 @@ describe Elasticsearch::Model::Indexing do
789
857
 
790
858
  before do
791
859
  expect(DummyIndexingModelForCreate).to receive(:client).and_return(client)
792
- expect(DummyIndexingModelForCreate).to receive(:index_exists?).and_return(false)
793
860
  expect(DummyIndexingModelForCreate).to receive(:delete_index!).and_return(true)
861
+ expect(DummyIndexingModelForCreate).to receive(:index_exists?).and_return(false)
794
862
  expect(indices).to receive(:create).and_raise(Exception)
795
863
  end
796
864
 
@@ -810,8 +878,8 @@ describe Elasticsearch::Model::Indexing do
810
878
  end
811
879
 
812
880
  let(:expected_body) do
813
- { mappings: { _doc: { properties: { foo: { analyzer: 'keyword',
814
- type: 'text' } } } },
881
+ { mappings: { properties: { foo: { analyzer: 'keyword',
882
+ type: 'text' } } },
815
883
  settings: { index: { number_of_shards: 1 } } }
816
884
  end
817
885
 
@@ -846,7 +914,11 @@ describe Elasticsearch::Model::Indexing do
846
914
  end
847
915
 
848
916
  let(:client) do
849
- double('client', indices: indices, transport: double('transport', { logger: nil }))
917
+ double('client', indices: indices, transport: transport)
918
+ end
919
+
920
+ let(:transport) do
921
+ Elasticsearch::Transport::Client.new(logger: nil)
850
922
  end
851
923
 
852
924
  let(:indices) do
@@ -858,9 +930,7 @@ describe Elasticsearch::Model::Indexing do
858
930
  end
859
931
 
860
932
  context 'when the force option is true' do
861
-
862
933
  context 'when the operation raises a NotFound exception' do
863
-
864
934
  before do
865
935
  expect(indices).to receive(:refresh).and_raise(NotFound)
866
936
  end
@@ -870,13 +940,16 @@ describe Elasticsearch::Model::Indexing do
870
940
  end
871
941
 
872
942
  context 'when the client has a logger' do
873
-
874
943
  let(:logger) do
875
944
  Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
876
945
  end
877
946
 
878
947
  let(:client) do
879
- double('client', indices: indices, transport: double('transport', { logger: logger }))
948
+ double('client', indices: indices, transport: transport)
949
+ end
950
+
951
+ let(:transport) do
952
+ Elasticsearch::Transport::Client.new(logger: logger)
880
953
  end
881
954
 
882
955
  it 'does not raise an exception' do
@@ -891,7 +964,6 @@ describe Elasticsearch::Model::Indexing do
891
964
  end
892
965
 
893
966
  context 'when the operation raises another type of exception' do
894
-
895
967
  before do
896
968
  expect(indices).to receive(:refresh).and_raise(Exception)
897
969
  end
@@ -905,7 +977,6 @@ describe Elasticsearch::Model::Indexing do
905
977
  end
906
978
 
907
979
  context 'when an index name is provided in the options' do
908
-
909
980
  before do
910
981
  expect(indices).to receive(:refresh).with(index: 'custom-foo')
911
982
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model do
@@ -5,7 +22,7 @@ describe Elasticsearch::Model do
5
22
  describe '#client' do
6
23
 
7
24
  it 'should have a default' do
8
- expect(Elasticsearch::Model.client).to be_a(Elasticsearch::Transport::Client)
25
+ expect(Elasticsearch::Model.client).to be_a(Elasticsearch::Client)
9
26
  end
10
27
  end
11
28
 
@@ -31,6 +48,7 @@ describe Elasticsearch::Model do
31
48
  end
32
49
 
33
50
  DummyIncludingModel.__send__ :include, Elasticsearch::Model
51
+ DummyIncludingModelWithSearchMethodDefined.__send__ :include, Elasticsearch::Model
34
52
  end
35
53
 
36
54
  after(:all) do
@@ -72,30 +90,5 @@ describe Elasticsearch::Model do
72
90
  expect(Elasticsearch::Model.settings[:foo]).to eq('bar')
73
91
  end
74
92
  end
75
-
76
- context 'when \'inheritance_enabled\' is set' do
77
-
78
- around do |example|
79
- original_value = Elasticsearch::Model.settings[:inheritance_enabled]
80
- example.run
81
- Elasticsearch::Model.settings[:inheritance_enabled] = original_value
82
- end
83
-
84
- context 'when \'inheritance_enabled\' is true' do
85
-
86
- it 'warns with a deprecation message' do
87
- expect(Elasticsearch::Model).to receive(:warn)
88
- Elasticsearch::Model.inheritance_enabled = true
89
- end
90
- end
91
-
92
- context 'when \'inheritance_enabled\' is false' do
93
-
94
- it 'does not warn' do
95
- expect(Elasticsearch::Model).not_to receive(:warn)
96
- Elasticsearch::Model.inheritance_enabled = false
97
- end
98
- end
99
- end
100
93
  end
101
94
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Multimodel do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe 'naming' do
@@ -34,9 +51,9 @@ describe 'naming' do
34
51
  expect(::MyNamespace::DummyNamingModelInNamespace.new.index_name).to eq('my_namespace-dummy_naming_model_in_namespaces')
35
52
  end
36
53
 
37
- it 'returns the document type' do
38
- expect(DummyNamingModel.document_type).to eq('_doc')
39
- expect(DummyNamingModel.new.document_type).to eq('_doc')
54
+ it 'returns nil' do
55
+ expect(DummyNamingModel.document_type).to be_nil
56
+ expect(DummyNamingModel.new.document_type).to be_nil
40
57
  end
41
58
 
42
59
  describe '#index_name' do
@@ -124,8 +141,8 @@ describe 'naming' do
124
141
 
125
142
  describe '#document_type' do
126
143
 
127
- it 'returns the document type' do
128
- expect(DummyNamingModel.document_type).to eq('_doc')
144
+ it 'returns nil' do
145
+ expect(DummyNamingModel.document_type).to be_nil
129
146
  end
130
147
 
131
148
  context 'when the method is called with an argument' do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Proxy do
@@ -14,6 +31,10 @@ describe Elasticsearch::Model::Proxy do
14
31
  'insta barr'
15
32
  end
16
33
 
34
+ def keyword_method(foo: 'default value')
35
+ foo
36
+ end
37
+
17
38
  def as_json(options)
18
39
  {foo: 'bar'}
19
40
  end
@@ -81,7 +102,6 @@ describe Elasticsearch::Model::Proxy do
81
102
  end
82
103
 
83
104
  context 'when instances are cloned' do
84
-
85
105
  let!(:model) do
86
106
  DummyProxyModel.new
87
107
  end
@@ -104,4 +124,9 @@ describe Elasticsearch::Model::Proxy do
104
124
  expect(duplicate).to eq(duplicate_target)
105
125
  end
106
126
  end
127
+
128
+ it 'forwards keyword arguments to target methods' do
129
+ expect(DummyProxyModel.new.__elasticsearch__.keyword_method(foo: 'bar')).to eq('bar')
130
+ end
131
+
107
132
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Response::Aggregations do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Response::Base do