qa 2.0.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +54 -6
  3. data/app/controllers/qa/application_controller.rb +24 -0
  4. data/app/controllers/qa/linked_data_terms_controller.rb +116 -51
  5. data/app/controllers/qa/terms_controller.rb +7 -2
  6. data/app/models/qa/mesh_tree.rb +5 -9
  7. data/app/models/qa/subject_mesh_term.rb +2 -7
  8. data/config/authorities/linked_data/agrovoc.json +8 -1
  9. data/config/initializers/linked_data_authorities.rb +1 -17
  10. data/config/routes.rb +11 -0
  11. data/lib/generators/qa/apidoc/USAGE +11 -0
  12. data/lib/generators/qa/apidoc/apidoc_generator.rb +22 -0
  13. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/apidoc.json +1322 -0
  14. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-16x16.png +0 -0
  15. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-32x32.png +0 -0
  16. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/index.html +61 -0
  17. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/oauth2-redirect.html +67 -0
  18. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js +93 -0
  19. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js.map +1 -0
  20. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js +14 -0
  21. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js.map +1 -0
  22. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css +3 -0
  23. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css.map +1 -0
  24. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js +9 -0
  25. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js.map +1 -0
  26. data/lib/generators/qa/install/install_generator.rb +11 -0
  27. data/lib/generators/qa/install/templates/config/initializers/qa.rb +13 -0
  28. data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +1 -1
  29. data/lib/generators/qa/local/tables/tables_generator.rb +1 -1
  30. data/lib/qa.rb +16 -0
  31. data/lib/qa/authorities/assign_fast_subauthority.rb +3 -3
  32. data/lib/qa/authorities/getty/aat.rb +13 -6
  33. data/lib/qa/authorities/getty/tgn.rb +11 -22
  34. data/lib/qa/authorities/getty/ulan.rb +13 -16
  35. data/lib/qa/authorities/linked_data.rb +1 -0
  36. data/lib/qa/authorities/linked_data/authority_service.rb +47 -0
  37. data/lib/qa/authorities/linked_data/config.rb +9 -3
  38. data/lib/qa/authorities/linked_data/config/search_config.rb +16 -2
  39. data/lib/qa/authorities/linked_data/config/term_config.rb +17 -3
  40. data/lib/qa/authorities/linked_data/find_term.rb +4 -3
  41. data/lib/qa/authorities/linked_data/generic_authority.rb +8 -1
  42. data/lib/qa/authorities/linked_data/rdf_helper.rb +15 -0
  43. data/lib/qa/authorities/linked_data/search_query.rb +19 -3
  44. data/lib/qa/authorities/loc/generic_authority.rb +2 -2
  45. data/lib/qa/authorities/loc_subauthority.rb +2 -2
  46. data/lib/qa/authorities/local.rb +2 -4
  47. data/lib/qa/authorities/local/file_based_authority.rb +1 -1
  48. data/lib/qa/authorities/local/mysql_table_based_authority.rb +11 -2
  49. data/lib/qa/authorities/local/table_based_authority.rb +2 -1
  50. data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +1 -1
  51. data/lib/qa/authorities/mesh_tools/mesh_importer.rb +1 -1
  52. data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +1 -3
  53. data/lib/qa/configuration.rb +34 -0
  54. data/lib/qa/version.rb +1 -1
  55. data/lib/tasks/mesh.rake +3 -3
  56. data/spec/controllers/linked_data_terms_controller_spec.rb +247 -18
  57. data/spec/controllers/terms_controller_spec.rb +87 -12
  58. data/spec/fixtures/authorities/linked_data/lod_encoding_config.json +91 -0
  59. data/spec/fixtures/authorities/linked_data/lod_term_id_param_config.json +27 -0
  60. data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +27 -0
  61. data/spec/fixtures/{lexvo_snippet.rdf → lexvo_snippet.rdf.xml} +1 -0
  62. data/spec/lib/authorities/assign_fast_spec.rb +3 -1
  63. data/spec/lib/authorities/file_based_authority_spec.rb +19 -11
  64. data/spec/lib/authorities/geonames_spec.rb +3 -3
  65. data/spec/lib/authorities/getty/aat_spec.rb +14 -8
  66. data/spec/lib/authorities/getty/tgn_spec.rb +8 -15
  67. data/spec/lib/authorities/getty/ulan_spec.rb +8 -6
  68. data/spec/lib/authorities/getty_spec.rb +2 -1
  69. data/spec/lib/authorities/linked_data/authority_service_spec.rb +47 -0
  70. data/spec/lib/authorities/linked_data/generic_authority_spec.rb +56 -14
  71. data/spec/lib/authorities/linked_data/search_config_spec.rb +33 -19
  72. data/spec/lib/authorities/linked_data/search_query_spec.rb +67 -15
  73. data/spec/lib/authorities/linked_data/term_config_spec.rb +34 -20
  74. data/spec/lib/authorities/loc_spec.rb +9 -9
  75. data/spec/lib/authorities/local_spec.rb +7 -8
  76. data/spec/lib/authorities/oclcts_spec.rb +27 -20
  77. data/spec/lib/authorities/table_based_authority_spec.rb +5 -3
  78. data/spec/lib/authorities_loc_subauthorities.rb +2 -2
  79. data/spec/lib/configuration_spec.rb +58 -0
  80. data/spec/lib/mesh_data_parser_spec.rb +2 -0
  81. data/spec/lib/services/rdf_authority_parser_spec.rb +1 -1
  82. data/spec/lib/tasks/mesh.rake_spec.rb +13 -12
  83. data/spec/models/subject_mesh_term_spec.rb +2 -0
  84. data/spec/requests/cors_headers_spec.rb +118 -0
  85. data/spec/spec_helper.rb +2 -2
  86. metadata +167 -137
@@ -29,7 +29,16 @@ describe Qa::TermsController, type: :controller do
29
29
  end
30
30
  context "when a sub-authority does not exist" do
31
31
  it "returns 404 if a sub-authority does not exist" do
32
- expect(Rails.logger).to receive(:warn).with("Unable to initialize sub-authority non-existent-subauthority for Qa::Authorities::Loc. Valid sub-authorities are [\"subjects\", \"names\", \"classification\", \"childrensSubjects\", \"genreForms\", \"performanceMediums\", \"graphicMaterials\", \"organizations\", \"relators\", \"countries\", \"ethnographicTerms\", \"geographicAreas\", \"languages\", \"iso639-1\", \"iso639-2\", \"iso639-5\", \"preservation\", \"actionsGranted\", \"agentType\", \"edtf\", \"contentLocationType\", \"copyrightStatus\", \"cryptographicHashFunctions\", \"environmentCharacteristic\", \"environmentPurpose\", \"eventRelatedAgentRole\", \"eventRelatedObjectRole\", \"eventType\", \"formatRegistryRole\", \"hardwareType\", \"inhibitorTarget\", \"inhibitorType\", \"objectCategory\", \"preservationLevelRole\", \"relationshipSubType\", \"relationshipType\", \"rightsBasis\", \"rightsRelatedAgentRole\", \"signatureEncoding\", \"signatureMethod\", \"softwareType\", \"storageMedium\"]")
32
+ msg = "Unable to initialize sub-authority non-existent-subauthority for Qa::Authorities::Loc. Valid sub-authorities are " \
33
+ "[\"subjects\", \"names\", \"classification\", \"childrensSubjects\", \"genreForms\", \"performanceMediums\", " \
34
+ "\"graphicMaterials\", \"organizations\", \"relators\", \"countries\", \"ethnographicTerms\", \"geographicAreas\", " \
35
+ "\"languages\", \"iso639-1\", \"iso639-2\", \"iso639-5\", \"preservation\", \"actionsGranted\", \"agentType\", " \
36
+ "\"edtf\", \"contentLocationType\", \"copyrightStatus\", \"cryptographicHashFunctions\", " \
37
+ "\"environmentCharacteristic\", \"environmentPurpose\", \"eventRelatedAgentRole\", \"eventRelatedObjectRole\", " \
38
+ "\"eventType\", \"formatRegistryRole\", \"hardwareType\", \"inhibitorTarget\", \"inhibitorType\", \"objectCategory\", " \
39
+ "\"preservationLevelRole\", \"relationshipSubType\", \"relationshipType\", \"rightsBasis\", \"rightsRelatedAgentRole\", " \
40
+ "\"signatureEncoding\", \"signatureMethod\", \"softwareType\", \"storageMedium\"]"
41
+ expect(Rails.logger).to receive(:warn).with(msg)
33
42
  get :search, params: { q: "a query", vocab: "loc", subauthority: "non-existent-subauthority" }
34
43
  expect(response.code).to eq("404")
35
44
  end
@@ -63,25 +72,51 @@ describe Qa::TermsController, type: :controller do
63
72
  end
64
73
  it "succeeds" do
65
74
  get :search, params: { q: "a query", vocab: "local", subauthority: "two_args" }
66
- expect(response).to be_success
75
+ expect(response).to be_successful
67
76
  end
68
77
  end
69
78
 
70
79
  context "loc" do
71
80
  before do
72
- 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")
73
82
  .with(headers: { 'Accept' => 'application/json' })
74
83
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
75
84
  end
76
85
 
77
86
  it "returns a set of terms for a tgnlang query" do
78
87
  get :search, params: { q: "Tibetan", vocab: "tgnlang" }
79
- expect(response).to be_success
88
+ expect(response).to be_successful
80
89
  end
81
90
 
82
91
  it "does not return 404 if subauthority is valid" do
83
92
  get :search, params: { q: "Berry", vocab: "loc", subauthority: "names" }
84
- expect(response).to be_success
93
+ expect(response).to be_successful
94
+ end
95
+
96
+ context 'when cors headers are enabled' do
97
+ before do
98
+ Qa.config.enable_cors_headers
99
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
100
+ .with(headers: { 'Accept' => 'application/json' })
101
+ .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
102
+ end
103
+ it 'Access-Control-Allow-Origin is *' do
104
+ get :search, params: { q: "Tibetan", vocab: "tgnlang" }
105
+ expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
106
+ end
107
+ end
108
+
109
+ context 'when cors headers are disabled' do
110
+ before do
111
+ Qa.config.disable_cors_headers
112
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
113
+ .with(headers: { 'Accept' => 'application/json' })
114
+ .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
115
+ end
116
+ it 'Access-Control-Allow-Origin is not present' do
117
+ get :search, params: { q: "Tibetan", vocab: "tgnlang" }
118
+ expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
119
+ end
85
120
  end
86
121
  end
87
122
 
@@ -93,7 +128,7 @@ describe Qa::TermsController, type: :controller do
93
128
  end
94
129
  it "succeeds if authority class is camelcase" do
95
130
  get :search, params: { q: "word", vocab: "assign_fast", subauthority: "topical" }
96
- expect(response).to be_success
131
+ expect(response).to be_successful
97
132
  end
98
133
  end
99
134
  end
@@ -102,11 +137,31 @@ describe Qa::TermsController, type: :controller do
102
137
  context "with supported authorities" do
103
138
  it "returns all local authority state terms" do
104
139
  get :index, params: { vocab: "local", subauthority: "states" }
105
- expect(response).to be_success
140
+ expect(response).to be_successful
106
141
  end
107
142
  it "returns all MeSH terms" do
108
143
  get :index, params: { vocab: "mesh" }
109
- expect(response).to be_success
144
+ expect(response).to be_successful
145
+ end
146
+
147
+ context 'when cors headers are enabled' do
148
+ before do
149
+ Qa.config.enable_cors_headers
150
+ end
151
+ it 'Access-Control-Allow-Origin is *' do
152
+ get :index, params: { vocab: "local", subauthority: "states" }
153
+ expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
154
+ end
155
+ end
156
+
157
+ context 'when cors headers are disabled' do
158
+ before do
159
+ Qa.config.disable_cors_headers
160
+ end
161
+ it 'Access-Control-Allow-Origin is not present' do
162
+ get :index, params: { vocab: "local", subauthority: "states" }
163
+ expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
164
+ end
110
165
  end
111
166
  end
112
167
 
@@ -129,24 +184,44 @@ describe Qa::TermsController, type: :controller do
129
184
  describe "#show" do
130
185
  context "with supported authorities" do
131
186
  before do
132
- stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json")
187
+ stub_request(:get, "https://id.loc.gov/authorities/subjects/sh85077565.json")
133
188
  .with(headers: { 'Accept' => 'application/json' })
134
189
  .to_return(status: 200, body: webmock_fixture("loc-names-response.txt"), headers: {})
135
190
  end
136
191
 
137
192
  it "returns an individual state term" do
138
193
  get :show, params: { vocab: "local", subauthority: "states", id: "OH" }
139
- expect(response).to be_success
194
+ expect(response).to be_successful
140
195
  end
141
196
 
142
197
  it "returns an individual MeSH term" do
143
198
  get :show, params: { vocab: "mesh", id: "D000001" }
144
- expect(response).to be_success
199
+ expect(response).to be_successful
145
200
  end
146
201
 
147
202
  it "returns an individual subject term" do
148
203
  get :show, params: { vocab: "loc", subauthority: "subjects", id: "sh85077565" }
149
- expect(response).to be_success
204
+ expect(response).to be_successful
205
+ end
206
+
207
+ context 'when cors headers are enabled' do
208
+ before do
209
+ Qa.config.enable_cors_headers
210
+ end
211
+ it 'Access-Control-Allow-Origin is *' do
212
+ get :show, params: { vocab: "mesh", id: "D000001" }
213
+ expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
214
+ end
215
+ end
216
+
217
+ context 'when cors headers are disabled' do
218
+ before do
219
+ Qa.config.disable_cors_headers
220
+ end
221
+ it 'Access-Control-Allow-Origin is not present' do
222
+ get :show, params: { vocab: "mesh", id: "D000001" }
223
+ expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
224
+ end
150
225
  end
151
226
  end
152
227
  end
@@ -0,0 +1,91 @@
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}&{?encode_true}&{?encode_false}&{?encode_not_specified}",
7
+ "variableRepresentation": "BasicRepresentation",
8
+ "mapping": [
9
+ {
10
+ "@type": "IriTemplateMapping",
11
+ "variable": "term_uri",
12
+ "property": "hydra:freetextQuery",
13
+ "required": true,
14
+ "encode": true
15
+ },
16
+ {
17
+ "@type": "IriTemplateMapping",
18
+ "variable": "encode_true",
19
+ "property": "hydra:freetextQuery",
20
+ "required": true,
21
+ "encode": true
22
+ },
23
+ {
24
+ "@type": "IriTemplateMapping",
25
+ "variable": "encode_false",
26
+ "property": "hydra:freetextQuery",
27
+ "required": true,
28
+ "encode": false
29
+ },
30
+ {
31
+ "@type": "IriTemplateMapping",
32
+ "variable": "encode_not_specified",
33
+ "property": "hydra:freetextQuery",
34
+ "required": true
35
+ }
36
+ ]
37
+ },
38
+ "qa_replacement_patterns": {
39
+ "term_id": "term_uri"
40
+ },
41
+ "term_id": "URI",
42
+ "results": {
43
+ "id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
44
+ "label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
45
+ }
46
+ },
47
+ "search": {
48
+ "url": {
49
+ "@context": "http://www.w3.org/ns/hydra/context.jsonld",
50
+ "@type": "IriTemplate",
51
+ "template": "http://localhost/test_default/search?query={?query}&{?encode_true}&{?encode_false}&{?encode_not_specified}",
52
+ "variableRepresentation": "BasicRepresentation",
53
+ "mapping": [
54
+ {
55
+ "@type": "IriTemplateMapping",
56
+ "variable": "query",
57
+ "property": "hydra:freetextQuery",
58
+ "required": true,
59
+ "encode": true
60
+ },
61
+ {
62
+ "@type": "IriTemplateMapping",
63
+ "variable": "encode_true",
64
+ "property": "hydra:freetextQuery",
65
+ "required": true,
66
+ "encode": true
67
+ },
68
+ {
69
+ "@type": "IriTemplateMapping",
70
+ "variable": "encode_false",
71
+ "property": "hydra:freetextQuery",
72
+ "required": true,
73
+ "encode": false
74
+ },
75
+ {
76
+ "@type": "IriTemplateMapping",
77
+ "variable": "encode_not_specified",
78
+ "property": "hydra:freetextQuery",
79
+ "required": true
80
+ }
81
+ ]
82
+ },
83
+ "qa_replacement_patterns": {
84
+ "query": "query"
85
+ },
86
+ "results": {
87
+ "id_predicate": "http://purl.org/dc/terms/identifier",
88
+ "label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
89
+ }
90
+ }
91
+ }
@@ -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/{?term_id}",
7
+ "variableRepresentation": "BasicRepresentation",
8
+ "mapping": [
9
+ {
10
+ "@type": "IriTemplateMapping",
11
+ "variable": "term_id",
12
+ "property": "hydra:freetextQuery",
13
+ "required": true
14
+ }
15
+ ]
16
+ },
17
+ "qa_replacement_patterns": {
18
+ "term_id": "term_id"
19
+ },
20
+ "term_id": "ID",
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
+ }
@@ -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
+ }
@@ -89,3 +89,4 @@ Niger–Congo family.</rdfs:comment>
89
89
  <lvont:label rdf:resource="http://lexvo.org/id/term/pms/Lenga%20Ari" /> <!-- Lenga Ari -->
90
90
  <skos:prefLabel xml:lang="en">Ari</skos:prefLabel>
91
91
  </rdf:Description>
92
+ </rdf:RDF>
@@ -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
- expect(Rails.logger).to receive(:info).with("Could not parse response as JSON. Request url: http://fast.oclc.org/searchfast/fastsuggest?&query=word%20ling&queryIndex=suggestall&queryReturn=suggestall%2Cidroot%2Cauth%2Ctype&suggest=autoSubject&rows=20")
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) { [{ 'id' => "A1", 'label' => "Abc Term A1", 'active' => true },
11
- { 'id' => "A2", 'label' => "Term A2", 'active' => false },
12
- { 'id' => "A3", 'label' => "Abc Term A3", 'active' => true }] }
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) { [{ 'id' => "Term B1", 'label' => "Term B1", 'active' => true },
18
- { 'id' => "Term B2", 'label' => "Term B2", 'active' => true },
19
- { 'id' => "Term B3", 'label' => "Term B3", 'active' => true }] }
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) { [{ 'id' => "Term C1", 'label' => "Term C1", 'active' => true },
26
- { 'id' => "Term C2", 'label' => "Term C2", 'active' => true },
27
- { 'id' => "Term C3", 'label' => "Term C3", 'active' => true }] }
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) { [{ 'id' => "A1", 'label' => "Abc Term A1" },
48
- { 'id' => "A3", 'label' => "Abc Term A3" }] }
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
- @original_label = described_class.label
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 = @original_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")
@@ -65,14 +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 { is_expected.to eq 'SELECT ?s ?name {
72
- ?s a skos:Concept; luc:term "search_term";
73
- skos:inScheme <http://vocab.getty.edu/aat/> ;
74
- gvp:prefLabelGVP [skosxl:literalForm ?name].
75
- FILTER regex(?name, "search_term", "i") .
76
- } 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
77
82
  end
83
+ # rubocop:enable Metrics/LineLength
78
84
  end
@@ -65,27 +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
- it { is_expected.to eq 'SELECT DISTINCT ?s ?name ?par {
73
- ?s a skos:Concept; luc:term "search_term";
74
- skos:inScheme <http://vocab.getty.edu/tgn/> ;
75
- gvp:prefLabelGVP [skosxl:literalForm ?name] ;
76
- gvp:parentString ?par .
77
- FILTER regex(?name, "search_term", "i") .
78
- } ORDER BY ?name ASC(?par)' }
72
+ it {
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
+ }
79
75
  end
80
76
  context "using a two subject terms" do
81
77
  subject { authority.sparql('search term') }
82
- it { is_expected.to eq "SELECT DISTINCT ?s ?name ?par {
83
- ?s a skos:Concept; luc:term \"search term\";
84
- skos:inScheme <http://vocab.getty.edu/tgn/> ;
85
- gvp:prefLabelGVP [skosxl:literalForm ?name] ;
86
- gvp:parentString ?par .
87
- 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
- } ORDER BY ?name ASC(?par)" }
78
+ it {
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
+ }
89
81
  end
90
82
  end
83
+ # rubocop:enable Metrics/LineLength
91
84
  end