qa 2.1.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +22 -3
  3. data/app/controllers/qa/application_controller.rb +2 -0
  4. data/app/controllers/qa/linked_data_terms_controller.rb +108 -49
  5. data/config/initializers/linked_data_authorities.rb +1 -17
  6. data/config/routes.rb +3 -0
  7. data/lib/generators/qa/apidoc/USAGE +11 -0
  8. data/lib/generators/qa/apidoc/apidoc_generator.rb +22 -0
  9. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/apidoc.json +1322 -0
  10. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-16x16.png +0 -0
  11. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-32x32.png +0 -0
  12. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/index.html +61 -0
  13. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/oauth2-redirect.html +67 -0
  14. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js +93 -0
  15. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js.map +1 -0
  16. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js +14 -0
  17. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js.map +1 -0
  18. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css +3 -0
  19. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css.map +1 -0
  20. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js +9 -0
  21. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js.map +1 -0
  22. data/lib/generators/qa/install/install_generator.rb +7 -0
  23. data/lib/generators/qa/install/templates/config/initializers/qa.rb +6 -0
  24. data/lib/qa/authorities/getty/aat.rb +13 -6
  25. data/lib/qa/authorities/getty/tgn.rb +10 -21
  26. data/lib/qa/authorities/getty/ulan.rb +12 -15
  27. data/lib/qa/authorities/linked_data.rb +1 -0
  28. data/lib/qa/authorities/linked_data/authority_service.rb +47 -0
  29. data/lib/qa/authorities/linked_data/config.rb +1 -1
  30. data/lib/qa/authorities/linked_data/find_term.rb +2 -1
  31. data/lib/qa/authorities/linked_data/generic_authority.rb +8 -1
  32. data/lib/qa/authorities/loc/generic_authority.rb +2 -2
  33. data/lib/qa/configuration.rb +18 -0
  34. data/lib/qa/version.rb +1 -1
  35. data/spec/controllers/linked_data_terms_controller_spec.rb +175 -35
  36. data/spec/controllers/terms_controller_spec.rb +2 -2
  37. data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +27 -0
  38. data/spec/lib/authorities/getty/aat_spec.rb +14 -9
  39. data/spec/lib/authorities/getty/tgn_spec.rb +6 -17
  40. data/spec/lib/authorities/getty/ulan_spec.rb +5 -5
  41. data/spec/lib/authorities/linked_data/authority_service_spec.rb +46 -0
  42. data/spec/lib/authorities/linked_data/generic_authority_spec.rb +0 -84
  43. data/spec/lib/authorities/loc_spec.rb +9 -9
  44. data/spec/lib/configuration_spec.rb +58 -0
  45. metadata +42 -14
  46. data/config/authorities/linked_data/agrovoc.json +0 -61
  47. data/spec/fixtures/lod_agrovoc_query_many_results.json +0 -1
  48. data/spec/fixtures/lod_agrovoc_query_no_results.json +0 -1
  49. data/spec/fixtures/lod_agrovoc_term_found.rdf.xml +0 -217
@@ -44,7 +44,7 @@ module Qa::Authorities
44
44
  # Return the full configuration for an authority
45
45
  # @return [String] the authority configuration
46
46
  def auth_config
47
- @authority_config ||= LINKED_DATA_AUTHORITIES_CONFIG[@authority_name]
47
+ @authority_config ||= Qa::Authorities::LinkedData::AuthorityService.authority_config(@authority_name)
48
48
  raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data authority '#{@authority_name}'" if @authority_config.nil?
49
49
  @authority_config
50
50
  end
@@ -33,13 +33,14 @@ module Qa::Authorities
33
33
  # "http://schema.org/name":["Cornell University","Ithaca (N.Y.). Cornell University"],
34
34
  # "http://www.w3.org/2004/02/skos/core#altLabel":["Ithaca (N.Y.). Cornell University"],
35
35
  # "http://schema.org/sameAs":["http://id.loc.gov/authorities/names/n79021621","https://viaf.org/viaf/126293486"] } }
36
- def find(id, language: nil, replacements: {}, subauth: nil)
36
+ def find(id, language: nil, replacements: {}, subauth: nil, jsonld: false)
37
37
  raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data term sub-authority #{subauth}" unless subauth.nil? || term_subauthority?(subauth)
38
38
  language ||= term_config.term_language
39
39
  url = term_config.term_url_with_replacements(id, subauth, replacements)
40
40
  Rails.logger.info "QA Linked Data term url: #{url}"
41
41
  graph = get_linked_data(url)
42
42
  return "{}" unless graph.size.positive?
43
+ return graph.dump(:jsonld, standard_prefixes: true) if jsonld
43
44
  parse_term_authority_response(id, graph, language)
44
45
  end
45
46
 
@@ -22,7 +22,13 @@ module Qa::Authorities
22
22
  @auth_config = Qa::Authorities::LinkedData::Config.new(auth_name)
23
23
  end
24
24
 
25
- include WebServiceBase
25
+ def reload_authorities
26
+ @authorities_service.load_authorities
27
+ end
28
+
29
+ def authorities_service
30
+ @authorities_service ||= Qa::Authorities::LinkedData::AuthorityService
31
+ end
26
32
 
27
33
  def search_service
28
34
  @search_service ||= Qa::Authorities::LinkedData::SearchQuery.new(search_config)
@@ -34,6 +40,7 @@ module Qa::Authorities
34
40
 
35
41
  delegate :search, to: :search_service
36
42
  delegate :find, to: :item_service
43
+ delegate :load_authorities, :authority_names, to: :authorities_service
37
44
 
38
45
  private
39
46
 
@@ -26,7 +26,7 @@ module Qa::Authorities
26
26
  def build_query_url(q)
27
27
  escaped_query = URI.escape(q)
28
28
  authority_fragment = Loc.get_url_for_authority(subauthority) + URI.escape(subauthority)
29
- "http://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
29
+ "https://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
30
30
  end
31
31
 
32
32
  def find(id)
@@ -34,7 +34,7 @@ module Qa::Authorities
34
34
  end
35
35
 
36
36
  def find_url(id)
37
- "http://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
37
+ "https://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
38
38
  end
39
39
 
40
40
  private
@@ -12,5 +12,23 @@ module Qa
12
12
  def disable_cors_headers
13
13
  @cors_headers_enabled = false
14
14
  end
15
+
16
+ # Provide a token that allows reloading of linked data authorities through the controller
17
+ # action '/reload/linked_data/authorities?auth_token=YOUR_AUTH_TOKEN_DEFINED_HERE' without
18
+ # requiring a restart of rails. By default, reloading through the browser is not allowed
19
+ # when the token is nil or blank. Change to your approved token string in
20
+ # config/initializers/qa.rb.
21
+ attr_writer :authorized_reload_token
22
+ def authorized_reload_token
23
+ @authorized_reload_token ||= nil
24
+ end
25
+
26
+ def valid_authority_reload_token?(token)
27
+ return false if token.blank? || authorized_reload_token.blank?
28
+ token == authorized_reload_token
29
+ end
30
+
31
+ # Hold linked data authority configs
32
+ attr_accessor :linked_data_authority_configs
15
33
  end
16
34
  end
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "2.1.1".freeze
2
+ VERSION = "3.1.0".freeze
3
3
  end
@@ -61,6 +61,14 @@ describe Qa::LinkedDataTermsController, type: :controller do
61
61
  end
62
62
  end
63
63
 
64
+ describe '#check_uri_param' do
65
+ it 'returns 400 if the uri is missing' do
66
+ expect(Rails.logger).to receive(:warn).with("Required fetch param 'uri' is missing or empty")
67
+ get :fetch, params: { uri: '', vocab: 'OCLC_FAST' }
68
+ expect(response.code).to eq('400')
69
+ end
70
+ end
71
+
64
72
  describe '#init_authority' do
65
73
  context 'when the authority does not exist' do
66
74
  it 'returns 400' do
@@ -71,6 +79,18 @@ describe Qa::LinkedDataTermsController, type: :controller do
71
79
  end
72
80
  end
73
81
 
82
+ describe '#list' do
83
+ let(:expected_results) { ['Auth1', 'Auth2', 'Auth3'] }
84
+ before do
85
+ allow(Qa::Authorities::LinkedData::AuthorityService).to receive(:authority_names).and_return(expected_results)
86
+ end
87
+ it 'returns list of authorities' do
88
+ get :list
89
+ expect(response).to be_successful
90
+ expect(response.body).to eq expected_results.to_json
91
+ end
92
+ end
93
+
74
94
  describe '#search' do
75
95
  context 'producing internal server error' do
76
96
  context 'when server returns 500' do
@@ -195,30 +215,6 @@ describe Qa::LinkedDataTermsController, type: :controller do
195
215
  end
196
216
  end
197
217
  end
198
-
199
- context 'in AGROVOC authority' do
200
- context '0 search results' do
201
- before do
202
- stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/search/?lang=en&query=*supercalifragilisticexpialidocious*')
203
- .to_return(status: 200, body: webmock_fixture('lod_agrovoc_query_no_results.json'), headers: { 'Content-Type' => 'application/json' })
204
- end
205
- it 'succeeds' do
206
- get :search, params: { q: 'supercalifragilisticexpialidocious', vocab: 'AGROVOC' }
207
- expect(response).to be_successful
208
- end
209
- end
210
-
211
- context '3 search results' do
212
- before do
213
- stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/search/?lang=en&query=*milk*')
214
- .to_return(status: 200, body: webmock_fixture('lod_agrovoc_query_many_results.json'), headers: { 'Content-Type' => 'application/json' })
215
- end
216
- it 'succeeds' do
217
- get :search, params: { q: 'milk', vocab: 'AGROVOC' }
218
- expect(response).to be_successful
219
- end
220
- end
221
- end
222
218
  end
223
219
 
224
220
  describe '#show' do
@@ -287,9 +283,27 @@ describe Qa::LinkedDataTermsController, type: :controller do
287
283
  stub_request(:get, 'http://id.worldcat.org/fast/530369')
288
284
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
289
285
  end
290
- it 'succeeds' do
286
+ it 'succeeds and defaults to json content type' do
291
287
  get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
292
288
  expect(response).to be_successful
289
+ expect(response.content_type).to eq 'application/json'
290
+ end
291
+
292
+ context 'and it was requested as json' do
293
+ it 'succeeds and returns term data as json content type' do
294
+ get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'json' }
295
+ expect(response).to be_successful
296
+ expect(response.content_type).to eq 'application/json'
297
+ end
298
+ end
299
+
300
+ context 'and it was requested as jsonld' do
301
+ it 'succeeds and returns term data as jsonld content type' do
302
+ get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'jsonld' }
303
+ expect(response).to be_successful
304
+ expect(response.content_type).to eq 'application/ld+json'
305
+ expect(JSON.parse(response.body).keys).to match_array ["@context", "@graph"]
306
+ end
293
307
  end
294
308
  end
295
309
 
@@ -318,30 +332,156 @@ describe Qa::LinkedDataTermsController, type: :controller do
318
332
  end
319
333
  end
320
334
 
321
- context 'in AGROVOC authority' do
335
+ context 'in LOC authority' do
322
336
  context 'term found' do
323
337
  before do
324
- stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/data?uri=http://aims.fao.org/aos/agrovoc/c_9513')
325
- .to_return(status: 200, body: webmock_fixture('lod_agrovoc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
338
+ stub_request(:get, 'http://id.loc.gov/authorities/subjects/sh85118553')
339
+ .to_return(status: 200, body: webmock_fixture('lod_loc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
326
340
  end
327
- it 'succeeds' do
328
- get :show, params: { id: 'c_9513', vocab: 'AGROVOC' }
341
+ it 'succeeds and defaults to json content type' do
342
+ get :show, params: { id: 'sh85118553', vocab: 'LOC', subauthority: 'subjects' }
329
343
  expect(response).to be_successful
344
+ expect(response.content_type).to eq 'application/json'
330
345
  end
331
346
  end
332
347
  end
348
+ end
333
349
 
334
- context 'in LOC authority' do
350
+ describe '#fetch' do
351
+ context 'producing internal server error' do
352
+ context 'when server returns 500' do
353
+ before do
354
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 500)
355
+ end
356
+ it 'returns 500' do
357
+ expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term http://test.org/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
358
+ get :fetch, params: { vocab: 'LOD_TERM_URI_PARAM_CONFIG', uri: 'http://test.org/530369' }
359
+ expect(response.code).to eq('500')
360
+ end
361
+ end
362
+
363
+ context 'when rdf format error' do
364
+ before do
365
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 200)
366
+ allow(RDF::Graph).to receive(:load).and_raise(RDF::FormatError)
367
+ end
368
+ it 'returns 500' do
369
+ msg = "RDF Format Error - Results from fetch term http://test.org/530369 for authority LOD_TERM_URI_PARAM_CONFIG was not identified as a valid RDF format. " \
370
+ "You may need to include the linkeddata gem."
371
+ expect(Rails.logger).to receive(:warn).with(msg)
372
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
373
+ expect(response.code).to eq('500')
374
+ end
375
+ end
376
+
377
+ context "when error isn't specifically handled" do
378
+ before do
379
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 501)
380
+ end
381
+ it 'returns 500' do
382
+ expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term http://test.org/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
383
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
384
+ expect(response.code).to eq('500')
385
+ end
386
+ end
387
+ end
388
+
389
+ context 'when service unavailable' do
390
+ before do
391
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 503)
392
+ end
393
+ it 'returns 503' do
394
+ expect(Rails.logger).to receive(:warn).with("Service Unavailable - Fetch term http://test.org/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
395
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
396
+ expect(response.code).to eq('503')
397
+ end
398
+ end
399
+
400
+ context 'when requested term is not found at the server' do
401
+ before do
402
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/FAKE_ID').to_return(status: 404, body: '', headers: {})
403
+ end
404
+ it 'returns 404' do
405
+ expect(Rails.logger).to receive(:warn).with('Term Not Found - Fetch term http://test.org/FAKE_ID unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG')
406
+ get :fetch, params: { uri: 'http://test.org/FAKE_ID', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
407
+ expect(response.code).to eq('404')
408
+ end
409
+ end
410
+
411
+ context 'in LOD_TERM_URI_PARAM_CONFIG authority' do
335
412
  context 'term found' do
336
413
  before do
337
- stub_request(:get, 'http://id.loc.gov/authorities/subjects/sh85118553')
338
- .to_return(status: 200, body: webmock_fixture('lod_loc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
414
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369')
415
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
339
416
  end
340
- it 'succeeds' do
341
- get :show, params: { id: 'sh85118553', vocab: 'LOC', subauthority: 'subjects' }
417
+
418
+ it 'succeeds and defaults to json content type' do
419
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
342
420
  expect(response).to be_successful
421
+ expect(response.content_type).to eq 'application/json'
422
+ end
423
+
424
+ context 'and it was requested as json' do
425
+ it 'succeeds and returns term data as json content type' do
426
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'json' }
427
+ expect(response).to be_successful
428
+ expect(response.content_type).to eq 'application/json'
429
+ end
430
+ end
431
+
432
+ context 'and it was requested as jsonld' do
433
+ it 'succeeds and returns term data as jsonld content type' do
434
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'jsonld' }
435
+ expect(response).to be_successful
436
+ expect(response.content_type).to eq 'application/ld+json'
437
+ expect(JSON.parse(response.body).keys).to match_array ["@context", "@graph"]
438
+ end
439
+ end
440
+ end
441
+
442
+ context 'when cors headers are enabled' do
443
+ before do
444
+ Qa.config.enable_cors_headers
445
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369')
446
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
447
+ end
448
+ it 'Access-Control-Allow-Origin is *' do
449
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
450
+ expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
451
+ end
452
+ end
453
+
454
+ context 'when cors headers are disabled' do
455
+ before do
456
+ Qa.config.disable_cors_headers
457
+ stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369')
458
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
459
+ end
460
+ it 'Access-Control-Allow-Origin is not present' do
461
+ get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
462
+ expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
343
463
  end
344
464
  end
345
465
  end
346
466
  end
467
+
468
+ describe '#reload' do
469
+ before do
470
+ Qa.config.authorized_reload_token = 'A_TOKEN'
471
+ end
472
+
473
+ context 'when token does not match' do
474
+ it 'returns 401' do
475
+ get :reload, params: { auth_token: 'BAD_TOKEN' }
476
+ expect(response.code).to eq('401')
477
+ end
478
+ end
479
+
480
+ context 'when token does match' do
481
+ it 'returns 200' do
482
+ get :reload, params: { auth_token: 'A_TOKEN' }
483
+ expect(response.code).to eq('200')
484
+ end
485
+ end
486
+ end
347
487
  end
@@ -78,7 +78,7 @@ describe Qa::TermsController, type: :controller do
78
78
 
79
79
  context "loc" do
80
80
  before do
81
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
81
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
82
82
  .with(headers: { 'Accept' => 'application/json' })
83
83
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
84
84
  end
@@ -184,7 +184,7 @@ describe Qa::TermsController, type: :controller do
184
184
  describe "#show" do
185
185
  context "with supported authorities" do
186
186
  before do
187
- stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json")
187
+ stub_request(:get, "https://id.loc.gov/authorities/subjects/sh85077565.json")
188
188
  .with(headers: { 'Accept' => 'application/json' })
189
189
  .to_return(status: 200, body: webmock_fixture("loc-names-response.txt"), headers: {})
190
190
  end
@@ -0,0 +1,27 @@
1
+ {
2
+ "term": {
3
+ "url": {
4
+ "@context": "http://www.w3.org/ns/hydra/context.jsonld",
5
+ "@type": "IriTemplate",
6
+ "template": "http://localhost/test_default/term?uri={?term_uri}",
7
+ "variableRepresentation": "BasicRepresentation",
8
+ "mapping": [
9
+ {
10
+ "@type": "IriTemplateMapping",
11
+ "variable": "term_uri",
12
+ "property": "hydra:freetextQuery",
13
+ "required": true
14
+ }
15
+ ]
16
+ },
17
+ "qa_replacement_patterns": {
18
+ "term_id": "term_uri"
19
+ },
20
+ "term_id": "URI",
21
+ "results": {
22
+ "id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
23
+ "label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
24
+ }
25
+ },
26
+ "search": {}
27
+ }
@@ -65,15 +65,20 @@ describe Qa::Authorities::Getty::AAT do
65
65
  subject { authority.request_options }
66
66
  it { is_expected.to eq(accept: "application/sparql-results+json") }
67
67
  end
68
-
68
+ # rubocop:disable Metrics/LineLength
69
69
  describe "#sparql" do
70
- subject { authority.sparql('search_term') }
71
- it {
72
- is_expected.to eq 'SELECT ?s ?name {
73
- ?s a skos:Concept; luc:term "search_term";
74
- skos:inScheme <http://vocab.getty.edu/aat/> ;
75
- gvp:prefLabelGVP [skosxl:literalForm ?name].
76
- FILTER regex(?name, "search_term", "i") .
77
- } ORDER BY ?name' }
70
+ context "using a single subject term" do
71
+ subject { authority.sparql('search_term') }
72
+ it {
73
+ is_expected.to eq %(SELECT ?s ?name { ?s a skos:Concept; luc:term "search_term"; skos:inScheme <http://vocab.getty.edu/aat/> ; gvp:prefLabelGVP [skosxl:literalForm ?name]. FILTER regex(?name, "search_term", "i") . } ORDER BY ?name)
74
+ }
75
+ end
76
+ context "using a two subject terms" do
77
+ subject { authority.sparql('search term') }
78
+ it {
79
+ is_expected.to eq %(SELECT ?s ?name { ?s a skos:Concept; luc:term "search term"; skos:inScheme <http://vocab.getty.edu/aat/> ; gvp:prefLabelGVP [skosxl:literalForm ?name]. FILTER ((regex(?name, "search", "i")) && (regex(?name, "term", "i"))) . } ORDER BY ?name)
80
+ }
81
+ end
78
82
  end
83
+ # rubocop:enable Metrics/LineLength
79
84
  end
@@ -65,31 +65,20 @@ describe Qa::Authorities::Getty::TGN do
65
65
  subject { authority.request_options }
66
66
  it { is_expected.to eq(accept: "application/sparql-results+json") }
67
67
  end
68
-
68
+ # rubocop:disable Metrics/LineLength
69
69
  describe "#sparql" do
70
70
  context "using a single subject term" do
71
71
  subject { authority.sparql('search_term') }
72
72
  it {
73
- is_expected.to eq 'SELECT DISTINCT ?s ?name ?par {
74
- ?s a skos:Concept; luc:term "search_term";
75
- skos:inScheme <http://vocab.getty.edu/tgn/> ;
76
- gvp:prefLabelGVP [skosxl:literalForm ?name] ;
77
- gvp:parentString ?par .
78
- FILTER regex(?name, "search_term", "i") .
79
- } ORDER BY ?name ASC(?par)' }
73
+ is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search_term"; skos:inScheme <http://vocab.getty.edu/ulan/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER regex(?name, "search_term", "i") . } ORDER BY ?name ASC(?par))
74
+ }
80
75
  end
81
76
  context "using a two subject terms" do
82
77
  subject { authority.sparql('search term') }
83
- # rubocop:disable Metrics/LineLength
84
78
  it {
85
- is_expected.to eq "SELECT DISTINCT ?s ?name ?par {
86
- ?s a skos:Concept; luc:term \"search term\";
87
- skos:inScheme <http://vocab.getty.edu/tgn/> ;
88
- gvp:prefLabelGVP [skosxl:literalForm ?name] ;
89
- gvp:parentString ?par .
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\" ) ) ) .
91
- } ORDER BY ?name ASC(?par)" }
92
- # rubocop:enable Metrics/LineLength
79
+ is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search term"; skos:inScheme <http://vocab.getty.edu/ulan/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER ((regex(?name, "search", "i") || regex(?alt, "search", "i")) && (regex(?name, "term", "i") || regex(?alt, "term", "i"))) . } ORDER BY ?name ASC(?par))
80
+ }
93
81
  end
94
82
  end
83
+ # rubocop:enable Metrics/LineLength
95
84
  end