qa 3.1.0 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +16 -548
  3. data/app/controllers/qa/linked_data_terms_controller.rb +64 -42
  4. data/app/controllers/qa/terms_controller.rb +14 -6
  5. data/app/models/qa/iri_template/url_config.rb +47 -0
  6. data/app/models/qa/iri_template/variable_map.rb +62 -0
  7. data/app/models/qa/linked_data/config/context_map.rb +77 -0
  8. data/app/models/qa/linked_data/config/context_property_map.rb +144 -0
  9. data/app/models/qa/linked_data/config/helper.rb +34 -0
  10. data/app/services/qa/iri_template_service.rb +31 -0
  11. data/{lib/qa/authorities → app/services/qa}/linked_data/authority_service.rb +3 -4
  12. data/app/services/qa/linked_data/authority_url_service.rb +48 -0
  13. data/app/services/qa/linked_data/deep_sort_service.rb +238 -0
  14. data/app/services/qa/linked_data/graph_service.rb +106 -0
  15. data/app/services/qa/linked_data/language_service.rb +30 -0
  16. data/app/services/qa/linked_data/language_sort_service.rb +81 -0
  17. data/app/services/qa/linked_data/mapper/context_mapper_service.rb +59 -0
  18. data/app/services/qa/linked_data/mapper/graph_mapper_service.rb +40 -0
  19. data/app/services/qa/linked_data/mapper/search_results_mapper_service.rb +70 -0
  20. data/config/authorities/linked_data/loc.json +5 -2
  21. data/config/authorities/linked_data/oclc_fast.json +3 -2
  22. data/config/initializers/linked_data_authorities.rb +1 -1
  23. data/config/locales/qa.en.yml +9 -0
  24. data/lib/generators/qa/install/templates/config/initializers/qa.rb +4 -0
  25. data/lib/qa.rb +8 -0
  26. data/lib/qa/authorities/assign_fast/generic_authority.rb +1 -1
  27. data/lib/qa/authorities/base.rb +0 -11
  28. data/lib/qa/authorities/crossref/generic_authority.rb +1 -1
  29. data/lib/qa/authorities/geonames.rb +1 -1
  30. data/lib/qa/authorities/getty/aat.rb +7 -2
  31. data/lib/qa/authorities/getty/tgn.rb +7 -2
  32. data/lib/qa/authorities/getty/ulan.rb +7 -2
  33. data/lib/qa/authorities/linked_data.rb +0 -1
  34. data/lib/qa/authorities/linked_data/config.rb +29 -28
  35. data/lib/qa/authorities/linked_data/config/search_config.rb +21 -79
  36. data/lib/qa/authorities/linked_data/config/term_config.rb +7 -77
  37. data/lib/qa/authorities/linked_data/find_term.rb +25 -17
  38. data/lib/qa/authorities/linked_data/generic_authority.rb +6 -5
  39. data/lib/qa/authorities/linked_data/rdf_helper.rb +6 -73
  40. data/lib/qa/authorities/linked_data/search_query.rb +54 -101
  41. data/lib/qa/authorities/loc/generic_authority.rb +4 -4
  42. data/lib/qa/authorities/web_service_base.rb +1 -8
  43. data/lib/qa/configuration.rb +7 -0
  44. data/lib/qa/version.rb +1 -1
  45. data/lib/tasks/mesh.rake +19 -18
  46. data/spec/controllers/linked_data_terms_controller_spec.rb +51 -1
  47. data/spec/controllers/terms_controller_spec.rb +15 -15
  48. data/spec/fixtures/authorities/linked_data/lod_encoding_config.json +2 -1
  49. data/spec/fixtures/authorities/linked_data/lod_full_config.json +56 -2
  50. data/spec/fixtures/authorities/linked_data/lod_full_config_1_0.json +164 -0
  51. data/spec/fixtures/authorities/linked_data/lod_lang_defaults.json +5 -4
  52. data/spec/fixtures/authorities/linked_data/lod_lang_multi_defaults.json +3 -2
  53. data/spec/fixtures/authorities/linked_data/lod_lang_no_defaults.json +3 -2
  54. data/spec/fixtures/authorities/linked_data/lod_lang_param.json +3 -2
  55. data/spec/fixtures/authorities/linked_data/lod_min_config.json +3 -2
  56. data/spec/fixtures/authorities/linked_data/lod_search_only_config.json +2 -1
  57. data/spec/fixtures/authorities/linked_data/lod_sort.json +2 -1
  58. data/spec/fixtures/authorities/linked_data/lod_term_id_param_config.json +2 -1
  59. data/spec/fixtures/authorities/linked_data/lod_term_only_config.json +2 -1
  60. data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +2 -1
  61. data/spec/fixtures/getty-error-response.txt +10 -0
  62. data/spec/fixtures/lod_2_ranked_2_unranked.nt +17 -0
  63. data/spec/fixtures/lod_3_ranked_varying_preds.nt +16 -0
  64. data/spec/fixtures/lod_lang_search_filtering.nt +11 -0
  65. data/spec/fixtures/lod_search_with_blanknode_subjects.nt +18 -0
  66. data/spec/fixtures/lod_term_with_blanknode_objects.nt +8 -0
  67. data/spec/lib/authorities/assign_fast_spec.rb +1 -0
  68. data/spec/lib/authorities/getty/aat_spec.rb +14 -2
  69. data/spec/lib/authorities/getty/tgn_spec.rb +14 -2
  70. data/spec/lib/authorities/getty/ulan_spec.rb +14 -2
  71. data/spec/lib/authorities/linked_data/authority_service_spec.rb +2 -1
  72. data/spec/lib/authorities/linked_data/config_spec.rb +284 -5
  73. data/spec/lib/authorities/linked_data/find_term_spec.rb +3 -1
  74. data/spec/lib/authorities/linked_data/generic_authority_spec.rb +92 -42
  75. data/spec/lib/authorities/linked_data/search_config_spec.rb +67 -160
  76. data/spec/lib/authorities/linked_data/search_query_spec.rb +3 -127
  77. data/spec/lib/authorities/linked_data/term_config_spec.rb +6 -134
  78. data/spec/lib/authorities/loc_spec.rb +9 -9
  79. data/spec/lib/configuration_spec.rb +20 -7
  80. data/spec/lib/tasks/mesh.rake_spec.rb +2 -2
  81. data/spec/models/iri_template/url_config_spec.rb +102 -0
  82. data/spec/models/iri_template/variable_map_spec.rb +105 -0
  83. data/spec/models/linked_data/config/context_map_spec.rb +148 -0
  84. data/spec/models/linked_data/config/context_property_map_spec.rb +286 -0
  85. data/spec/services/iri_template_service_spec.rb +69 -0
  86. data/spec/services/linked_data/authority_url_service_spec.rb +107 -0
  87. data/spec/services/linked_data/deep_sort_service_spec.rb +260 -0
  88. data/spec/services/linked_data/graph_service_spec.rb +232 -0
  89. data/spec/services/linked_data/language_service_spec.rb +66 -0
  90. data/spec/services/linked_data/language_sort_service_spec.rb +58 -0
  91. data/spec/services/linked_data/mapper/context_mapper_service_spec.rb +137 -0
  92. data/spec/services/linked_data/mapper/graph_mapper_service_spec.rb +110 -0
  93. data/spec/services/linked_data/mapper/search_results_mapper_service_spec.rb +109 -0
  94. data/spec/spec_helper.rb +10 -2
  95. metadata +81 -11
@@ -1,131 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
4
- describe "#sort_search_results" do
5
- let(:config) { Qa::Authorities::LinkedData::Config.new(auth_name).search }
6
- let(:instance) { described_class.new(config) }
7
-
8
- let(:term_a) { "alpha" }
9
- let(:term_b) { "bravo" }
10
- let(:term_c) { "charlie" }
11
- let(:term_d) { "delta" }
12
-
13
- context 'when sort predicate is NOT specified in configuration' do
14
- let(:auth_name) { :LOD_MIN_CONFIG }
15
-
16
- it "does not change order" do
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] }]
20
- expect(instance.send(:sort_search_results, json_results)).to eq json_results
21
- end
22
- end
23
-
24
- context 'when sort predicate is specified in configuration' do
25
- let(:auth_name) { :LOD_SORT }
26
-
27
- context "and sort term is empty" do
28
- context "for all" do
29
- it "does not change order" do
30
- json_results = [{ label: "[#{term_b}]", sort: [""] },
31
- { label: "[#{term_a}]", sort: [""] },
32
- { label: "[#{term_c}]", sort: [""] }]
33
- expect(instance.send(:sort_search_results, json_results)).to eq json_results
34
- end
35
- end
36
-
37
- context "for one" do
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}]" }]
65
- expect(instance.send(:sort_search_results, json_results)).to eq expected_results
66
- end
67
- end
68
- end
69
-
70
- context "and sort term is single value" do
71
- context "for all" do
72
- it "sorts on the single value" do
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}]" }]
79
- expect(instance.send(:sort_search_results, json_results)).to eq expected_results
80
- end
81
- end
82
- end
83
-
84
- context "when first sort term is same" do
85
- it "sorts on second sort term" do
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}]" }]
92
- expect(instance.send(:sort_search_results, json_results)).to eq expected_results
93
- end
94
- end
95
-
96
- context "when different number of sort terms" do
97
- context "and initial terms match" do
98
- it "puts shorter set of terms before longer set" do
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}]" }]
105
- expect(instance.send(:sort_search_results, json_results)).to eq expected_results
106
- end
107
- end
108
-
109
- context "and a difference happens before end of term sets" do
110
- it "stops ordering as soon as a difference is found" do
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}]" }]
117
- expect(instance.send(:sort_search_results, json_results)).to eq expected_results
118
- end
119
- end
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
129
- end
130
- end
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"
131
7
  end
@@ -12,7 +12,7 @@ describe Qa::Authorities::LinkedData::TermConfig do
12
12
  url: {
13
13
  :@context => 'http://www.w3.org/ns/hydra/context.jsonld',
14
14
  :@type => 'IriTemplate',
15
- template: 'http://localhost/test_default/term/{?subauth}/{?term_id}?param1={?param1}&param2={?param2}',
15
+ template: 'http://localhost/test_default/term/{subauth}/{term_id}?{?param1}&{?param2}',
16
16
  variableRepresentation: 'BasicRepresentation',
17
17
  mapping: [
18
18
  {
@@ -83,12 +83,12 @@ describe Qa::Authorities::LinkedData::TermConfig do
83
83
  end
84
84
  end
85
85
 
86
- describe '#term_url' do
86
+ describe '#url_config' do
87
87
  let(:url_config) do
88
88
  {
89
89
  :@context => 'http://www.w3.org/ns/hydra/context.jsonld',
90
90
  :@type => 'IriTemplate',
91
- template: 'http://localhost/test_default/term/{?subauth}/{?term_id}?param1={?param1}&param2={?param2}',
91
+ template: 'http://localhost/test_default/term/{subauth}/{term_id}?{?param1}&{?param2}',
92
92
  variableRepresentation: 'BasicRepresentation',
93
93
  mapping: [
94
94
  {
@@ -123,20 +123,10 @@ describe Qa::Authorities::LinkedData::TermConfig do
123
123
  end
124
124
 
125
125
  it 'returns nil if only search configuration is defined' do
126
- expect(search_only_config.term_url).to eq nil
126
+ expect(search_only_config.url_config).to eq nil
127
127
  end
128
- it 'returns the term url from the configuration' do
129
- expect(full_config.term_url).to eq url_config
130
- end
131
- end
132
-
133
- describe '#term_url' do
134
- it 'returns nil if only search configuration is defined' do
135
- expect(search_only_config.term_url_template).to eq nil
136
- end
137
- it 'returns the term url from the configuration' do
138
- expected_url = 'http://localhost/test_default/term/{?subauth}/{?term_id}?param1={?param1}&param2={?param2}'
139
- expect(full_config.term_url_template).to eq expected_url
128
+ it 'returns the url config from the configuration' do
129
+ expect(full_config.url_config).to be_kind_of Qa::IriTemplate::UrlConfig
140
130
  end
141
131
  end
142
132
 
@@ -255,48 +245,6 @@ describe Qa::Authorities::LinkedData::TermConfig do
255
245
  end
256
246
  end
257
247
 
258
- describe '#term_replacements?' do
259
- it 'returns false if only search configuration is defined' do
260
- expect(search_only_config.term_replacements?).to eq false
261
- end
262
- it 'returns false if the configuration does NOT define replacements' do
263
- expect(min_config.term_replacements?).to eq false
264
- end
265
- it 'returns true if the configuration defines replacements' do
266
- expect(full_config.term_replacements?).to eq true
267
- end
268
- end
269
-
270
- describe '#term_replacement_count' do
271
- it 'returns 0 if only search configuration is defined' do
272
- expect(search_only_config.term_replacement_count).to eq 0
273
- end
274
- it 'returns 0 if replacement_count is NOT defined' do
275
- expect(min_config.term_replacement_count).to eq 0
276
- end
277
- it 'returns the number of replacements if defined' do
278
- expect(full_config.term_replacement_count).to eq 2
279
- end
280
- end
281
-
282
- describe '#term_replacements' do
283
- it 'returns empty hash if only search configuration is defined' do
284
- empty_hash = {}
285
- expect(search_only_config.term_replacements).to eq empty_hash
286
- end
287
- it 'returns empty hash if no replacement patterns are defined' do
288
- empty_hash = {}
289
- expect(min_config.term_replacements).to eq empty_hash
290
- end
291
- it 'returns hash of all replacement patterns' do
292
- expected_hash = {
293
- param1: { :@type => 'IriTemplateMapping', variable: 'param1', property: 'hydra:freetextQuery', required: false, default: 'alpha' },
294
- param2: { :@type => 'IriTemplateMapping', variable: 'param2', property: 'hydra:freetextQuery', required: false, default: 'beta' }
295
- }
296
- expect(full_config.term_replacements).to eq expected_hash
297
- end
298
- end
299
-
300
248
  describe '#term_subauthorities?' do
301
249
  it 'returns false if only search configuration is defined' do
302
250
  expect(search_only_config.term_subauthorities?).to eq false
@@ -354,80 +302,4 @@ describe Qa::Authorities::LinkedData::TermConfig do
354
302
  expect(full_config.term_subauthorities).to eq expected_hash
355
303
  end
356
304
  end
357
-
358
- describe '#term_subauthority_replacement_pattern' do
359
- it 'returns empty hash if only search configuration is defined' do
360
- empty_hash = {}
361
- expect(search_only_config.term_subauthority_replacement_pattern).to eq empty_hash
362
- end
363
- it 'returns empty hash if no subauthorities are defined' do
364
- empty_hash = {}
365
- expect(min_config.term_subauthority_replacement_pattern).to eq empty_hash
366
- end
367
- it 'returns hash replacement pattern for subauthority and the default value' do
368
- expected_hash = { pattern: 'subauth', default: 'term_sub2_name' }
369
- expect(full_config.term_subauthority_replacement_pattern).to eq expected_hash
370
- end
371
- end
372
-
373
- # rubocop:disable RSpec/RepeatedExample
374
- describe '#term_url_with_replacements' do
375
- it 'returns nil if only search configuration is defined' do
376
- expect(search_only_config.term_url_with_replacements('C123')).to eq nil
377
- end
378
- context 'when subauthorities ARE defined' do
379
- it 'returns the url with query substitution applied' do
380
- expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=alpha&param2=beta'
381
- expect(full_config.term_url_with_replacements('C123')).to eq expected_url
382
- end
383
- it 'returns the url with default subauthority when NOT specified' do
384
- expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=alpha&param2=beta'
385
- expect(full_config.term_url_with_replacements('C123')).to eq expected_url
386
- end
387
- it 'returns the url with subauthority substitution when specified' do
388
- expected_url = 'http://localhost/test_default/term/term_sub3_name/C123?param1=alpha&param2=beta'
389
- expect(full_config.term_url_with_replacements('C123', 'term_sub3_key')).to eq expected_url
390
- end
391
- it 'returns the url with default values when replacements are NOT specified' do
392
- expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=alpha&param2=beta'
393
- expect(full_config.term_url_with_replacements('C123')).to eq expected_url
394
- end
395
- it 'returns the url with replacement substitution values when replacements are specified' do
396
- expected_url = 'http://localhost/test_default/term/term_sub2_name/C123?param1=golf&param2=hotel'
397
- expect(full_config.term_url_with_replacements('C123', nil, param1: 'golf', param2: 'hotel')).to eq expected_url
398
- end
399
- end
400
-
401
- context 'when subauthorities are NOT defined' do
402
- it 'returns the url with query substitution applied' do
403
- expected_url = 'http://localhost/test_default/term/C123'
404
- expect(min_config.term_url_with_replacements('C123')).to eq expected_url
405
- end
406
- it 'and subauth param is included returns the url with query substitution applied ignoring the subauth' do
407
- expected_url = 'http://localhost/test_default/term/C123'
408
- expect(min_config.term_url_with_replacements('C123', 'fake_subauth_key')).to eq expected_url
409
- end
410
- end
411
-
412
- context 'when replacements are not defined' do
413
- it 'returns the url with query substitution applied' do
414
- expected_url = 'http://localhost/test_default/term/C123'
415
- expect(min_config.term_url_with_replacements('C123')).to eq expected_url
416
- end
417
- it 'and replacements param is included returns the url with query substitution applied ignoring the replacements' do
418
- expected_url = 'http://localhost/test_default/term/C123'
419
- expect(min_config.term_url_with_replacements('C123', nil, fake_replacement_key: 'fake_value')).to eq expected_url
420
- end
421
- end
422
-
423
- context 'with encoding specified in config' do
424
- it 'returns the uri as the url' do
425
- expected_url = 'http://localhost/test_default/term?uri=http%3A%2F%2Fencoded%2Ebecause%3Fencode%3Dtrue&yes%3Aencoded%20here&no:encoding here&defaults:to not encoded'
426
- term_uri = 'http://encoded.because?encode=true'
427
- replacements = { encode_true: 'yes:encoded here', encode_false: 'no:encoding here', encode_not_specified: 'defaults:to not encoded' }
428
- expect(encoding_config.term_url_with_replacements(term_uri, nil, replacements)).to eq expected_url
429
- end
430
- end
431
- end
432
- # rubocop:enable RSpec/RepeatedExample
433
305
  end
@@ -28,14 +28,14 @@ describe Qa::Authorities::Loc do
28
28
  end
29
29
 
30
30
  context "for searching" do
31
- let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
31
+ let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
32
32
  it "returns a url" do
33
33
  expect(authority.build_query_url("foo")).to eq(url)
34
34
  end
35
35
  end
36
36
 
37
37
  context "for returning single terms" do
38
- let(:url) { "https://id.loc.gov/authorities/subjects/sh2002003586.json" }
38
+ let(:url) { "http://id.loc.gov/authorities/subjects/sh2002003586.json" }
39
39
  it "returns a url with an authority and id" do
40
40
  expect(authority.find_url("sh2002003586")).to eq(url)
41
41
  end
@@ -49,15 +49,15 @@ describe Qa::Authorities::Loc do
49
49
  end
50
50
 
51
51
  before do
52
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
52
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
53
53
  .with(headers: { 'Accept' => 'application/json' })
54
54
  .to_return(status: 200, body: "")
55
55
  end
56
56
 
57
57
  context "with flat params encoded" do
58
- let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
58
+ let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
59
59
  it "returns a response" do
60
- flat_params_url = "https://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
60
+ flat_params_url = "http://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
61
61
  expect(subject.env.url.to_s).to eq(flat_params_url)
62
62
  end
63
63
  end
@@ -66,7 +66,7 @@ describe Qa::Authorities::Loc do
66
66
  describe "#search" do
67
67
  context "any LOC authorities" do
68
68
  let :authority do
69
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
69
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
70
70
  .with(headers: { 'Accept' => 'application/json' })
71
71
  .to_return(body: webmock_fixture("loc-response.txt"), status: 200)
72
72
  described_class.subauthority_for("geographicAreas")
@@ -95,7 +95,7 @@ describe Qa::Authorities::Loc do
95
95
 
96
96
  context "subject terms" do
97
97
  let :results do
98
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
98
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
99
99
  .with(headers: { 'Accept' => 'application/json' })
100
100
  .to_return(body: webmock_fixture("loc-subjects-response.txt"), status: 200)
101
101
  described_class.subauthority_for("subjects").search("History--")
@@ -111,7 +111,7 @@ describe Qa::Authorities::Loc do
111
111
 
112
112
  context "name terms" do
113
113
  let :results do
114
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
114
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
115
115
  .with(headers: { 'Accept' => 'application/json' })
116
116
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
117
117
  described_class.subauthority_for("names").search("Berry")
@@ -125,7 +125,7 @@ describe Qa::Authorities::Loc do
125
125
  describe "#find" do
126
126
  context "using a subject id" do
127
127
  let :results do
128
- stub_request(:get, "https://id.loc.gov/authorities/subjects/sh2002003586.json")
128
+ stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json")
129
129
  .with(headers: { 'Accept' => 'application/json' })
130
130
  .to_return(status: 200, body: webmock_fixture("loc-subject-find-response.txt"), headers: {})
131
131
  described_class.subauthority_for("subjects").find("sh2002003586")
@@ -1,13 +1,8 @@
1
+ require 'spec_helper'
2
+
1
3
  RSpec.describe Qa::Configuration do
2
4
  subject { described_class.new }
3
5
 
4
- it { is_expected.to respond_to(:cors_headers?) }
5
- it { is_expected.to respond_to(:enable_cors_headers) }
6
- it { is_expected.to respond_to(:disable_cors_headers) }
7
- it { is_expected.to respond_to(:authorized_reload_token=) }
8
- it { is_expected.to respond_to(:authorized_reload_token) }
9
- it { is_expected.to respond_to(:valid_authority_reload_token?) }
10
-
11
6
  describe '#enable_cors_headers' do
12
7
  it 'turns on cors headers support' do
13
8
  subject.enable_cors_headers
@@ -55,4 +50,22 @@ RSpec.describe Qa::Configuration do
55
50
  end
56
51
  end
57
52
  end
53
+
54
+ describe '#default_language' do
55
+ context 'when NOT configured' do
56
+ it 'returns :en as the default language' do
57
+ expect(subject.default_language).to be :en
58
+ end
59
+ end
60
+
61
+ context 'when configured' do
62
+ before do
63
+ subject.default_language = [:fr]
64
+ end
65
+
66
+ it 'returns the configured default language' do
67
+ expect(subject.default_language).to match_array [:fr]
68
+ end
69
+ end
70
+ end
58
71
  end
@@ -10,8 +10,8 @@ describe "mesh rake tasks" do # rubocop:disable RSpec/DescribeClass
10
10
  Rake::Task.define_task(:environment) # rspec has loaded rails
11
11
  end
12
12
 
13
- describe "mesh:import" do
14
- let(:task_name) { "mesh:import" }
13
+ describe "qa:mesh:import" do
14
+ let(:task_name) { "qa:mesh:import" }
15
15
  let(:output) { StringIO.new }
16
16
  before do
17
17
  $stdout = output # rubocop:disable RSpec/ExpectOutput # TODO: Explore how to remove this disable
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Qa::IriTemplate::UrlConfig do
4
+ let(:url_template) do
5
+ {
6
+ :"@context" => "http://www.w3.org/ns/hydra/context.jsonld",
7
+ :"@type" => "IriTemplate",
8
+ template: "http://localhost/test_default/search?{?subauth}&{?query}&{?param1}&{?param2}",
9
+ variableRepresentation: "BasicRepresentation",
10
+ mapping: [
11
+ {
12
+ :"@type" => "IriTemplateMapping",
13
+ variable: "query",
14
+ property: "hydra:freetextQuery",
15
+ required: true
16
+ },
17
+ {
18
+ :"@type" => "IriTemplateMapping",
19
+ variable: "subauth",
20
+ property: "hydra:freetextQuery",
21
+ required: false,
22
+ default: "search_sub1_name"
23
+ },
24
+ {
25
+ :"@type" => "IriTemplateMapping",
26
+ variable: "param1",
27
+ property: "hydra:freetextQuery",
28
+ required: false,
29
+ default: "delta"
30
+ },
31
+ {
32
+ :"@type" => "IriTemplateMapping",
33
+ variable: "param2",
34
+ property: "hydra:freetextQuery",
35
+ required: false,
36
+ default: "echo"
37
+ }
38
+ ]
39
+ }
40
+ end
41
+
42
+ describe 'model attributes' do
43
+ subject { described_class.new(url_template) }
44
+
45
+ it { is_expected.to respond_to :template }
46
+ it { is_expected.to respond_to :variable_representation }
47
+ it { is_expected.to respond_to :mapping }
48
+ end
49
+
50
+ describe '#new' do
51
+ context 'when missing template' do
52
+ before do
53
+ allow(url_template).to receive(:fetch).with(:template, nil).and_return(nil)
54
+ end
55
+
56
+ it 'raises an error' do
57
+ expect { described_class.new(url_template) }.to raise_error(Qa::InvalidConfiguration, 'template is required')
58
+ end
59
+ end
60
+
61
+ context 'when missing mapping' do
62
+ before do
63
+ allow(url_template).to receive(:fetch).with(:template, nil).and_return("http://localhost/test_default/search?{?subauth}&{?query}&{?param1}&{?param2}")
64
+ allow(url_template).to receive(:fetch).with(:mapping, nil).and_return(nil)
65
+ end
66
+
67
+ it 'raises an error' do
68
+ expect { described_class.new(url_template) }.to raise_error(Qa::InvalidConfiguration, 'mapping is required')
69
+ end
70
+ end
71
+
72
+ context 'when no maps defined' do
73
+ before do
74
+ allow(url_template).to receive(:fetch).with(:template, nil).and_return("http://localhost/test_default/search?{?subauth}&{?query}&{?param1}&{?param2}")
75
+ allow(url_template).to receive(:fetch).with(:mapping, nil).and_return([])
76
+ end
77
+
78
+ it 'raises an error' do
79
+ expect { described_class.new(url_template) }.to raise_error(Qa::InvalidConfiguration, 'mapping must include at least one map')
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#template' do
85
+ subject { described_class.new(url_template) }
86
+
87
+ it 'returns the configured url template' do
88
+ expect(subject.template).to eq 'http://localhost/test_default/search?{?subauth}&{?query}&{?param1}&{?param2}'
89
+ end
90
+ end
91
+
92
+ describe '#mapping' do
93
+ subject { described_class.new(url_template) }
94
+
95
+ it 'returns an array of variable maps' do
96
+ mapping = subject.mapping
97
+ expect(mapping).to be_kind_of Array
98
+ expect(mapping.size).to eq 4
99
+ expect(mapping.first).to be_kind_of Qa::IriTemplate::VariableMap
100
+ end
101
+ end
102
+ end