elasticsearch-model 7.0.0.pre → 7.1.2.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +41 -43
- data/Rakefile +7 -10
- data/elasticsearch-model.gemspec +37 -39
- data/examples/activerecord_associations.rb +16 -0
- data/gemfiles/4.0.gemfile +4 -3
- data/gemfiles/6.0.gemfile +3 -3
- data/lib/elasticsearch/model.rb +10 -55
- data/lib/elasticsearch/model/adapters/active_record.rb +1 -1
- data/lib/elasticsearch/model/importing.rb +43 -16
- data/lib/elasticsearch/model/indexing.rb +41 -36
- data/lib/elasticsearch/model/multimodel.rb +1 -1
- data/lib/elasticsearch/model/naming.rb +1 -10
- data/lib/elasticsearch/model/proxy.rb +41 -21
- data/lib/elasticsearch/model/response/records.rb +0 -1
- data/lib/elasticsearch/model/version.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +1 -12
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +11 -11
- data/spec/elasticsearch/model/importing_spec.rb +12 -0
- data/spec/elasticsearch/model/indexing_spec.rb +3 -33
- data/spec/elasticsearch/model/module_spec.rb +1 -0
- data/spec/spec_helper.rb +19 -5
- data/spec/support/app.rb +9 -2
- metadata +46 -48
- data/spec/elasticsearch/model/naming_inheritance_spec.rb +0 -123
@@ -1,123 +0,0 @@
|
|
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
|
-
|
18
|
-
require 'spec_helper'
|
19
|
-
|
20
|
-
describe 'naming inheritance' do
|
21
|
-
|
22
|
-
before(:all) do
|
23
|
-
class ::TestBase
|
24
|
-
extend ActiveModel::Naming
|
25
|
-
|
26
|
-
extend Elasticsearch::Model::Naming::ClassMethods
|
27
|
-
include Elasticsearch::Model::Naming::InstanceMethods
|
28
|
-
end
|
29
|
-
|
30
|
-
class ::Animal < ::TestBase
|
31
|
-
extend ActiveModel::Naming
|
32
|
-
|
33
|
-
extend Elasticsearch::Model::Naming::ClassMethods
|
34
|
-
include Elasticsearch::Model::Naming::InstanceMethods
|
35
|
-
|
36
|
-
index_name "mammals"
|
37
|
-
document_type "mammal"
|
38
|
-
end
|
39
|
-
|
40
|
-
class ::Dog < ::Animal
|
41
|
-
end
|
42
|
-
|
43
|
-
module ::MyNamespace
|
44
|
-
class Dog < ::Animal
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class ::Cat < ::Animal
|
49
|
-
extend ActiveModel::Naming
|
50
|
-
|
51
|
-
extend Elasticsearch::Model::Naming::ClassMethods
|
52
|
-
include Elasticsearch::Model::Naming::InstanceMethods
|
53
|
-
|
54
|
-
index_name "cats"
|
55
|
-
document_type "cat"
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
after(:all) do
|
61
|
-
remove_classes(TestBase, Animal, MyNamespace, Cat)
|
62
|
-
end
|
63
|
-
|
64
|
-
around(:all) do |example|
|
65
|
-
original_value = Elasticsearch::Model.settings[:inheritance_enabled]
|
66
|
-
Elasticsearch::Model.settings[:inheritance_enabled] = true
|
67
|
-
example.run
|
68
|
-
Elasticsearch::Model.settings[:inheritance_enabled] = original_value
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
describe '#index_name' do
|
73
|
-
|
74
|
-
it 'returns the default index name' do
|
75
|
-
expect(TestBase.index_name).to eq('test_bases')
|
76
|
-
expect(TestBase.new.index_name).to eq('test_bases')
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'returns the explicit index name' do
|
80
|
-
expect(Animal.index_name).to eq('mammals')
|
81
|
-
expect(Animal.new.index_name).to eq('mammals')
|
82
|
-
|
83
|
-
expect(Cat.index_name).to eq('cats')
|
84
|
-
expect(Cat.new.index_name).to eq('cats')
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'returns the ancestor index name' do
|
88
|
-
expect(Dog.index_name).to eq('mammals')
|
89
|
-
expect(Dog.new.index_name).to eq('mammals')
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'returns the ancestor index name for namespaced models' do
|
93
|
-
expect(::MyNamespace::Dog.index_name).to eq('mammals')
|
94
|
-
expect(::MyNamespace::Dog.new.index_name).to eq('mammals')
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '#document_type' do
|
99
|
-
|
100
|
-
it 'returns nil' do
|
101
|
-
expect(TestBase.document_type).to be_nil
|
102
|
-
expect(TestBase.new.document_type).to be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'returns the explicit document type' do
|
106
|
-
expect(Animal.document_type).to eq('mammal')
|
107
|
-
expect(Animal.new.document_type).to eq('mammal')
|
108
|
-
|
109
|
-
expect(Cat.document_type).to eq('cat')
|
110
|
-
expect(Cat.new.document_type).to eq('cat')
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'returns the ancestor document type' do
|
114
|
-
expect(Dog.document_type).to eq('mammal')
|
115
|
-
expect(Dog.new.document_type).to eq('mammal')
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'returns the ancestor document type for namespaced models' do
|
119
|
-
expect(::MyNamespace::Dog.document_type).to eq('mammal')
|
120
|
-
expect(::MyNamespace::Dog.new.document_type).to eq('mammal')
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|