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.
- checksums.yaml +4 -4
- data/app/controllers/krikri/records_controller.rb +2 -2
- data/app/helpers/krikri/application_helper.rb +1 -1
- data/app/models/krikri/provider.rb +137 -44
- data/app/models/krikri/qa_report.rb +1 -1
- data/app/models/krikri/validation_report.rb +3 -1
- data/app/views/krikri/providers/index.html.erb +1 -1
- data/lib/krikri/harvesters/oai_harvester.rb +6 -16
- data/lib/krikri/parser.rb +58 -7
- data/lib/krikri/version.rb +1 -1
- data/lib/tasks/krikri.rake +12 -7
- data/spec/controllers/providers_controller_spec.rb +2 -1
- data/spec/factories/krikri_provider.rb +2 -4
- data/spec/helpers/krikri/application_helper_spec.rb +2 -2
- data/spec/internal/db/test.sqlite3 +0 -0
- data/spec/internal/log/test.log +27735 -0
- data/spec/lib/krikri/harvesters/oai_harvester_spec.rb +14 -19
- data/spec/lib/krikri/parser_value_array_spec.rb +47 -4
- data/spec/lib/krikri/search_index_spec.rb +1 -0
- data/spec/models/provider_spec.rb +104 -65
- data/spec/models/qa_report_spec.rb +5 -3
- data/spec/models/validation_report_spec.rb +2 -2
- data/spec/support/shared_contexts/indexed_item.rb +17 -11
- data/spec/support/shared_examples/active_model_lint.rb +14 -0
- data/spec/views/krikri/providers/index.html.erb_spec.rb +2 -2
- data/spec/views/krikri/providers/show.html.erb_spec.rb +1 -1
- data/spec/views/krikri/reports/index.html.erb_spec.rb +1 -1
- metadata +8 -6
@@ -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
|
-
|
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
|
-
|
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
|
-
|
4
|
+
it_behaves_like 'ActiveModel'
|
12
5
|
|
13
|
-
let(:
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
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 '
|
35
|
+
shared_context 'bnode indexed in Solr' do
|
26
36
|
before do
|
27
|
-
agg.save
|
28
37
|
indexer = Krikri::QASearchIndex.new
|
29
|
-
indexer.add
|
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 '
|
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 '
|
62
|
+
context 'with valid item' do
|
63
|
+
include_context 'indexed in Solr'
|
47
64
|
|
48
|
-
it 'returns
|
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
|
67
|
+
.to contain_exactly rdf_subject
|
52
68
|
end
|
53
|
-
end
|
54
69
|
|
55
|
-
|
56
|
-
|
70
|
+
it 'assigns :name Providers' do
|
71
|
+
expect(described_class.all.map(&:name))
|
72
|
+
.to include name
|
73
|
+
end
|
74
|
+
end
|
57
75
|
|
58
|
-
|
76
|
+
context 'with bnode' do
|
77
|
+
include_context 'bnode indexed in Solr'
|
59
78
|
|
60
|
-
it '
|
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 '
|
67
|
-
include_context 'with indexed item'
|
85
|
+
describe '#find' do
|
68
86
|
|
69
|
-
it '
|
70
|
-
expect(described_class.find(
|
87
|
+
it 'returns nil if item not found' do
|
88
|
+
expect(described_class.find(id)).to eq nil
|
71
89
|
end
|
72
90
|
|
73
|
-
|
74
|
-
|
75
|
-
.to eq provider.count
|
76
|
-
end
|
91
|
+
context 'with item' do
|
92
|
+
include_context 'indexed in Solr'
|
77
93
|
|
78
|
-
|
79
|
-
|
80
|
-
|
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 '#
|
85
|
-
include_context 'with indexed item'
|
104
|
+
describe '#base_uri' do
|
86
105
|
|
87
|
-
it '
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
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 '
|
101
|
-
expect(
|
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 '#
|
106
|
-
|
107
|
-
|
108
|
-
|
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 '
|
112
|
-
|
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 '
|
117
|
-
expect(
|
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 '
|
121
|
-
|
122
|
-
|
123
|
-
|
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! '
|
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
|
54
|
-
expect(subject.build_provider).to be_a
|
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
|
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
|
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
|
-
|
19
|
-
|
20
|
-
a.set_subject! 'moomin'
|
21
|
-
a
|
22
|
-
end
|
18
|
+
provider_agent = provider.agent
|
19
|
+
provider_agent.label = provider.name
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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:
|
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
|