qa 2.0.1 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -3
- data/app/controllers/qa/application_controller.rb +22 -0
- data/app/controllers/qa/linked_data_terms_controller.rb +16 -10
- data/app/controllers/qa/terms_controller.rb +7 -2
- data/app/models/qa/mesh_tree.rb +5 -9
- data/app/models/qa/subject_mesh_term.rb +2 -7
- data/config/initializers/linked_data_authorities.rb +1 -1
- data/config/routes.rb +8 -0
- data/lib/generators/qa/install/install_generator.rb +4 -0
- data/lib/generators/qa/install/templates/config/initializers/qa.rb +7 -0
- data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +1 -1
- data/lib/generators/qa/local/tables/tables_generator.rb +1 -1
- data/lib/qa.rb +16 -0
- data/lib/qa/authorities/assign_fast_subauthority.rb +3 -3
- data/lib/qa/authorities/getty/tgn.rb +1 -1
- data/lib/qa/authorities/getty/ulan.rb +1 -1
- data/lib/qa/authorities/linked_data/find_term.rb +2 -2
- data/lib/qa/authorities/linked_data/rdf_helper.rb +15 -0
- data/lib/qa/authorities/linked_data/search_query.rb +19 -3
- data/lib/qa/authorities/loc_subauthority.rb +2 -2
- data/lib/qa/authorities/local.rb +2 -4
- data/lib/qa/authorities/local/file_based_authority.rb +1 -1
- data/lib/qa/authorities/local/mysql_table_based_authority.rb +11 -2
- data/lib/qa/authorities/local/table_based_authority.rb +2 -1
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +1 -1
- data/lib/qa/authorities/mesh_tools/mesh_importer.rb +1 -1
- data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +1 -3
- data/lib/qa/configuration.rb +16 -0
- data/lib/qa/version.rb +1 -1
- data/lib/tasks/mesh.rake +3 -3
- data/spec/controllers/linked_data_terms_controller_spec.rb +65 -14
- data/spec/controllers/terms_controller_spec.rb +85 -10
- data/spec/fixtures/{lexvo_snippet.rdf → lexvo_snippet.rdf.xml} +1 -0
- data/spec/lib/authorities/assign_fast_spec.rb +3 -1
- data/spec/lib/authorities/file_based_authority_spec.rb +19 -11
- data/spec/lib/authorities/geonames_spec.rb +3 -3
- data/spec/lib/authorities/getty/aat_spec.rb +2 -1
- data/spec/lib/authorities/getty/tgn_spec.rb +6 -2
- data/spec/lib/authorities/getty/ulan_spec.rb +4 -2
- data/spec/lib/authorities/getty_spec.rb +2 -1
- data/spec/lib/authorities/linked_data/generic_authority_spec.rb +54 -12
- data/spec/lib/authorities/linked_data/search_config_spec.rb +23 -19
- data/spec/lib/authorities/linked_data/search_query_spec.rb +67 -15
- data/spec/lib/authorities/linked_data/term_config_spec.rb +24 -20
- data/spec/lib/authorities/local_spec.rb +7 -8
- data/spec/lib/authorities/oclcts_spec.rb +27 -20
- data/spec/lib/authorities/table_based_authority_spec.rb +5 -3
- data/spec/lib/authorities_loc_subauthorities.rb +2 -2
- data/spec/lib/mesh_data_parser_spec.rb +2 -0
- data/spec/lib/services/rdf_authority_parser_spec.rb +1 -1
- data/spec/lib/tasks/mesh.rake_spec.rb +13 -12
- data/spec/models/subject_mesh_term_spec.rb +2 -0
- data/spec/requests/cors_headers_spec.rb +118 -0
- data/spec/spec_helper.rb +2 -2
- metadata +133 -142
@@ -48,7 +48,9 @@ describe Qa::Authorities::AssignFast do
|
|
48
48
|
.to_return(status: 200, body: "", headers: {})
|
49
49
|
end
|
50
50
|
it "logs an info and returns an empty array" do
|
51
|
-
|
51
|
+
msg = "Could not parse response as JSON. Request url: " \
|
52
|
+
"http://fast.oclc.org/searchfast/fastsuggest?&query=word%20ling&queryIndex=suggestall&queryReturn=suggestall%2Cidroot%2Cauth%2Ctype&suggest=autoSubject&rows=20"
|
53
|
+
expect(Rails.logger).to receive(:info).with(msg)
|
52
54
|
results = authority.search("word (ling")
|
53
55
|
expect(results).to eq([])
|
54
56
|
end
|
@@ -7,24 +7,30 @@ describe Qa::Authorities::Local::FileBasedAuthority do
|
|
7
7
|
let(:authority_d) { Qa::Authorities::Local.subauthority_for("authority_D") }
|
8
8
|
|
9
9
|
describe "#all" do
|
10
|
-
let(:expected)
|
11
|
-
|
12
|
-
|
10
|
+
let(:expected) do
|
11
|
+
[{ 'id' => "A1", 'label' => "Abc Term A1", 'active' => true },
|
12
|
+
{ 'id' => "A2", 'label' => "Term A2", 'active' => false },
|
13
|
+
{ 'id' => "A3", 'label' => "Abc Term A3", 'active' => true }]
|
14
|
+
end
|
13
15
|
it "returns all the entries" do
|
14
16
|
expect(authority_a.all).to eq(expected)
|
15
17
|
end
|
16
18
|
context "when terms do not have ids" do
|
17
|
-
let(:expected)
|
18
|
-
|
19
|
-
|
19
|
+
let(:expected) do
|
20
|
+
[{ 'id' => "Term B1", 'label' => "Term B1", 'active' => true },
|
21
|
+
{ 'id' => "Term B2", 'label' => "Term B2", 'active' => true },
|
22
|
+
{ 'id' => "Term B3", 'label' => "Term B3", 'active' => true }]
|
23
|
+
end
|
20
24
|
it "sets the id to be same as the label" do
|
21
25
|
expect(authority_b.all).to eq(expected)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
context "authority YAML file is a list of terms" do
|
25
|
-
let(:expected)
|
26
|
-
|
27
|
-
|
29
|
+
let(:expected) do
|
30
|
+
[{ 'id' => "Term C1", 'label' => "Term C1", 'active' => true },
|
31
|
+
{ 'id' => "Term C2", 'label' => "Term C2", 'active' => true },
|
32
|
+
{ 'id' => "Term C3", 'label' => "Term C3", 'active' => true }]
|
33
|
+
end
|
28
34
|
it "uses the terms as labels" do
|
29
35
|
expect(authority_c.all).to eq(expected)
|
30
36
|
end
|
@@ -44,8 +50,10 @@ describe Qa::Authorities::Local::FileBasedAuthority do
|
|
44
50
|
end
|
45
51
|
end
|
46
52
|
context "with at least one matching entry" do
|
47
|
-
let(:expected)
|
48
|
-
|
53
|
+
let(:expected) do
|
54
|
+
[{ 'id' => "A1", 'label' => "Abc Term A1" },
|
55
|
+
{ 'id' => "A3", 'label' => "Abc Term A3" }]
|
56
|
+
end
|
49
57
|
it "returns only entries matching the query term" do
|
50
58
|
expect(authority_a.search("Abc")).to eq(expected)
|
51
59
|
end
|
@@ -37,12 +37,12 @@ describe Qa::Authorities::Geonames do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context "with custom label" do
|
40
|
+
let!(:original_label) { described_class.label }
|
40
41
|
before do
|
41
|
-
|
42
|
-
described_class.label = -> (item) { item['name'] }
|
42
|
+
described_class.label = ->(item) { item['name'] }
|
43
43
|
end
|
44
44
|
after do
|
45
|
-
described_class.label =
|
45
|
+
described_class.label = original_label
|
46
46
|
end
|
47
47
|
it "uses the lambda" do
|
48
48
|
expect(subject.first['label']).to eq("Port Moresby")
|
@@ -68,7 +68,8 @@ describe Qa::Authorities::Getty::AAT do
|
|
68
68
|
|
69
69
|
describe "#sparql" do
|
70
70
|
subject { authority.sparql('search_term') }
|
71
|
-
it {
|
71
|
+
it {
|
72
|
+
is_expected.to eq 'SELECT ?s ?name {
|
72
73
|
?s a skos:Concept; luc:term "search_term";
|
73
74
|
skos:inScheme <http://vocab.getty.edu/aat/> ;
|
74
75
|
gvp:prefLabelGVP [skosxl:literalForm ?name].
|
@@ -69,7 +69,8 @@ describe Qa::Authorities::Getty::TGN do
|
|
69
69
|
describe "#sparql" do
|
70
70
|
context "using a single subject term" do
|
71
71
|
subject { authority.sparql('search_term') }
|
72
|
-
it {
|
72
|
+
it {
|
73
|
+
is_expected.to eq 'SELECT DISTINCT ?s ?name ?par {
|
73
74
|
?s a skos:Concept; luc:term "search_term";
|
74
75
|
skos:inScheme <http://vocab.getty.edu/tgn/> ;
|
75
76
|
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
|
@@ -79,13 +80,16 @@ describe Qa::Authorities::Getty::TGN do
|
|
79
80
|
end
|
80
81
|
context "using a two subject terms" do
|
81
82
|
subject { authority.sparql('search term') }
|
82
|
-
|
83
|
+
# rubocop:disable Metrics/LineLength
|
84
|
+
it {
|
85
|
+
is_expected.to eq "SELECT DISTINCT ?s ?name ?par {
|
83
86
|
?s a skos:Concept; luc:term \"search term\";
|
84
87
|
skos:inScheme <http://vocab.getty.edu/tgn/> ;
|
85
88
|
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
|
86
89
|
gvp:parentString ?par .
|
87
90
|
FILTER ((regex(CONCAT(?name, ', ', REPLACE(str(?par), \",[^,]+,[^,]+$\", \"\")), \"search\",\"i\" ) && regex(CONCAT(?name, ', ', REPLACE(str(?par), \",[^,]+,[^,]+$\", \"\")), \"term\",\"i\" ) ) && (regex(?name, \"search\",\"i\" ) || regex(?name, \"term\",\"i\" ) ) ) .
|
88
91
|
} ORDER BY ?name ASC(?par)" }
|
92
|
+
# rubocop:enable Metrics/LineLength
|
89
93
|
end
|
90
94
|
end
|
91
95
|
end
|
@@ -69,7 +69,8 @@ describe Qa::Authorities::Getty::Ulan do
|
|
69
69
|
describe "#sparql" do
|
70
70
|
context "using a single subject term" do
|
71
71
|
subject { authority.sparql('search_term') }
|
72
|
-
it {
|
72
|
+
it {
|
73
|
+
is_expected.to eq 'SELECT DISTINCT ?s ?name ?bio {
|
73
74
|
?s a skos:Concept; luc:term "search_term";
|
74
75
|
skos:inScheme <http://vocab.getty.edu/ulan/> ;
|
75
76
|
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
|
@@ -80,7 +81,8 @@ describe Qa::Authorities::Getty::Ulan do
|
|
80
81
|
end
|
81
82
|
context "using a two subject terms" do
|
82
83
|
subject { authority.sparql('search term') }
|
83
|
-
it {
|
84
|
+
it {
|
85
|
+
is_expected.to eq "SELECT DISTINCT ?s ?name ?bio {
|
84
86
|
?s a skos:Concept; luc:term \"search term\";
|
85
87
|
skos:inScheme <http://vocab.getty.edu/ulan/> ;
|
86
88
|
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
|
@@ -3,7 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Qa::Authorities::Getty do
|
4
4
|
describe "#new" do
|
5
5
|
it "raises an exception" do
|
6
|
-
|
6
|
+
msg = "Initializing with as sub authority is removed. use Module.subauthority_for(nil) instead"
|
7
|
+
expect { described_class.new }.to raise_error RuntimeError, msg
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
@@ -93,6 +93,7 @@ RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
|
93
93
|
# # let(:lod_loc) { Qa::Authorities::LinkedData::GenericAuthority.new(:LOC) }
|
94
94
|
# end
|
95
95
|
|
96
|
+
# rubocop:disable RSpec/NestedGroups
|
96
97
|
describe "language processing" do
|
97
98
|
context "when filtering #search results" do
|
98
99
|
context "and lang NOT passed in" do
|
@@ -184,6 +185,7 @@ RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
|
184
185
|
end
|
185
186
|
end
|
186
187
|
end
|
188
|
+
# rubocop:enable RSpec/NestedGroups
|
187
189
|
end
|
188
190
|
|
189
191
|
describe '#find' do
|
@@ -195,7 +197,7 @@ RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
|
195
197
|
context 'with bad id' do
|
196
198
|
before do
|
197
199
|
stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID')
|
198
|
-
.to_return(status: 404, body: '', headers:
|
200
|
+
.to_return(status: 404, body: '', headers: {})
|
199
201
|
end
|
200
202
|
it 'raises a TermNotFound exception' do
|
201
203
|
expect { lod_oclc.find('FAKE_ID') }.to raise_error Qa::TermNotFound, /.*\/FAKE_ID\ Not Found - Term may not exist at LOD Authority./
|
@@ -256,14 +258,19 @@ RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
|
256
258
|
it 'has primary predicates in pred-obj list' do
|
257
259
|
expect(results['predicates']['http://purl.org/dc/terms/identifier']).to eq ['530369']
|
258
260
|
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#prefLabel']).to eq ['Cornell University']
|
259
|
-
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#altLabel'])
|
261
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#altLabel'])
|
262
|
+
.to include('Ithaca (N.Y.). Cornell University', "Kornel\\xCA\\xB9skii universitet",
|
263
|
+
"K\\xCA\\xBBang-nai-erh ta hs\\xC3\\xBCeh")
|
260
264
|
expect(results['predicates']['http://schema.org/sameAs']).to include('http://id.loc.gov/authorities/names/n79021621', 'https://viaf.org/viaf/126293486')
|
261
265
|
end
|
262
266
|
|
263
267
|
it 'has unspecified predicate values' do
|
264
268
|
expect(results['predicates']['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']).to eq ['http://schema.org/Organization']
|
265
|
-
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#inScheme'])
|
266
|
-
|
269
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#inScheme'])
|
270
|
+
.to include('http://id.worldcat.org/fast/ontology/1.0/#fast', 'http://id.worldcat.org/fast/ontology/1.0/#facet-Corporate')
|
271
|
+
expect(results['predicates']['http://schema.org/name'])
|
272
|
+
.to include('Cornell University', 'Ithaca (N.Y.). Cornell University', "Kornel\\xCA\\xB9skii universitet",
|
273
|
+
"K\\xCA\\xBBang-nai-erh ta hs\\xC3\\xBCeh")
|
267
274
|
end
|
268
275
|
end
|
269
276
|
end
|
@@ -290,11 +297,24 @@ RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
|
290
297
|
it 'has primary predicates in pred-obj list' do
|
291
298
|
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#prefLabel']).to eq ['buttermilk']
|
292
299
|
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#broader']).to eq ['http://aims.fao.org/aos/agrovoc/c_4830']
|
293
|
-
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#exactMatch'])
|
300
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#exactMatch'])
|
301
|
+
.to include('http://cat.aii.caas.cn/concept/c_26308', 'http://lod.nal.usda.gov/nalt/20627',
|
302
|
+
'http://d-nb.info/gnd/4147072-2')
|
294
303
|
end
|
295
304
|
|
296
305
|
it 'has skos predicate values' do
|
297
|
-
expect(results['predicates']['http://www.w3.org/2008/05/skos-xl#prefLabel'])
|
306
|
+
expect(results['predicates']['http://www.w3.org/2008/05/skos-xl#prefLabel'])
|
307
|
+
.to include('http://aims.fao.org/aos/agrovoc/xl_es_1299487482038', 'http://aims.fao.org/aos/agrovoc/xl_it_1299487482154',
|
308
|
+
'http://aims.fao.org/aos/agrovoc/xl_ko_1299487482210', 'http://aims.fao.org/aos/agrovoc/xl_pl_1299487482273',
|
309
|
+
'http://aims.fao.org/aos/agrovoc/xl_sk_1299487482378', 'http://aims.fao.org/aos/agrovoc/xl_en_1299487482019',
|
310
|
+
'http://aims.fao.org/aos/agrovoc/xl_tr_9513_1321792194941',
|
311
|
+
'http://aims.fao.org/aos/agrovoc/xl_de_1299487482000', 'http://aims.fao.org/aos/agrovoc/xl_fa_1299487482058',
|
312
|
+
'http://aims.fao.org/aos/agrovoc/xl_th_1299487482417', 'http://aims.fao.org/aos/agrovoc/xl_fr_1299487482080',
|
313
|
+
'http://aims.fao.org/aos/agrovoc/xl_hi_1299487482102', 'http://aims.fao.org/aos/agrovoc/xl_ar_1299487481966',
|
314
|
+
'http://aims.fao.org/aos/agrovoc/xl_ja_1299487482181', 'http://aims.fao.org/aos/agrovoc/xl_lo_1299487482240',
|
315
|
+
'http://aims.fao.org/aos/agrovoc/xl_ru_1299487482341', 'http://aims.fao.org/aos/agrovoc/xl_cs_1299487481982',
|
316
|
+
'http://aims.fao.org/aos/agrovoc/xl_zh_1299487482458', 'http://aims.fao.org/aos/agrovoc/xl_pt_1299487482307',
|
317
|
+
'http://aims.fao.org/aos/agrovoc/xl_hu_1299487482127')
|
298
318
|
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#inScheme']).to eq ['http://aims.fao.org/aos/agrovoc']
|
299
319
|
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#closeMatch']).to eq ['http://dbpedia.org/resource/Buttermilk']
|
300
320
|
expect(results['predicates']['http://www.w3.org/2008/05/skos-xl#altLabel']).to eq ['http://aims.fao.org/aos/agrovoc/xl_fa_1299487482544']
|
@@ -337,22 +357,43 @@ RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
|
337
357
|
|
338
358
|
it 'has loc mads predicate values' do
|
339
359
|
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#classification']).to eq ['Q']
|
340
|
-
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#isMemberOfMADSCollection'])
|
341
|
-
|
342
|
-
|
343
|
-
|
360
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#isMemberOfMADSCollection'])
|
361
|
+
.to include('http://id.loc.gov/authorities/subjects/collection_LCSHAuthorizedHeadings',
|
362
|
+
'http://id.loc.gov/authorities/subjects/collection_LCSH_General',
|
363
|
+
'http://id.loc.gov/authorities/subjects/collection_SubdivideGeographically')
|
364
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#hasCloseExternalAuthority'])
|
365
|
+
.to include('http://data.bnf.fr/ark:/12148/cb12321484k', 'http://data.bnf.fr/ark:/12148/cb119673416',
|
366
|
+
'http://data.bnf.fr/ark:/12148/cb119934236', 'http://data.bnf.fr/ark:/12148/cb12062047t',
|
367
|
+
'http://data.bnf.fr/ark:/12148/cb119469567', 'http://data.bnf.fr/ark:/12148/cb11933232c',
|
368
|
+
'http://data.bnf.fr/ark:/12148/cb122890536', 'http://data.bnf.fr/ark:/12148/cb121155321',
|
369
|
+
'http://data.bnf.fr/ark:/12148/cb15556043g', 'http://data.bnf.fr/ark:/12148/cb123662513',
|
370
|
+
'http://d-nb.info/gnd/4066562-8', 'http://data.bnf.fr/ark:/12148/cb120745812',
|
371
|
+
'http://data.bnf.fr/ark:/12148/cb11973101n', 'http://data.bnf.fr/ark:/12148/cb13328497r')
|
372
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#isMemberOfMADSScheme'])
|
373
|
+
.to eq ['http://id.loc.gov/authorities/subjects']
|
374
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#editorialNote'])
|
375
|
+
.to eq ['headings beginning with the word [Scientific;] and subdivision [Science] under ethnic groups and individual wars, e.g. [World War, 1939-1945--Science]']
|
344
376
|
end
|
345
377
|
|
346
378
|
it 'has more unspecified predicate values' do
|
347
379
|
expect(results['predicates']['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']).to include('http://www.loc.gov/mads/rdf/v1#Topic', 'http://www.loc.gov/mads/rdf/v1#Authority', 'http://www.w3.org/2004/02/skos/core#Concept')
|
348
380
|
expect(results['predicates']['http://www.w3.org/2002/07/owl#sameAs']).to include('info:lc/authorities/sh85118553', 'http://id.loc.gov/authorities/sh85118553#concept')
|
349
|
-
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#closeMatch'])
|
350
|
-
|
381
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#closeMatch'])
|
382
|
+
.to include('http://data.bnf.fr/ark:/12148/cb12321484k', 'http://data.bnf.fr/ark:/12148/cb119673416',
|
383
|
+
'http://data.bnf.fr/ark:/12148/cb119934236', 'http://data.bnf.fr/ark:/12148/cb12062047t',
|
384
|
+
'http://data.bnf.fr/ark:/12148/cb119469567', 'http://data.bnf.fr/ark:/12148/cb11933232c',
|
385
|
+
'http://data.bnf.fr/ark:/12148/cb122890536', 'http://data.bnf.fr/ark:/12148/cb121155321',
|
386
|
+
'http://data.bnf.fr/ark:/12148/cb15556043g', 'http://data.bnf.fr/ark:/12148/cb123662513',
|
387
|
+
'http://d-nb.info/gnd/4066562-8', 'http://data.bnf.fr/ark:/12148/cb120745812',
|
388
|
+
'http://data.bnf.fr/ark:/12148/cb11973101n', 'http://data.bnf.fr/ark:/12148/cb13328497r')
|
389
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#editorial'])
|
390
|
+
.to eq ['headings beginning with the word [Scientific;] and subdivision [Science] under ethnic groups and individual wars, e.g. [World War, 1939-1945--Science]']
|
351
391
|
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#inScheme']).to eq ['http://id.loc.gov/authorities/subjects']
|
352
392
|
end
|
353
393
|
end
|
354
394
|
end
|
355
395
|
|
396
|
+
# rubocop:disable RSpec/NestedGroups
|
356
397
|
describe "language processing" do
|
357
398
|
context "when filtering #find result" do
|
358
399
|
context "and lang NOT passed in" do
|
@@ -461,6 +502,7 @@ RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
|
461
502
|
end
|
462
503
|
end
|
463
504
|
end
|
505
|
+
# rubocop:enable RSpec/NestedGroups
|
464
506
|
end
|
465
507
|
|
466
508
|
describe '#new' do
|
@@ -336,29 +336,32 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
|
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
339
|
+
# rubocop:disable RSpec/RepeatedExample
|
339
340
|
describe '#search_url_with_replacements' do
|
340
341
|
it 'returns nil if only term configuration is defined' do
|
341
342
|
expect(term_only_config.url_with_replacements('Smith')).to eq nil
|
342
343
|
end
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
344
|
+
context 'when subauthorities ARE defined' do
|
345
|
+
it 'returns the url with query substitution applied' do
|
346
|
+
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith¶m1=delta¶m2=echo'
|
347
|
+
expect(full_config.url_with_replacements('Smith')).to eq expected_url
|
348
|
+
end
|
349
|
+
it 'returns the url with default subauthority when NOT specified' do
|
350
|
+
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith¶m1=delta¶m2=echo'
|
351
|
+
expect(full_config.url_with_replacements('Smith')).to eq expected_url
|
352
|
+
end
|
353
|
+
it 'returns the url with subauthority substitution when specified' do
|
354
|
+
expected_url = 'http://localhost/test_default/search?subauth=search_sub3_name&query=Smith¶m1=delta¶m2=echo'
|
355
|
+
expect(full_config.url_with_replacements('Smith', 'search_sub3_key')).to eq expected_url
|
356
|
+
end
|
357
|
+
it 'returns the url with default values when replacements are NOT specified' do
|
358
|
+
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith¶m1=delta¶m2=echo'
|
359
|
+
expect(full_config.url_with_replacements('Smith')).to eq expected_url
|
360
|
+
end
|
361
|
+
it 'returns the url with replacement substitution values when replacements are specified' do
|
362
|
+
expected_url = 'http://localhost/test_default/search?subauth=search_sub1_name&query=Smith¶m1=golf¶m2=hotel'
|
363
|
+
expect(full_config.url_with_replacements('Smith', nil, param1: 'golf', param2: 'hotel')).to eq expected_url
|
364
|
+
end
|
362
365
|
end
|
363
366
|
|
364
367
|
context 'when subauthorities are not defined' do
|
@@ -392,4 +395,5 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
|
|
392
395
|
end
|
393
396
|
end
|
394
397
|
end
|
398
|
+
# rubocop:enable RSpec/RepeatedExample
|
395
399
|
end
|
@@ -14,7 +14,9 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
|
|
14
14
|
let(:auth_name) { :LOD_MIN_CONFIG }
|
15
15
|
|
16
16
|
it "does not change order" do
|
17
|
-
json_results = [{ label: "[#{term_b}, #{term_c}]", sort: [term_b, term_c] },
|
17
|
+
json_results = [{ label: "[#{term_b}, #{term_c}]", sort: [term_b, term_c] },
|
18
|
+
{ label: "[#{term_b}, #{term_d}]", sort: [term_b, term_d] },
|
19
|
+
{ label: "[#{term_b}, #{term_a}]", sort: [term_b, term_a] }]
|
18
20
|
expect(instance.send(:sort_search_results, json_results)).to eq json_results
|
19
21
|
end
|
20
22
|
end
|
@@ -22,28 +24,58 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
|
|
22
24
|
context 'when sort predicate is specified in configuration' do
|
23
25
|
let(:auth_name) { :LOD_SORT }
|
24
26
|
|
25
|
-
context "
|
27
|
+
context "and sort term is empty" do
|
26
28
|
context "for all" do
|
27
29
|
it "does not change order" do
|
28
|
-
json_results = [{ label: "[#{term_b}]", sort: [""] },
|
30
|
+
json_results = [{ label: "[#{term_b}]", sort: [""] },
|
31
|
+
{ label: "[#{term_a}]", sort: [""] },
|
32
|
+
{ label: "[#{term_c}]", sort: [""] }]
|
29
33
|
expect(instance.send(:sort_search_results, json_results)).to eq json_results
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
37
|
context "for one" do
|
34
|
-
it "puts empty first" do
|
35
|
-
json_results = [{ label: "[
|
36
|
-
|
38
|
+
it "puts empty first when empty is in 1st position" do
|
39
|
+
json_results = [{ label: "['_empty_1_']", sort: [""] },
|
40
|
+
{ label: "[#{term_c}]", sort: [term_c] },
|
41
|
+
{ label: "[#{term_a}]", sort: [term_a] }]
|
42
|
+
expected_results = [{ label: "['_empty_1_']" },
|
43
|
+
{ label: "[#{term_a}]" },
|
44
|
+
{ label: "[#{term_c}]" }]
|
45
|
+
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
46
|
+
end
|
47
|
+
|
48
|
+
it "puts empty first when empty is in 2nd position" do
|
49
|
+
json_results = [{ label: "[#{term_b}]", sort: [term_b] },
|
50
|
+
{ label: "['_empty_2_']", sort: [""] },
|
51
|
+
{ label: "[#{term_a}]", sort: [term_a] }]
|
52
|
+
expected_results = [{ label: "['_empty_2_']" },
|
53
|
+
{ label: "[#{term_a}]" },
|
54
|
+
{ label: "[#{term_b}]" }]
|
55
|
+
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
56
|
+
end
|
57
|
+
|
58
|
+
it "puts empty first when empty is in last position" do
|
59
|
+
json_results = [{ label: "[#{term_b}]", sort: [term_b] },
|
60
|
+
{ label: "[#{term_c}]", sort: [term_c] },
|
61
|
+
{ label: "['_empty_last_']", sort: [""] }]
|
62
|
+
expected_results = [{ label: "['_empty_last_']" },
|
63
|
+
{ label: "[#{term_b}]" },
|
64
|
+
{ label: "[#{term_c}]" }]
|
37
65
|
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
38
66
|
end
|
39
67
|
end
|
40
68
|
end
|
41
69
|
|
42
|
-
context "
|
70
|
+
context "and sort term is single value" do
|
43
71
|
context "for all" do
|
44
72
|
it "sorts on the single value" do
|
45
|
-
json_results = [{ label: "[#{term_b}]", sort: [term_b] },
|
46
|
-
|
73
|
+
json_results = [{ label: "[#{term_b}]", sort: [term_b] },
|
74
|
+
{ label: "[#{term_c}]", sort: [term_c] },
|
75
|
+
{ label: "[#{term_a}]", sort: [term_a] }]
|
76
|
+
expected_results = [{ label: "[#{term_a}]" },
|
77
|
+
{ label: "[#{term_b}]" },
|
78
|
+
{ label: "[#{term_c}]" }]
|
47
79
|
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
48
80
|
end
|
49
81
|
end
|
@@ -51,8 +83,12 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
|
|
51
83
|
|
52
84
|
context "when first sort term is same" do
|
53
85
|
it "sorts on second sort term" do
|
54
|
-
json_results = [{ label: "[#{term_b}, #{term_c}]", sort: [term_b, term_c] },
|
55
|
-
|
86
|
+
json_results = [{ label: "[#{term_b}, #{term_c}]", sort: [term_b, term_c] },
|
87
|
+
{ label: "[#{term_b}, #{term_d}]", sort: [term_b, term_d] },
|
88
|
+
{ label: "[#{term_b}, #{term_a}]", sort: [term_b, term_a] }]
|
89
|
+
expected_results = [{ label: "[#{term_b}, #{term_a}]" },
|
90
|
+
{ label: "[#{term_b}, #{term_c}]" },
|
91
|
+
{ label: "[#{term_b}, #{term_d}]" }]
|
56
92
|
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
57
93
|
end
|
58
94
|
end
|
@@ -60,20 +96,36 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
|
|
60
96
|
context "when different number of sort terms" do
|
61
97
|
context "and initial terms match" do
|
62
98
|
it "puts shorter set of terms before longer set" do
|
63
|
-
json_results = [{ label: "[#{term_b}, #{term_c}]", sort: [term_b, term_c] },
|
64
|
-
|
99
|
+
json_results = [{ label: "[#{term_b}, #{term_c}]", sort: [term_b, term_c] },
|
100
|
+
{ label: "[#{term_b}]", sort: [term_b] },
|
101
|
+
{ label: "[#{term_b}, #{term_a}]", sort: [term_b, term_a] }]
|
102
|
+
expected_results = [{ label: "[#{term_b}]" },
|
103
|
+
{ label: "[#{term_b}, #{term_a}]" },
|
104
|
+
{ label: "[#{term_b}, #{term_c}]" }]
|
65
105
|
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
66
106
|
end
|
67
107
|
end
|
68
108
|
|
69
109
|
context "and a difference happens before end of term sets" do
|
70
110
|
it "stops ordering as soon as a difference is found" do
|
71
|
-
json_results = [{ label: "[#{term_b}, #{term_d}, #{term_c}]", sort: [term_b, term_d, term_c] },
|
72
|
-
|
111
|
+
json_results = [{ label: "[#{term_b}, #{term_d}, #{term_c}]", sort: [term_b, term_d, term_c] },
|
112
|
+
{ label: "[#{term_a}, #{term_c}]", sort: [term_a, term_c] },
|
113
|
+
{ label: "[#{term_b}, #{term_d}, #{term_a}]", sort: [term_b, term_d, term_a] }]
|
114
|
+
expected_results = [{ label: "[#{term_a}, #{term_c}]" },
|
115
|
+
{ label: "[#{term_b}, #{term_d}, #{term_a}]" },
|
116
|
+
{ label: "[#{term_b}, #{term_d}, #{term_c}]" }]
|
73
117
|
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
74
118
|
end
|
75
119
|
end
|
76
120
|
end
|
121
|
+
|
122
|
+
context "and sort values are numeric" do
|
123
|
+
it "does numeric compare" do
|
124
|
+
json_results = [{ label: "['22']", sort: ["22"] }, { label: "['1']", sort: ["1"] }, { label: "['215']", sort: ["215"] }]
|
125
|
+
expected_results = [{ label: "['1']" }, { label: "['22']" }, { label: "['215']" }]
|
126
|
+
expect(instance.send(:sort_search_results, json_results)).to eq expected_results
|
127
|
+
end
|
128
|
+
end
|
77
129
|
end
|
78
130
|
end
|
79
131
|
end
|