qa 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/qa/linked_data_terms_controller.rb +30 -9
  4. data/app/controllers/qa/terms_controller.rb +3 -2
  5. data/app/models/qa/linked_data/config/context_property_map.rb +6 -25
  6. data/app/services/qa/iri_template_service.rb +32 -24
  7. data/app/services/qa/linked_data/authority_service.rb +8 -0
  8. data/app/services/qa/linked_data/authority_url_service.rb +27 -8
  9. data/app/services/qa/linked_data/deep_sort_service.rb +3 -2
  10. data/app/services/qa/linked_data/graph_service.rb +13 -0
  11. data/app/services/qa/linked_data/language_service.rb +12 -0
  12. data/app/services/qa/linked_data/language_sort_service.rb +7 -2
  13. data/app/services/qa/linked_data/ldpath_service.rb +40 -0
  14. data/app/services/qa/linked_data/mapper/graph_ldpath_mapper_service.rb +49 -0
  15. data/app/services/qa/linked_data/mapper/graph_mapper_service.rb +3 -11
  16. data/app/services/qa/linked_data/mapper/graph_predicate_mapper_service.rb +40 -0
  17. data/app/services/qa/linked_data/mapper/search_results_mapper_service.rb +58 -11
  18. data/app/services/qa/linked_data/mapper/term_results_mapper_service.rb +80 -0
  19. data/config/authorities/linked_data/loc.json +13 -7
  20. data/config/authorities/linked_data/oclc_fast.json +13 -8
  21. data/lib/generators/qa/discogs/USAGE +10 -0
  22. data/lib/generators/qa/discogs/discogs_generator.rb +12 -0
  23. data/lib/generators/qa/discogs/templates/config/discogs-formats.yml +346 -0
  24. data/lib/generators/qa/discogs/templates/config/discogs-genres.yml +627 -0
  25. data/lib/generators/qa/install/templates/config/initializers/qa.rb +4 -0
  26. data/lib/qa.rb +6 -0
  27. data/lib/qa/authorities.rb +2 -0
  28. data/lib/qa/authorities/discogs.rb +28 -0
  29. data/lib/qa/authorities/discogs/discogs_instance_builder.rb +145 -0
  30. data/lib/qa/authorities/discogs/discogs_translation.rb +126 -0
  31. data/lib/qa/authorities/discogs/discogs_utils.rb +89 -0
  32. data/lib/qa/authorities/discogs/discogs_works_builder.rb +153 -0
  33. data/lib/qa/authorities/discogs/generic_authority.rb +151 -0
  34. data/lib/qa/authorities/discogs_subauthority.rb +9 -0
  35. data/lib/qa/authorities/linked_data/config.rb +7 -3
  36. data/lib/qa/authorities/linked_data/config/search_config.rb +99 -11
  37. data/lib/qa/authorities/linked_data/config/term_config.rb +112 -8
  38. data/lib/qa/authorities/linked_data/find_term.rb +154 -84
  39. data/lib/qa/authorities/linked_data/search_query.rb +76 -13
  40. data/lib/qa/configuration.rb +8 -0
  41. data/lib/qa/version.rb +1 -1
  42. data/spec/controllers/linked_data_terms_controller_spec.rb +151 -30
  43. data/spec/controllers/terms_controller_spec.rb +4 -0
  44. data/spec/features/linked_data/language_spec.rb +298 -0
  45. data/spec/fixtures/authorities/linked_data/lod_full_config.json +21 -5
  46. data/spec/fixtures/authorities/linked_data/lod_lang_defaults.json +4 -4
  47. data/spec/fixtures/authorities/linked_data/lod_lang_multi_defaults.json +4 -4
  48. data/spec/fixtures/authorities/linked_data/lod_lang_no_defaults.json +4 -5
  49. data/spec/fixtures/authorities/linked_data/lod_lang_param.json +4 -4
  50. data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +1 -1
  51. data/spec/fixtures/discogs-find-response-json.json +1 -0
  52. data/spec/fixtures/discogs-find-response-jsonld-master.json +1 -0
  53. data/spec/fixtures/discogs-find-response-jsonld-release.json +1 -0
  54. data/spec/fixtures/discogs-id-matches-master.json +1 -0
  55. data/spec/fixtures/discogs-id-matches-release.json +1 -0
  56. data/spec/fixtures/discogs-id-not-found-master.json +1 -0
  57. data/spec/fixtures/discogs-id-not-found-release.json +1 -0
  58. data/spec/fixtures/discogs-search-response-no-auth.json +1 -0
  59. data/spec/fixtures/discogs-search-response-no-subauth.json +1 -0
  60. data/spec/fixtures/discogs-search-response-subauth.json +1 -0
  61. data/spec/fixtures/lod_lang_search_enesfrde.rdf.xml +60 -0
  62. data/spec/fixtures/lod_lang_search_sv.rdf.xml +42 -0
  63. data/spec/fixtures/lod_loc_term_found.rdf.xml +5 -0
  64. data/spec/lib/authorities/discogs/generic_authority_spec.rb +235 -0
  65. data/spec/lib/authorities/discogs_spec.rb +17 -0
  66. data/spec/lib/authorities/linked_data/config_spec.rb +68 -5
  67. data/spec/lib/authorities/linked_data/find_term_spec.rb +298 -3
  68. data/spec/lib/authorities/linked_data/generic_authority_spec.rb +46 -485
  69. data/spec/lib/authorities/linked_data/search_config_spec.rb +154 -3
  70. data/spec/lib/authorities/linked_data/search_query_spec.rb +240 -3
  71. data/spec/lib/authorities/linked_data/term_config_spec.rb +193 -5
  72. data/spec/lib/configuration_spec.rb +18 -0
  73. data/spec/models/linked_data/config/context_property_map_spec.rb +3 -31
  74. data/spec/services/iri_template_service_spec.rb +54 -12
  75. data/spec/{lib/authorities → services}/linked_data/authority_service_spec.rb +47 -0
  76. data/spec/services/linked_data/language_service_spec.rb +52 -11
  77. data/spec/services/linked_data/ldpath_service_spec.rb +61 -0
  78. data/spec/services/linked_data/mapper/graph_ldpath_mapper_service_spec.rb +118 -0
  79. data/spec/services/linked_data/mapper/graph_predicate_mapper_service_spec.rb +110 -0
  80. data/spec/services/linked_data/mapper/term_results_mapper_service_spec.rb +94 -0
  81. data/spec/spec_helper.rb +1 -1
  82. data/spec/support/matchers/include_hash.rb +5 -0
  83. data/spec/test_app_templates/lib/generators/test_app_generator.rb +4 -0
  84. metadata +73 -5
  85. data/lib/qa/authorities/linked_data/rdf_helper.rb +0 -49
@@ -1,18 +1,32 @@
1
1
  require 'spec_helper'
2
+ require 'qa/authorities/linked_data/config/search_config'
2
3
 
3
4
  RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
5
+ before do
6
+ Qa::LinkedData::AuthorityService.load_authorities
7
+ end
8
+
4
9
  let(:full_config) { Qa::Authorities::LinkedData::Config.new(:LOD_FULL_CONFIG).search }
5
10
  let(:min_config) { Qa::Authorities::LinkedData::Config.new(:LOD_MIN_CONFIG).search }
6
11
  let(:term_only_config) { Qa::Authorities::LinkedData::Config.new(:LOD_TERM_ONLY_CONFIG).search }
7
12
  let(:encoding_config) { Qa::Authorities::LinkedData::Config.new(:LOD_ENCODING_CONFIG).search }
8
13
 
14
+ let(:ldpath_results_config) do
15
+ {
16
+ id_ldpath: 'schema:identifier ::xsd:string',
17
+ label_ldpath: 'skos:prefLabel ::xsd:string',
18
+ altlabel_ldpath: 'skos:altLabel ::xsd:string',
19
+ sort_ldpath: 'skos:prefLabel ::xsd:string'
20
+ }
21
+ end
22
+
9
23
  describe '#search_config' do
10
24
  let(:full_search_config) do
11
25
  {
12
26
  url: {
13
27
  :@context => 'http://www.w3.org/ns/hydra/context.jsonld',
14
28
  :@type => 'IriTemplate',
15
- template: 'http://localhost/test_default/search?{?subauth}&{?query}&{?param1}&{?param2}',
29
+ template: 'http://localhost/test_default/search?{?subauth}&{?query}&{?param1}&{?param2}&{?lang}',
16
30
  variableRepresentation: 'BasicRepresentation',
17
31
  mapping: [
18
32
  {
@@ -41,12 +55,20 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
41
55
  property: 'hydra:freetextQuery',
42
56
  required: false,
43
57
  default: 'echo'
58
+ },
59
+ {
60
+ :@type => 'IriTemplateMapping',
61
+ variable: 'lang',
62
+ property: 'hydra:freetextQuery',
63
+ required: false,
64
+ default: 'fr'
44
65
  }
45
66
  ]
46
67
  },
47
68
  qa_replacement_patterns: {
48
69
  query: 'query',
49
- subauth: 'subauth'
70
+ subauth: 'subauth',
71
+ lang: 'lang'
50
72
  },
51
73
  language: ['en', 'fr', 'de'],
52
74
  results: {
@@ -177,6 +199,19 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
177
199
  end
178
200
  end
179
201
 
202
+ describe '#results_id_ldpath' do
203
+ it 'returns nil if only term configuration is defined' do
204
+ expect(term_only_config.results_id_ldpath).to eq nil
205
+ end
206
+
207
+ context 'when id specified as ldpath' do
208
+ before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
209
+ it 'returns the ldpath' do
210
+ expect(full_config.results_id_ldpath).to eq 'schema:identifier ::xsd:string'
211
+ end
212
+ end
213
+ end
214
+
180
215
  describe '#results_label_predicate' do
181
216
  it 'returns nil if only term configuration is defined' do
182
217
  expect(term_only_config.results_label_predicate).to eq nil
@@ -186,11 +221,24 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
186
221
  end
187
222
  end
188
223
 
224
+ describe '#results_label_ldpath' do
225
+ it 'returns nil if only term configuration is defined' do
226
+ expect(term_only_config.results_label_ldpath).to eq nil
227
+ end
228
+
229
+ context 'when label specified as ldpath' do
230
+ before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
231
+ it 'returns the ldpath' do
232
+ expect(full_config.results_label_ldpath).to eq 'skos:prefLabel ::xsd:string'
233
+ end
234
+ end
235
+ end
236
+
189
237
  describe '#results_altlabel_predicate' do
190
238
  it 'returns nil if only term configuration is defined' do
191
239
  expect(term_only_config.results_altlabel_predicate).to eq nil
192
240
  end
193
- it 'return nil if altlabel predicate is not defined' do
241
+ it 'returns nil if altlabel predicate is not defined' do
194
242
  expect(min_config.results_altlabel_predicate).to eq nil
195
243
  end
196
244
  it 'returns the predicate that holds the altlabel in search results' do
@@ -198,6 +246,22 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
198
246
  end
199
247
  end
200
248
 
249
+ describe '#results_altlabel_ldpath' do
250
+ it 'returns nil if only term configuration is defined' do
251
+ expect(term_only_config.results_altlabel_ldpath).to eq nil
252
+ end
253
+ it 'returns nil if altlabel ldpath is not defined' do
254
+ expect(min_config.results_altlabel_ldpath).to eq nil
255
+ end
256
+
257
+ context 'when altlabel specified as ldpath' do
258
+ before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
259
+ it 'returns the ldpath' do
260
+ expect(full_config.results_altlabel_ldpath).to eq 'skos:altLabel ::xsd:string'
261
+ end
262
+ end
263
+ end
264
+
201
265
  describe '#supports_sort?' do
202
266
  it 'returns false if only term configuration is defined' do
203
267
  expect(term_only_config.supports_sort?).to eq false
@@ -222,6 +286,22 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
222
286
  end
223
287
  end
224
288
 
289
+ describe '#results_sort_ldpath' do
290
+ it 'returns nil if only term configuration is defined' do
291
+ expect(term_only_config.results_sort_ldpath).to eq nil
292
+ end
293
+ it 'returns nil if sort ldpath is not defined' do
294
+ expect(min_config.results_sort_ldpath).to eq nil
295
+ end
296
+
297
+ context 'when sort specified as ldpath' do
298
+ before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
299
+ it 'returns the ldpath' do
300
+ expect(full_config.results_sort_ldpath).to eq 'skos:prefLabel ::xsd:string'
301
+ end
302
+ end
303
+ end
304
+
225
305
  describe '#supports_context?' do
226
306
  it 'returns false if only term configuration is defined' do
227
307
  expect(term_only_config.supports_context?).to eq false
@@ -246,6 +326,30 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
246
326
  end
247
327
  end
248
328
 
329
+ describe '#supports_language_parameter?' do
330
+ it 'returns false if only term configuration is defined' do
331
+ expect(term_only_config.supports_language_parameter?).to eq false
332
+ end
333
+ it 'returns false if the configuration does NOT define the lang replacement' do
334
+ expect(min_config.supports_language_parameter?).to eq false
335
+ end
336
+ it 'returns true if the configuration defines the lang replacement' do
337
+ expect(full_config.supports_language_parameter?).to eq true
338
+ end
339
+ end
340
+
341
+ describe '#supports_subauthorities?' do
342
+ it 'returns false if only term configuration is defined' do
343
+ expect(term_only_config.supports_subauthorities?).to eq false
344
+ end
345
+ it 'returns false if the configuration does NOT define the subauth replacement' do
346
+ expect(min_config.supports_subauthorities?).to eq false
347
+ end
348
+ it 'returns true if the configuration defines the subauth replacement' do
349
+ expect(full_config.supports_subauthorities?).to eq true
350
+ end
351
+ end
352
+
249
353
  describe '#subauthorities?' do
250
354
  it 'returns false if only term configuration is defined' do
251
355
  expect(term_only_config.subauthorities?).to eq false
@@ -303,4 +407,51 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
303
407
  expect(full_config.subauthorities).to eq expected_hash
304
408
  end
305
409
  end
410
+
411
+ describe '#info' do
412
+ let(:term_details) do
413
+ {
414
+ "label" => "oclc_fast term (QA)",
415
+ "uri" => "urn:qa:term:oclc_fast",
416
+ "authority" => "oclc_fast",
417
+ "action" => "term",
418
+ "language" => ["en"]
419
+ }
420
+ end
421
+
422
+ let(:search_details) do
423
+ {
424
+ "label" => "oclc_fast search (QA)",
425
+ "uri" => "urn:qa:search:oclc_fast",
426
+ "authority" => "oclc_fast",
427
+ "action" => "search",
428
+ "language" => ["en"]
429
+ }
430
+ end
431
+
432
+ let(:search_details_with_subauth) do
433
+ {
434
+ "label" => "oclc_fast search topic (QA)",
435
+ "uri" => "urn:qa:search:oclc_fast:topic",
436
+ "authority" => "oclc_fast",
437
+ "subauthority" => "topic",
438
+ "action" => "search",
439
+ "language" => ["en"]
440
+ }
441
+ end
442
+
443
+ let(:details) { Qa::Authorities::LinkedData::Config.new(:OCLC_FAST).search.info }
444
+
445
+ it "does not return a list with details for term" do
446
+ expect(details).not_to include_hash(term_details)
447
+ end
448
+
449
+ it "returns a list with details for search without subauthorities" do
450
+ expect(details).to include_hash(search_details)
451
+ end
452
+
453
+ it "returns a list with details for search with a subauthority" do
454
+ expect(details).to include_hash(search_details_with_subauth)
455
+ end
456
+ end
306
457
  end
@@ -1,7 +1,244 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
4
- # all search functionality is tested in spec/lib/authorities/linked_data/generic_authority_spec.rb and
5
- # spec/controllers/linked_data_term_controller_spec.rb
6
- it "is tested elsewhere"
4
+ describe '#search' do
5
+ let(:lod_oclc) { described_class.new(search_config(:OCLC_FAST)) }
6
+
7
+ context 'performance stats' do
8
+ before do
9
+ stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22cornell%22&sortKeys=usage')
10
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
11
+ end
12
+ context 'when set to true' do
13
+ let :results do
14
+ lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' }, performance_data: true)
15
+ end
16
+ it 'includes performance in return hash' do
17
+ expect(results).to be_kind_of Hash
18
+ expect(results.keys).to match_array [:performance, :results]
19
+ expect(results[:performance].keys).to match_array [:result_count, :fetch_time_s, :normalization_time_s, :total_time_s]
20
+ expect(results[:performance][:total_time_s]).to eq results[:performance][:fetch_time_s] + results[:performance][:normalization_time_s]
21
+ expect(results[:performance][:result_count]).to eq 3
22
+ expect(results[:results].count).to eq 3
23
+ end
24
+ end
25
+
26
+ context 'when set to false' do
27
+ let :results do
28
+ lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' }, performance_data: false)
29
+ end
30
+ it 'does NOT include performance in return hash' do
31
+ expect(results).to be_kind_of Array
32
+ end
33
+ end
34
+
35
+ context 'when using default setting' do
36
+ let :results do
37
+ lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
38
+ end
39
+ it 'does NOT include performance in return hash' do
40
+ expect(results).to be_kind_of Array
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'in OCLC_FAST authority' do
46
+ context '0 search results' do
47
+ let :results do
48
+ stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=cql.any%20all%20%22supercalifragilisticexpialidocious%22&sortKeys=usage')
49
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_query_no_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
50
+ lod_oclc.search('supercalifragilisticexpialidocious', replacements: { 'maximumRecords' => '3' })
51
+ end
52
+ it 'returns an empty array' do
53
+ expect(results).to eq([])
54
+ end
55
+ end
56
+
57
+ context '3 search results' do
58
+ let :results do
59
+ stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=cql.any%20all%20%22cornell%22&sortKeys=usage')
60
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_all_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
61
+ lod_oclc.search('cornell', replacements: { 'maximumRecords' => '3' })
62
+ end
63
+ it 'is correctly parsed' do
64
+ expect(results.count).to eq(3)
65
+ expect(results.first).to eq(uri: 'http://id.worldcat.org/fast/530369', id: '530369', label: 'Cornell University')
66
+ expect(results.second).to eq(uri: 'http://id.worldcat.org/fast/5140', id: '5140', label: 'Cornell, Joseph')
67
+ expect(results.third).to eq(uri: 'http://id.worldcat.org/fast/557490', id: '557490', label: 'New York State School of Industrial and Labor Relations')
68
+ end
69
+ end
70
+ end
71
+
72
+ context 'in OCLC_FAST authority and personal_name subauthority' do
73
+ context '0 search results' do
74
+ let :results do
75
+ stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22supercalifragilisticexpialidocious%22&sortKeys=usage')
76
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_query_no_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
77
+ lod_oclc.search('supercalifragilisticexpialidocious', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
78
+ end
79
+ it 'returns an empty array' do
80
+ expect(results).to eq([])
81
+ end
82
+ end
83
+
84
+ context '3 search results' do
85
+ let :results do
86
+ stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22cornell%22&sortKeys=usage')
87
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
88
+ lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
89
+ end
90
+ it 'is correctly parsed' do
91
+ expect(results.count).to eq(3)
92
+ expect(results.first).to eq(uri: 'http://id.worldcat.org/fast/409667', id: '409667', label: 'Cornell, Ezra, 1807-1874')
93
+ expect(results.second).to eq(uri: 'http://id.worldcat.org/fast/5140', id: '5140', label: 'Cornell, Joseph')
94
+ expect(results.third).to eq(uri: 'http://id.worldcat.org/fast/72456', id: '72456', label: 'Cornell, Sarah Maria, 1802-1832')
95
+ end
96
+ end
97
+ end
98
+
99
+ context 'when id predicate is not specified' do
100
+ let(:min_authority) { described_class.new(search_config(:LOD_MIN_CONFIG)) }
101
+ let :results do
102
+ stub_request(:get, 'http://localhost/test_default/search?query=peanuts')
103
+ .to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
104
+ min_authority.search('peanuts')
105
+ end
106
+ it 'uses subject uri for id' do
107
+ expect(results.count).to eq(3)
108
+ expect(results.first).to eq(uri: 'http://id.worldcat.org/fast/409667', id: 'http://id.worldcat.org/fast/409667', label: 'Cornell, Ezra, 1807-1874')
109
+ expect(results.second).to eq(uri: 'http://id.worldcat.org/fast/5140', id: 'http://id.worldcat.org/fast/5140', label: 'Cornell, Joseph')
110
+ expect(results.third).to eq(uri: 'http://id.worldcat.org/fast/72456', id: 'http://id.worldcat.org/fast/72456', label: 'Cornell, Sarah Maria, 1802-1832')
111
+ end
112
+ end
113
+
114
+ # context 'in LOC authority' do
115
+ # ###################################
116
+ # ### SEARCH NOT SUPPORTED BY LOC ###
117
+ # ###################################
118
+ # # let(:lod_loc) { described_class.new(search_config(:LOC)) }
119
+ # end
120
+
121
+ # rubocop:disable RSpec/NestedGroups
122
+ describe "language processing" do
123
+ context "when filtering #search results" do
124
+ context "and lang NOT passed in" do
125
+ context "and NO language defined in authority config" do
126
+ context "and NO language defined in Qa config" do
127
+ let(:lod_lang_no_defaults) { described_class.new(search_config(:LOD_LANG_NO_DEFAULTS)) }
128
+ let :results do
129
+ stub_request(:get, "http://localhost/test_no_default/search?query=milk")
130
+ .to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
131
+ lod_lang_no_defaults.search('milk')
132
+ end
133
+
134
+ before do
135
+ Qa.config.default_language = []
136
+ end
137
+
138
+ after do
139
+ Qa.config.default_language = :en
140
+ end
141
+
142
+ it "is not filtered" do
143
+ expect(results.first[:label]).to eq('[buttermilk, Babeurre] (yummy, délicieux)')
144
+ expect(results.second[:label]).to eq('[condensed milk, lait condensé] (creamy, crémeux)')
145
+ expect(results.third[:label]).to eq('[dried milk, lait en poudre] (powdery, poudreux)')
146
+ end
147
+ end
148
+
149
+ context "and default_language is defined in Qa config" do
150
+ let(:lod_lang_no_defaults) { described_class.new(search_config(:LOD_LANG_NO_DEFAULTS)) }
151
+ let :results do
152
+ stub_request(:get, "http://localhost/test_no_default/search?query=milk")
153
+ .to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
154
+ lod_lang_no_defaults.search('milk')
155
+ end
156
+ it "filters using Qa configured default" do
157
+ expect(results.first[:label]).to eq('buttermilk (yummy)')
158
+ expect(results.second[:label]).to eq('condensed milk (creamy)')
159
+ expect(results.third[:label]).to eq('dried milk (powdery)')
160
+ end
161
+ end
162
+ end
163
+
164
+ context "and language IS defined in authority config" do
165
+ let(:lod_lang_defaults) { described_class.new(search_config(:LOD_LANG_DEFAULTS)) }
166
+ let :results do
167
+ stub_request(:get, "http://localhost/test_default/search?query=milk")
168
+ .to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
169
+ lod_lang_defaults.search('milk')
170
+ end
171
+ it "is filtered to authority defined language" do
172
+ expect(results.first[:label]).to eq('Babeurre (délicieux)')
173
+ expect(results.second[:label]).to eq('lait condensé (crémeux)')
174
+ expect(results.third[:label]).to eq('lait en poudre (poudreux)')
175
+ end
176
+ end
177
+ end
178
+
179
+ context "and multiple languages ARE defined in authority config" do
180
+ let(:lod_lang_multi_defaults) { described_class.new(search_config(:LOD_LANG_MULTI_DEFAULTS)) }
181
+ let :results do
182
+ stub_request(:get, "http://localhost/test_default/search?query=milk")
183
+ .to_return(status: 200, body: webmock_fixture("lod_lang_search_enfrde.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
184
+ lod_lang_multi_defaults.search('milk')
185
+ end
186
+ it "is filtered to authority defined languages" do
187
+ expect(results.first[:label]).to eq('[buttermilk, Babeurre] (yummy, délicieux)')
188
+ expect(results.second[:label]).to eq('[condensed milk, lait condensé] (creamy, crémeux)')
189
+ expect(results.third[:label]).to eq('[dried milk, lait en poudre] (powdery, poudreux)')
190
+ end
191
+ end
192
+
193
+ context "and language IS passed in to search" do
194
+ let(:lod_lang_defaults) { described_class.new(search_config(:LOD_LANG_DEFAULTS)) }
195
+ let :results do
196
+ stub_request(:get, "http://localhost/test_default/search?query=milk")
197
+ .to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
198
+ lod_lang_defaults.search('milk', language: :fr)
199
+ end
200
+ it "is filtered to specified language" do
201
+ expect(results.first[:label]).to eq('Babeurre (délicieux)')
202
+ expect(results.second[:label]).to eq('lait condensé (crémeux)')
203
+ expect(results.third[:label]).to eq('lait en poudre (poudreux)')
204
+ end
205
+ end
206
+
207
+ context "when replacement on authority search URL" do
208
+ context "and using default" do
209
+ let(:lod_lang_param) { described_class.new(search_config(:LOD_LANG_PARAM)) }
210
+ let :results do
211
+ stub_request(:get, "http://localhost/test_replacement/search?lang=en&query=milk")
212
+ .to_return(status: 200, body: webmock_fixture("lod_lang_search_en.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
213
+ lod_lang_param.search("milk")
214
+ end
215
+ it "is correctly parsed" do
216
+ expect(results.first[:label]).to eq('buttermilk (yummy)')
217
+ expect(results.second[:label]).to eq('condensed milk (creamy)')
218
+ expect(results.third[:label]).to eq('dried milk (powdery)')
219
+ end
220
+ end
221
+
222
+ context "and lang specified" do
223
+ let(:lod_lang_param) { described_class.new(search_config(:LOD_LANG_PARAM)) }
224
+ let :results do
225
+ stub_request(:get, "http://localhost/test_replacement/search?query=milk&lang=fr")
226
+ .to_return(status: 200, body: webmock_fixture("lod_lang_search_fr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
227
+ lod_lang_param.search("milk", replacements: { 'lang' => 'fr' })
228
+ end
229
+ it "is correctly parsed" do
230
+ expect(results.first[:label]).to eq('Babeurre (délicieux)')
231
+ expect(results.second[:label]).to eq('lait condensé (crémeux)')
232
+ expect(results.third[:label]).to eq('lait en poudre (poudreux)')
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
238
+ # rubocop:enable RSpec/NestedGroups
239
+ end
240
+
241
+ def search_config(authority_name)
242
+ Qa::Authorities::LinkedData::Config.new(authority_name).search
243
+ end
7
244
  end