krikri 0.7.2 → 0.7.3

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.
@@ -188,6 +188,20 @@ EOM
188
188
  :headers => {})
189
189
  end
190
190
 
191
+ it 'produces valid xml' do
192
+ expect do
193
+ Nokogiri::XML(subject.records.first.content) do |config|
194
+ config.options = Nokogiri::XML::ParseOptions::STRICT
195
+ end
196
+ end.not_to raise_error
197
+ end
198
+
199
+ it 'produces has oai namespace and header' do
200
+ expect(Nokogiri::XML(subject.records.first.content)
201
+ .xpath('//xmlns:header'))
202
+ .not_to be_empty
203
+ end
204
+
191
205
  it 'retries timed out requests' do
192
206
  expect_any_instance_of(Faraday::Adapter::NetHttp)
193
207
  .to receive(:perform_request).at_least(4).times
@@ -411,25 +425,6 @@ EOM
411
425
  end
412
426
  end
413
427
 
414
- describe '#record_xml' do
415
- let(:oai_record) { OAI::Record.new('') }
416
-
417
- it 'produces valid xml' do
418
- expect do
419
- Nokogiri::XML(subject.send(:record_xml, oai_record)) do |config|
420
- config.options = Nokogiri::XML::ParseOptions::STRICT
421
- end
422
- end.not_to raise_error
423
- end
424
-
425
- it 'sets header status' do
426
- allow(oai_record.header).to receive(:status).and_return('deleted')
427
- node = Nokogiri::XML(subject.send(:record_xml, oai_record))
428
- .at_css('header')
429
- expect(node['status']).to eq 'deleted'
430
- end
431
- end
432
-
433
428
  describe 'concat_enum' do
434
429
  it 'concatenates enums' do
435
430
  expect(subject.concat_enum([(1..10), (100..110)]).to_a)
@@ -238,18 +238,61 @@ describe Krikri::Parser::ValueArray do
238
238
  end
239
239
  end
240
240
 
241
- describe '#match_attribute' do
241
+ shared_context 'with attributes' do
242
242
  before do
243
243
  values.each { |val| allow(val).to receive(:attribute?).and_return(false) }
244
- end
245
244
 
246
- it 'selects values by their attributes' do
247
245
  allow(values[0]).to receive(:attribute?).with(:type).and_return(true)
248
246
  allow(values[0]).to receive(:type).and_return('Moomin')
249
247
  allow(values[1]).to receive(:attribute?).with(:type).and_return(true)
250
248
  allow(values[1]).to receive(:type).and_return('mummi')
251
- expect(subject.match_attribute(:type, 'moomin'))
249
+ end
250
+ end
251
+
252
+ describe '#match_attribute' do
253
+ include_context 'with attributes'
254
+
255
+ it 'selects values by presence of attributes' do
256
+ expect(subject.match_attribute(:type))
257
+ .to contain_exactly(values[0], values[1])
258
+ end
259
+
260
+ it 'selects values by attribute values matching other' do
261
+ expect(subject.match_attribute(:type, 'Moomin'))
252
262
  .to contain_exactly(values[0])
253
263
  end
264
+
265
+ it 'selects according to a given block' do
266
+ expect(subject.match_attribute(:type) { |v| v.starts_with?('mu') })
267
+ .to contain_exactly(values[1])
268
+ end
269
+
270
+ it 'selects according to a given block and comparison to other' do
271
+ expect(subject.match_attribute(:type, 'moomin') { |v| v.downcase })
272
+ .to contain_exactly(values[0])
273
+ end
274
+ end
275
+
276
+ describe '#reject_attribute' do
277
+ include_context 'with attributes'
278
+
279
+ it 'rejects values by presence of attributes' do
280
+ expect(subject.reject_attribute(:type)).to contain_exactly(values[2])
281
+ end
282
+
283
+ it 'selects values by attribute values matching other' do
284
+ expect(subject.reject_attribute(:type, 'Moomin'))
285
+ .to contain_exactly(values[1], values[2])
286
+ end
287
+
288
+ it 'selects according to a given block' do
289
+ expect(subject.reject_attribute(:type) { |v| v.starts_with?('mu') })
290
+ .to contain_exactly(values[0], values[2])
291
+ end
292
+
293
+ it 'selects according to a given block and comparison to other' do
294
+ expect(subject.reject_attribute(:type, 'moomin') { |v| v.downcase })
295
+ .to contain_exactly(values[1], values[2])
296
+ end
254
297
  end
255
298
  end
@@ -117,6 +117,7 @@ describe Krikri::QASearchIndex do
117
117
  subject.commit
118
118
  aggregation.set_subject!('http://api.dp.la/item/123')
119
119
  aggregation.provider << build(:krikri_provider, rdf_subject: 'snork')
120
+ .agent
120
121
  subject.add aggregation.to_jsonld['@graph'][0]
121
122
  subject.commit
122
123
  end
@@ -1,32 +1,41 @@
1
1
  require 'spec_helper'
2
- require 'rdf/isomorphic'
3
-
4
- module RDF
5
- module Isomorphic
6
- alias_method :==, :isomorphic_with?
7
- end
8
- end
9
2
 
10
3
  describe Krikri::Provider do
11
- let(:local_name) { '123' }
4
+ it_behaves_like 'ActiveModel'
12
5
 
13
- let(:provider) do
14
- provider = Krikri::Provider.new(local_name)
15
- provider.providedLabel = "moomin"
16
- provider
17
- end
6
+ let(:provider_base) { Krikri::Settings.prov.provider_base }
7
+ let(:id) { '123' }
8
+ let(:rdf_subject) { provider_base + id }
9
+ let(:name) { 'Snork Maiden Archives' }
18
10
 
19
11
  let(:agg) do
20
- a = build(:aggregation, :provider => provider)
21
- a.set_subject! 'moomin'
22
- a
12
+ p = DPLA::MAP::Agent.new(RDF::URI(provider_base) / id)
13
+ p.label = name
14
+ build(:aggregation, :provider => p)
15
+ end
16
+
17
+ let(:bnode) do
18
+ p = DPLA::MAP::Agent.new
19
+ build(:aggregation, :provider => p)
20
+ end
21
+
22
+ shared_context 'indexed in Solr' do
23
+ before do
24
+ clear_search_index
25
+ indexer = Krikri::QASearchIndex.new
26
+ indexer.add agg.to_jsonld['@graph'].first
27
+ indexer.commit
28
+ end
29
+
30
+ after do
31
+ clear_search_index
32
+ end
23
33
  end
24
34
 
25
- shared_context 'with indexed item' do
35
+ shared_context 'bnode indexed in Solr' do
26
36
  before do
27
- agg.save
28
37
  indexer = Krikri::QASearchIndex.new
29
- indexer.add(agg.to_jsonld['@graph'].first)
38
+ indexer.add bnode.to_jsonld['@graph'].first
30
39
  indexer.commit
31
40
  end
32
41
 
@@ -37,90 +46,120 @@ describe Krikri::Provider do
37
46
  end
38
47
  end
39
48
 
40
- describe '.all' do
49
+ describe '#initialize' do
50
+
51
+ it 'sets given attributes' do
52
+ expect(described_class.new({ rdf_subject: rdf_subject }).rdf_subject)
53
+ .to eq rdf_subject
54
+ end
55
+ end
56
+
57
+ describe '#all' do
41
58
  it 'with no items is empty' do
42
59
  expect(described_class.all).to be_empty
43
60
  end
44
61
 
45
- context 'with item' do
46
- include_context 'with indexed item'
62
+ context 'with valid item' do
63
+ include_context 'indexed in Solr'
47
64
 
48
- it 'returns all items' do
49
- # todo: ActiveTriples::Resource equality needs work
65
+ it 'returns valid item' do
50
66
  expect(described_class.all.map(&:rdf_subject))
51
- .to contain_exactly provider.rdf_subject
67
+ .to contain_exactly rdf_subject
52
68
  end
53
- end
54
69
 
55
- context 'with bnode provider' do
56
- include_context 'with indexed item'
70
+ it 'assigns :name Providers' do
71
+ expect(described_class.all.map(&:name))
72
+ .to include name
73
+ end
74
+ end
57
75
 
58
- let(:provider) { DPLA::MAP::Agent.new }
76
+ context 'with bnode' do
77
+ include_context 'bnode indexed in Solr'
59
78
 
60
- it 'ignores bnodes' do
79
+ it 'ingnores bnode' do
61
80
  expect(described_class.all).to be_empty
62
81
  end
63
82
  end
64
83
  end
65
84
 
66
- describe '.find' do
67
- include_context 'with indexed item'
85
+ describe '#find' do
68
86
 
69
- it 'finds the provider' do
70
- expect(described_class.find(local_name)).to eq provider
87
+ it 'returns nil if item not found' do
88
+ expect(described_class.find(id)).to eq nil
71
89
  end
72
90
 
73
- it 'populates graph' do
74
- expect(described_class.find(local_name).count)
75
- .to eq provider.count
76
- end
91
+ context 'with item' do
92
+ include_context 'indexed in Solr'
77
93
 
78
- it 'returns property values' do
79
- expect(described_class.find(local_name).providedLabel)
80
- .to eq provider.providedLabel
94
+ it 'finds the provider with a given :id' do
95
+ expect(described_class.find(id).name).to eq name
96
+ end
97
+
98
+ it 'finds the provider with a given :rdf_subject' do
99
+ expect(described_class.find(rdf_subject).name).to eq name
100
+ end
81
101
  end
82
102
  end
83
103
 
84
- describe '#records' do
85
- include_context 'with indexed item'
104
+ describe '#base_uri' do
86
105
 
87
- it 'gives the record' do
88
- # @todo fix once {ActiveTriples::RDFSource} equality is figured out
89
- expect(provider.records.map(&:rdf_subject))
90
- .to contain_exactly agg.rdf_subject
106
+ it 'adds trailing "/" to provider_base if missing' do
107
+ allow(Krikri::Settings).to receive_message_chain('prov.provider_base')
108
+ .and_return 'http://example.com/abc'
109
+ expect(described_class.base_uri).to eq('http://example.com/abc/')
91
110
  end
92
111
  end
93
112
 
94
113
  describe '#id' do
95
- it 'gives a valid id for initializing resource' do
96
- expect(Krikri::Provider.new(provider.id).rdf_subject)
97
- .to eq provider.rdf_subject
114
+
115
+ it 'returns an :id parsed from :rdf_subject' do
116
+ expect(described_class.new({ rdf_subject: rdf_subject }).id).to eq id
98
117
  end
99
118
 
100
- it 'does not include the base uri' do
101
- expect(provider.id).not_to include provider.base_uri
119
+ it 'returns nil without valid :rdf_subject' do
120
+ expect(described_class.new.id).to eq nil
102
121
  end
103
122
  end
104
123
 
105
- describe '#provider_name' do
106
- it 'gives prefLabel if present' do
107
- provider.label = 'littly my'
108
- expect(provider.provider_name).to eq provider.label.first
124
+ describe '#name' do
125
+ include_context 'indexed in Solr'
126
+
127
+ it 'returns an :name corresponding to the indexed :rdf_subject' do
128
+ expect(described_class.new({ rdf_subject: rdf_subject }).name).to eq name
109
129
  end
110
130
 
111
- it 'with multiple labels gives just one' do
112
- provider.label = ['little my', 'snork']
113
- expect(provider.provider_name).to eq provider.label.first
131
+ it 'returns nil without valid :rdf_subject' do
132
+ expect(described_class.new.name).to eq nil
114
133
  end
134
+ end
135
+
136
+ describe '#agent' do
137
+ include_context 'indexed in Solr'
115
138
 
116
- it 'gives providedLabel if no prefLabel present' do
117
- expect(provider.provider_name).to eq provider.providedLabel.first
139
+ it 'returns a DPLA::MAP::Agent object' do
140
+ expect(described_class.find(rdf_subject).agent)
141
+ .to be_a DPLA::MAP::Agent
118
142
  end
119
143
 
120
- it 'gives `#id` with with no labels' do
121
- provider.label = nil
122
- provider.providedLabel = nil
123
- expect(provider.provider_name).to eq provider.id
144
+ it 'assigns :rdf_subject to agent' do
145
+ agent = (described_class.find(rdf_subject).agent)
146
+ expect(agent.rdf_subject.to_s).to eq rdf_subject
147
+ end
148
+
149
+ it 'assigns :name to agent' do
150
+ agent = (described_class.find(rdf_subject).agent)
151
+ expect(agent.label.first).to eq name
152
+ end
153
+
154
+ it 'returns nil without valid :rdf_subject' do
155
+ expect(described_class.new.agent).to eq nil
156
+ end
157
+ end
158
+
159
+ describe '#valid_rdf_subject?' do
160
+ it 'recognizes bnodes' do
161
+ provider = Krikri::Provider.new({ rdf_subject: '_:b1' })
162
+ expect(provider.valid_rdf_subject?).to eq false
124
163
  end
125
164
  end
126
165
  end
@@ -4,9 +4,11 @@ describe Krikri::QAReport do
4
4
 
5
5
  subject { described_class.new(:provider => provider.id.to_s) }
6
6
 
7
+ let(:provider_base) { Krikri::Provider.base_uri }
8
+
7
9
  let(:provider) do
8
10
  agent = build(:agent)
9
- agent.set_subject! 'http://example.org/moomin'
11
+ agent.set_subject!(provider_base + 'moomin')
10
12
  agent
11
13
  end
12
14
 
@@ -50,8 +52,8 @@ describe Krikri::QAReport do
50
52
  end
51
53
 
52
54
  describe '#build_provider' do
53
- it 'gives a provider' do
54
- expect(subject.build_provider).to be_a Krikri::Provider
55
+ it 'gives a DPLA::MAP::Agent' do
56
+ expect(subject.build_provider).to be_a DPLA::MAP::Agent
55
57
  end
56
58
 
57
59
  it 'gives provider with correct uri' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Krikri::ValidationReport do
4
- describe `#all` do
4
+ describe '#all' do
5
5
  it 'returns facet for each required field' do
6
6
  count = described_class::REQUIRED_FIELDS.count
7
7
  facet_field_const = Blacklight::SolrResponse::Facets::FacetField
@@ -23,7 +23,7 @@ describe Krikri::ValidationReport do
23
23
  end
24
24
  end
25
25
 
26
- describe `#find` do
26
+ describe '#find' do
27
27
  it 'gives a blacklight solr response' do
28
28
  expect(subject.find('sourceResource_title'))
29
29
  .to be_a Blacklight::SolrResponse
@@ -15,17 +15,15 @@ shared_context 'with indexed item' do
15
15
  let(:records) { [agg] }
16
16
 
17
17
  let(:agg) do
18
- a = build(:aggregation)
19
- a.provider = provider
20
- a.set_subject! 'moomin'
21
- a
22
- end
18
+ provider_agent = provider.agent
19
+ provider_agent.label = provider.name
23
20
 
24
- let(:provider) do
25
- build(:krikri_provider,
26
- rdf_subject: 'moomin_valley',
27
- label: 'moomin valley')
21
+ aggregation = build(:aggregation, provider: provider_agent)
22
+ aggregation.set_subject! 'moomin'
23
+ aggregation
28
24
  end
25
+
26
+ let(:provider) { build(:krikri_provider) }
29
27
  end
30
28
 
31
29
  shared_context 'with missing values' do
@@ -33,14 +31,22 @@ shared_context 'with missing values' do
33
31
  let(:records) { [agg, empty, empty_new_provider] }
34
32
 
35
33
  let(:empty) do
36
- aggregation = build(:aggregation, provider: provider, sourceResource: nil)
34
+ provider_agent = provider.agent
35
+ provider_agent.label = provider.name
36
+
37
+ aggregation = build(:aggregation,
38
+ provider: provider_agent,
39
+ sourceResource: nil)
37
40
  aggregation.set_subject! 'empty'
38
41
  aggregation
39
42
  end
40
43
 
41
44
  let(:empty_new_provider) do
45
+ provider_agent = build(:krikri_provider,
46
+ rdf_subject: 'http://example.com/fake').agent
47
+
42
48
  aggregation = build(:aggregation,
43
- provider: RDF::URI('http://example.com/fake'),
49
+ provider: provider_agent,
44
50
  sourceResource: nil)
45
51
  aggregation.set_subject! 'empty_new_provider'
46
52
  aggregation
@@ -0,0 +1,14 @@
1
+ shared_examples 'ActiveModel' do
2
+ include ActiveModel::Lint::Tests
3
+
4
+ # to_s is to support ruby-1.9
5
+ ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
6
+ example m.gsub('_',' ') do
7
+ send m
8
+ end
9
+ end
10
+
11
+ def model
12
+ subject
13
+ end
14
+ end