ladder 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,221 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ladder::Searchable::Resource do
4
- before do
5
- Mongoid.load!('mongoid.yml', :development)
6
- Mongoid.logger.level = Moped.logger.level = Logger::DEBUG
7
- Mongoid.purge!
8
-
9
- Elasticsearch::Model.client = Elasticsearch::Client.new host: 'localhost:9200', log: true
10
- Elasticsearch::Model.client.indices.delete index: '_all'
11
-
12
- LADDER_BASE_URI = 'http://example.org'
13
-
14
- class Thing
15
- include Ladder::Resource
16
- include Ladder::Searchable
17
- end
18
-
19
- class Person
20
- include Ladder::Resource
21
- include Ladder::Searchable
22
- end
23
- end
24
-
25
- it_behaves_like 'a Resource'
26
-
27
- let(:subject) { Thing.new }
28
- let(:person) { Person.new }
29
-
30
- shared_context 'with data' do
31
- before do
32
- subject.class.configure type: RDF::DC.BibliographicResource
33
- subject.class.property :title, :predicate => RDF::DC.title
34
- subject.title = 'Comet in Moominland'
35
- end
36
- end
37
-
38
- describe '#index_for_search' do
39
- include_context 'with data'
40
-
41
- context 'with default' do
42
- before do
43
- subject.class.index_for_search
44
- subject.save
45
- Elasticsearch::Model.client.indices.flush
46
- end
47
-
48
- it 'should exist in the index' do
49
- results = subject.class.search('title:moomin*')
50
- expect(results.count).to eq 1
51
- expect(results.first._source.to_hash).to eq JSON.parse(subject.as_indexed_json.to_json)
52
- end
53
- end
54
-
55
- context 'with as qname' do
56
- before do
57
- subject.class.index_for_search as: :qname
58
- subject.save
59
- Elasticsearch::Model.client.indices.flush
60
- end
61
-
62
- it 'should exist in the index' do
63
- results = subject.class.search('dc.title.en:moomin*')
64
- expect(results.count).to eq 1
65
- expect(results.first._source.to_hash).to eq JSON.parse(subject.as_qname.to_json)
66
- end
67
- end
68
-
69
- context 'with as jsonld' do
70
- before do
71
- subject.class.index_for_search as: :jsonld
72
- subject.save
73
- Elasticsearch::Model.client.indices.flush
74
- end
75
-
76
- it 'should exist in the index' do
77
- results = subject.class.search('dc\:title.@value:moomin*')
78
- expect(results.count).to eq 1
79
- expect(results.first._source.to_hash).to eq subject.as_jsonld
80
- end
81
- end
82
- end
83
-
84
- describe '#index_for_search related' do
85
- include_context 'with data'
86
-
87
- before do
88
- # related object
89
- person.class.configure type: RDF::FOAF.Person
90
- person.class.property :foaf_name, :predicate => RDF::FOAF.name
91
- person.foaf_name = 'Tove Jansson'
92
-
93
- # many-to-many relation
94
- person.class.property :things, :predicate => RDF::DC.relation, :class_name => 'Thing'
95
- subject.class.property :people, :predicate => RDF::DC.creator, :class_name => 'Person'
96
- subject.people << person
97
- end
98
-
99
- context 'with default' do
100
- before do
101
- person.class.index_for_search
102
- subject.class.index_for_search
103
- subject.save
104
- Elasticsearch::Model.client.indices.flush
105
- end
106
-
107
- it 'should contain an ID for the related object' do
108
- results = subject.class.search('person_ids.$oid:' + person.id)
109
- expect(results.count).to eq 1
110
- end
111
-
112
- it 'should include the related object in the index' do
113
- results = person.class.search('foaf_name:tove')
114
- expect(results.count).to eq 1
115
- expect(results.first._source.to_hash).to eq JSON.parse(person.as_indexed_json.to_json)
116
- end
117
-
118
- it 'should contain an ID for the subject' do
119
- results = person.class.search('thing_ids.$oid:' + subject.id)
120
- expect(results.count).to eq 1
121
- end
122
- end
123
-
124
- context 'with as qname' do
125
- before do
126
- person.class.index_for_search as: :qname
127
- subject.class.index_for_search as: :qname
128
- subject.save
129
- Elasticsearch::Model.client.indices.flush
130
- end
131
-
132
- it 'should contain an ID for the related object' do
133
- results = subject.class.search('dc.creator:' + person.id)
134
- expect(results.count).to eq 1
135
- end
136
-
137
- it 'should include the related object in the index' do
138
- results = person.class.search('foaf.name.en:tove')
139
- expect(results.count).to eq 1
140
- expect(results.first._source.to_hash).to eq JSON.parse(person.as_qname.to_json)
141
- end
142
-
143
- it 'should contain an ID for the subject' do
144
- results = person.class.search('dc.relation:' + subject.id)
145
- expect(results.count).to eq 1
146
- end
147
- end
148
-
149
- context 'with as_qname related' do
150
- before do
151
- person.class.index_for_search as: :qname, related: true
152
- subject.class.index_for_search as: :qname, related: true
153
- subject.save
154
- Elasticsearch::Model.client.indices.flush
155
- end
156
-
157
- it 'should contain a embedded related object' do
158
- results = subject.class.search('dc.creator.foaf.name.en:tove')
159
- expect(results.count).to eq 1
160
- expect(results.first._source['dc']['creator'].first).to eq Hashie::Mash.new person.as_qname
161
- end
162
-
163
- it 'should contain an embedded subject in the related object' do
164
- results = person.class.search('dc.relation.dc.title.en:moomin*')
165
- expect(results.count).to eq 1
166
- expect(results.first._source['dc']['relation'].first).to eq Hashie::Mash.new subject.as_qname
167
- end
168
- end
169
-
170
- context 'with as_jsonld' do
171
- before do
172
- person.class.index_for_search as: :jsonld
173
- subject.class.index_for_search as: :jsonld
174
- subject.save
175
- Elasticsearch::Model.client.indices.flush
176
- end
177
-
178
- it 'should contain an ID for the related object' do
179
- results = subject.class.search('dc\:creator.@id:' + person.id)
180
- expect(results.count).to eq 1
181
- end
182
-
183
- it 'should include the related object in the index' do
184
- results = person.class.search('foaf\:name.@value:tove')
185
- expect(results.count).to eq 1
186
- expect(results.first._source.to_hash).to eq person.as_jsonld
187
- end
188
-
189
- it 'should contain an ID for the subject' do
190
- results = person.class.search('dc\:relation.@id:' + subject.id)
191
- expect(results.count).to eq 1
192
- end
193
- end
194
-
195
- context 'with as_jsonld related' do
196
- before do
197
- person.class.index_for_search as: :jsonld, related: true
198
- subject.class.index_for_search as: :jsonld, related: true
199
- subject.save
200
- Elasticsearch::Model.client.indices.flush
201
- end
202
-
203
- it 'should contain a embedded related object' do
204
- results = subject.class.search('dc\:creator.foaf\:name.@value:tove')
205
- expect(results.count).to eq 1
206
- expect(results.first._source.to_hash['dc:creator']).to eq person.as_jsonld.except '@context'
207
- end
208
-
209
- it 'should contain an embedded subject in the related object' do
210
- results = person.class.search('dc\:relation.dc\:title.@value:moomin*')
211
- expect(results.count).to eq 1
212
- expect(results.first._source.to_hash['dc:relation']).to eq subject.as_jsonld.except '@context'
213
- end
214
- end
215
- end
216
-
217
- after do
218
- Object.send(:remove_const, "Thing") if Object
219
- Object.send(:remove_const, "Person") if Object
220
- end
221
- end