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.
- checksums.yaml +5 -5
- data/README.md +54 -6
- data/app/controllers/qa/application_controller.rb +24 -0
- data/app/controllers/qa/linked_data_terms_controller.rb +116 -51
- data/app/controllers/qa/terms_controller.rb +7 -2
- data/app/models/qa/mesh_tree.rb +5 -9
- data/app/models/qa/subject_mesh_term.rb +2 -7
- data/config/authorities/linked_data/agrovoc.json +8 -1
- data/config/initializers/linked_data_authorities.rb +1 -17
- data/config/routes.rb +11 -0
- data/lib/generators/qa/apidoc/USAGE +11 -0
- data/lib/generators/qa/apidoc/apidoc_generator.rb +22 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/apidoc.json +1322 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-16x16.png +0 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-32x32.png +0 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/index.html +61 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/oauth2-redirect.html +67 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js +93 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js.map +1 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js +14 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js.map +1 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css +3 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css.map +1 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js +9 -0
- data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js.map +1 -0
- data/lib/generators/qa/install/install_generator.rb +11 -0
- data/lib/generators/qa/install/templates/config/initializers/qa.rb +13 -0
- data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +1 -1
- data/lib/generators/qa/local/tables/tables_generator.rb +1 -1
- data/lib/qa.rb +16 -0
- data/lib/qa/authorities/assign_fast_subauthority.rb +3 -3
- data/lib/qa/authorities/getty/aat.rb +13 -6
- data/lib/qa/authorities/getty/tgn.rb +11 -22
- data/lib/qa/authorities/getty/ulan.rb +13 -16
- data/lib/qa/authorities/linked_data.rb +1 -0
- data/lib/qa/authorities/linked_data/authority_service.rb +47 -0
- data/lib/qa/authorities/linked_data/config.rb +9 -3
- data/lib/qa/authorities/linked_data/config/search_config.rb +16 -2
- data/lib/qa/authorities/linked_data/config/term_config.rb +17 -3
- data/lib/qa/authorities/linked_data/find_term.rb +4 -3
- data/lib/qa/authorities/linked_data/generic_authority.rb +8 -1
- data/lib/qa/authorities/linked_data/rdf_helper.rb +15 -0
- data/lib/qa/authorities/linked_data/search_query.rb +19 -3
- data/lib/qa/authorities/loc/generic_authority.rb +2 -2
- data/lib/qa/authorities/loc_subauthority.rb +2 -2
- data/lib/qa/authorities/local.rb +2 -4
- data/lib/qa/authorities/local/file_based_authority.rb +1 -1
- data/lib/qa/authorities/local/mysql_table_based_authority.rb +11 -2
- data/lib/qa/authorities/local/table_based_authority.rb +2 -1
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +1 -1
- data/lib/qa/authorities/mesh_tools/mesh_importer.rb +1 -1
- data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +1 -3
- data/lib/qa/configuration.rb +34 -0
- data/lib/qa/version.rb +1 -1
- data/lib/tasks/mesh.rake +3 -3
- data/spec/controllers/linked_data_terms_controller_spec.rb +247 -18
- data/spec/controllers/terms_controller_spec.rb +87 -12
- data/spec/fixtures/authorities/linked_data/lod_encoding_config.json +91 -0
- data/spec/fixtures/authorities/linked_data/lod_term_id_param_config.json +27 -0
- data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +27 -0
- data/spec/fixtures/{lexvo_snippet.rdf → lexvo_snippet.rdf.xml} +1 -0
- data/spec/lib/authorities/assign_fast_spec.rb +3 -1
- data/spec/lib/authorities/file_based_authority_spec.rb +19 -11
- data/spec/lib/authorities/geonames_spec.rb +3 -3
- data/spec/lib/authorities/getty/aat_spec.rb +14 -8
- data/spec/lib/authorities/getty/tgn_spec.rb +8 -15
- data/spec/lib/authorities/getty/ulan_spec.rb +8 -6
- data/spec/lib/authorities/getty_spec.rb +2 -1
- data/spec/lib/authorities/linked_data/authority_service_spec.rb +47 -0
- data/spec/lib/authorities/linked_data/generic_authority_spec.rb +56 -14
- data/spec/lib/authorities/linked_data/search_config_spec.rb +33 -19
- data/spec/lib/authorities/linked_data/search_query_spec.rb +67 -15
- data/spec/lib/authorities/linked_data/term_config_spec.rb +34 -20
- data/spec/lib/authorities/loc_spec.rb +9 -9
- data/spec/lib/authorities/local_spec.rb +7 -8
- data/spec/lib/authorities/oclcts_spec.rb +27 -20
- data/spec/lib/authorities/table_based_authority_spec.rb +5 -3
- data/spec/lib/authorities_loc_subauthorities.rb +2 -2
- data/spec/lib/configuration_spec.rb +58 -0
- data/spec/lib/mesh_data_parser_spec.rb +2 -0
- data/spec/lib/services/rdf_authority_parser_spec.rb +1 -1
- data/spec/lib/tasks/mesh.rake_spec.rb +13 -12
- data/spec/models/subject_mesh_term_spec.rb +2 -0
- data/spec/requests/cors_headers_spec.rb +118 -0
- data/spec/spec_helper.rb +2 -2
- metadata +167 -137
|
@@ -9,7 +9,8 @@ module Qa::Authorities
|
|
|
9
9
|
@checked_for_index ||= begin
|
|
10
10
|
conn = ActiveRecord::Base.connection
|
|
11
11
|
if table_or_view_exists? && !conn.indexes(table_name).find { |i| i.name == table_index }
|
|
12
|
-
Rails.logger.error "You've installed local authority tables, but you haven't indexed the label.
|
|
12
|
+
Rails.logger.error "You've installed local authority tables, but you haven't indexed the label. " \
|
|
13
|
+
"Rails doesn't support functional indexes in migrations, so you'll have to add this manually:\n" \
|
|
13
14
|
"CREATE INDEX \"#{table_index}\" ON \"#{table_name}\" (local_authority_id, lower(label))\n" \
|
|
14
15
|
" OR on Sqlite: \n" \
|
|
15
16
|
"CREATE INDEX \"#{table_index}\" ON \"#{table_name}\" (local_authority_id, label collate nocase)\n" \
|
|
@@ -27,9 +27,7 @@ module Qa::Authorities
|
|
|
27
27
|
a = {}
|
|
28
28
|
zthes_record = raw_response.xpath("sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/Zthes/term[termId='#{id}']", 'sru' => 'http://www.loc.gov/zing/srw/')
|
|
29
29
|
zthes_record.children.each do |child|
|
|
30
|
-
if (child.is_a? Nokogiri::XML::Element) && !child.children.nil? && (child.children.size == 1) && (child.children.first.is_a? Nokogiri::XML::Text)
|
|
31
|
-
a[child.name] = child.children.first.to_s
|
|
32
|
-
end
|
|
30
|
+
a[child.name] = child.children.first.to_s if (child.is_a? Nokogiri::XML::Element) && !child.children.nil? && (child.children.size == 1) && (child.children.first.is_a? Nokogiri::XML::Text)
|
|
33
31
|
end
|
|
34
32
|
a
|
|
35
33
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Qa
|
|
2
|
+
class Configuration
|
|
3
|
+
def cors_headers?
|
|
4
|
+
return @cors_headers_enabled unless @cors_headers_enabled.nil?
|
|
5
|
+
@cors_headers_enabled = false
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def enable_cors_headers
|
|
9
|
+
@cors_headers_enabled = true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def disable_cors_headers
|
|
13
|
+
@cors_headers_enabled = false
|
|
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
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/qa/version.rb
CHANGED
data/lib/tasks/mesh.rake
CHANGED
|
@@ -2,11 +2,12 @@ require 'benchmark'
|
|
|
2
2
|
|
|
3
3
|
namespace :mesh do
|
|
4
4
|
desc "Import MeSH terms from the file $MESH_FILE, it will update any terms which are already in the database"
|
|
5
|
-
task :import => :environment do
|
|
5
|
+
# task :import => :environment do
|
|
6
|
+
task import: :environment do
|
|
6
7
|
fname = ENV['MESH_FILE']
|
|
7
8
|
if fname.nil?
|
|
8
9
|
puts "Need to set $MESH_FILE with path to file to ingest"
|
|
9
|
-
next
|
|
10
|
+
next # transfers control out of this block
|
|
10
11
|
end
|
|
11
12
|
Benchmark.bm(30) do |bm|
|
|
12
13
|
bm.report("Importing #{fname}") do
|
|
@@ -22,5 +23,4 @@ namespace :mesh do
|
|
|
22
23
|
task :clear do
|
|
23
24
|
puts "Not implemented"
|
|
24
25
|
end
|
|
25
|
-
|
|
26
26
|
end
|
|
@@ -6,13 +6,13 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
describe '#check_authority' do
|
|
9
|
-
it 'returns 400 if the vocabulary is not specified' do
|
|
9
|
+
it 'for search returns 400 if the vocabulary is not specified' do
|
|
10
10
|
expect(Rails.logger).to receive(:warn).with("Required param 'vocab' is missing or empty")
|
|
11
11
|
get :search, params: { q: 'a query', vocab: '' }
|
|
12
12
|
expect(response.code).to eq('400')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
it 'returns 400 if the vocabulary is not specified' do
|
|
15
|
+
it 'for show returns 400 if the vocabulary is not specified' do
|
|
16
16
|
expect(Rails.logger).to receive(:warn).with("Required param 'vocab' is missing or empty")
|
|
17
17
|
get :show, params: { id: 'C_1234', vocab: '' }
|
|
18
18
|
expect(response.code).to eq('400')
|
|
@@ -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
|
|
@@ -92,7 +112,8 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
92
112
|
allow(RDF::Graph).to receive(:load).and_raise(RDF::FormatError)
|
|
93
113
|
end
|
|
94
114
|
it 'returns 500' do
|
|
95
|
-
|
|
115
|
+
msg = "RDF Format Error - Results from search query my_query for authority OCLC_FAST was not identified as a valid RDF format. You may need to include the linkeddata gem."
|
|
116
|
+
expect(Rails.logger).to receive(:warn).with(msg)
|
|
96
117
|
get :search, params: { q: 'my_query', vocab: 'OCLC_FAST', maximumRecords: '3' }
|
|
97
118
|
expect(response.code).to eq('500')
|
|
98
119
|
end
|
|
@@ -122,6 +143,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
122
143
|
expect(response.code).to eq('503')
|
|
123
144
|
end
|
|
124
145
|
end
|
|
146
|
+
|
|
125
147
|
context 'in OCLC_FAST authority' do
|
|
126
148
|
context '0 search results' do
|
|
127
149
|
before do
|
|
@@ -130,7 +152,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
130
152
|
end
|
|
131
153
|
it 'succeeds' do
|
|
132
154
|
get :search, params: { q: 'supercalifragilisticexpialidocious', vocab: 'OCLC_FAST', maximumRecords: '3' }
|
|
133
|
-
expect(response).to
|
|
155
|
+
expect(response).to be_successful
|
|
134
156
|
end
|
|
135
157
|
end
|
|
136
158
|
|
|
@@ -141,7 +163,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
141
163
|
end
|
|
142
164
|
it 'succeeds' do
|
|
143
165
|
get :search, params: { q: 'cornell', vocab: 'OCLC_FAST', maximumRecords: '3' }
|
|
144
|
-
expect(response).to
|
|
166
|
+
expect(response).to be_successful
|
|
145
167
|
end
|
|
146
168
|
end
|
|
147
169
|
end
|
|
@@ -154,7 +176,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
154
176
|
end
|
|
155
177
|
it 'succeeds' do
|
|
156
178
|
get :search, params: { q: 'supercalifragilisticexpialidocious', vocab: 'OCLC_FAST', subauthority: 'personal_name', maximumRecords: '3' }
|
|
157
|
-
expect(response).to
|
|
179
|
+
expect(response).to be_successful
|
|
158
180
|
end
|
|
159
181
|
end
|
|
160
182
|
|
|
@@ -165,7 +187,31 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
165
187
|
end
|
|
166
188
|
it 'succeeds' do
|
|
167
189
|
get :search, params: { q: 'cornell', vocab: 'OCLC_FAST', subauthority: 'personal_name', maximumRecords: '3' }
|
|
168
|
-
expect(response).to
|
|
190
|
+
expect(response).to be_successful
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
context 'when cors headers are enabled' do
|
|
195
|
+
before do
|
|
196
|
+
Qa.config.enable_cors_headers
|
|
197
|
+
stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22cornell%22&sortKeys=usage')
|
|
198
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
199
|
+
end
|
|
200
|
+
it 'Access-Control-Allow-Origin is *' do
|
|
201
|
+
get :search, params: { q: 'cornell', vocab: 'OCLC_FAST', subauthority: 'personal_name', maximumRecords: '3' }
|
|
202
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
context 'when cors headers are disabled' do
|
|
207
|
+
before do
|
|
208
|
+
Qa.config.disable_cors_headers
|
|
209
|
+
stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22cornell%22&sortKeys=usage')
|
|
210
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
211
|
+
end
|
|
212
|
+
it 'Access-Control-Allow-Origin is not present' do
|
|
213
|
+
get :search, params: { q: 'cornell', vocab: 'OCLC_FAST', subauthority: 'personal_name', maximumRecords: '3' }
|
|
214
|
+
expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
|
|
169
215
|
end
|
|
170
216
|
end
|
|
171
217
|
end
|
|
@@ -173,23 +219,23 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
173
219
|
context 'in AGROVOC authority' do
|
|
174
220
|
context '0 search results' do
|
|
175
221
|
before do
|
|
176
|
-
stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/search/?lang=en&query=*supercalifragilisticexpialidocious
|
|
222
|
+
stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/search/?lang=en&query=*supercalifragilisticexpialidocious*&maxhits=20')
|
|
177
223
|
.to_return(status: 200, body: webmock_fixture('lod_agrovoc_query_no_results.json'), headers: { 'Content-Type' => 'application/json' })
|
|
178
224
|
end
|
|
179
225
|
it 'succeeds' do
|
|
180
226
|
get :search, params: { q: 'supercalifragilisticexpialidocious', vocab: 'AGROVOC' }
|
|
181
|
-
expect(response).to
|
|
227
|
+
expect(response).to be_successful
|
|
182
228
|
end
|
|
183
229
|
end
|
|
184
230
|
|
|
185
231
|
context '3 search results' do
|
|
186
232
|
before do
|
|
187
|
-
stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/search/?lang=en&query=*milk
|
|
233
|
+
stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/search/?lang=en&query=*milk*&maxhits=20')
|
|
188
234
|
.to_return(status: 200, body: webmock_fixture('lod_agrovoc_query_many_results.json'), headers: { 'Content-Type' => 'application/json' })
|
|
189
235
|
end
|
|
190
236
|
it 'succeeds' do
|
|
191
237
|
get :search, params: { q: 'milk', vocab: 'AGROVOC' }
|
|
192
|
-
expect(response).to
|
|
238
|
+
expect(response).to be_successful
|
|
193
239
|
end
|
|
194
240
|
end
|
|
195
241
|
end
|
|
@@ -214,7 +260,8 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
214
260
|
allow(RDF::Graph).to receive(:load).and_raise(RDF::FormatError)
|
|
215
261
|
end
|
|
216
262
|
it 'returns 500' do
|
|
217
|
-
|
|
263
|
+
msg = "RDF Format Error - Results from fetch term 530369 for authority OCLC_FAST was not identified as a valid RDF format. You may need to include the linkeddata gem."
|
|
264
|
+
expect(Rails.logger).to receive(:warn).with(msg)
|
|
218
265
|
get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
|
|
219
266
|
expect(response.code).to eq('500')
|
|
220
267
|
end
|
|
@@ -245,7 +292,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
245
292
|
|
|
246
293
|
context 'when requested term is not found at the server' do
|
|
247
294
|
before do
|
|
248
|
-
stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID').to_return(status: 404, body: '', headers:
|
|
295
|
+
stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID').to_return(status: 404, body: '', headers: {})
|
|
249
296
|
end
|
|
250
297
|
it 'returns 404' do
|
|
251
298
|
expect(Rails.logger).to receive(:warn).with('Term Not Found - Fetch term FAKE_ID unsuccessful for authority OCLC_FAST')
|
|
@@ -262,7 +309,31 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
262
309
|
end
|
|
263
310
|
it 'succeeds' do
|
|
264
311
|
get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
|
|
265
|
-
expect(response).to
|
|
312
|
+
expect(response).to be_successful
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
context 'when cors headers are enabled' do
|
|
317
|
+
before do
|
|
318
|
+
Qa.config.enable_cors_headers
|
|
319
|
+
stub_request(:get, 'http://id.worldcat.org/fast/530369')
|
|
320
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
321
|
+
end
|
|
322
|
+
it 'Access-Control-Allow-Origin is *' do
|
|
323
|
+
get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
|
|
324
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
context 'when cors headers are disabled' do
|
|
329
|
+
before do
|
|
330
|
+
Qa.config.disable_cors_headers
|
|
331
|
+
stub_request(:get, 'http://id.worldcat.org/fast/530369')
|
|
332
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
333
|
+
end
|
|
334
|
+
it 'Access-Control-Allow-Origin is not present' do
|
|
335
|
+
get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
|
|
336
|
+
expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
|
|
266
337
|
end
|
|
267
338
|
end
|
|
268
339
|
end
|
|
@@ -273,9 +344,28 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
273
344
|
stub_request(:get, 'http://artemide.art.uniroma2.it:8081/agrovoc/rest/v1/data?uri=http://aims.fao.org/aos/agrovoc/c_9513')
|
|
274
345
|
.to_return(status: 200, body: webmock_fixture('lod_agrovoc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
275
346
|
end
|
|
276
|
-
|
|
347
|
+
|
|
348
|
+
it 'succeeds and defaults to json content type' do
|
|
277
349
|
get :show, params: { id: 'c_9513', vocab: 'AGROVOC' }
|
|
278
|
-
expect(response).to
|
|
350
|
+
expect(response).to be_successful
|
|
351
|
+
expect(response.content_type).to eq 'application/json'
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
context 'and it was requested as json' do
|
|
355
|
+
it 'succeeds and returns term data as json content type' do
|
|
356
|
+
get :show, params: { id: 'c_9513', vocab: 'AGROVOC', format: 'json' }
|
|
357
|
+
expect(response).to be_successful
|
|
358
|
+
expect(response.content_type).to eq 'application/json'
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
context 'and it was requested as jsonld' do
|
|
363
|
+
it 'succeeds and returns term data as jsonld content type' do
|
|
364
|
+
get :show, params: { id: 'c_9513', vocab: 'AGROVOC', format: 'jsonld' }
|
|
365
|
+
expect(response).to be_successful
|
|
366
|
+
expect(response.content_type).to eq 'application/ld+json'
|
|
367
|
+
expect(JSON.parse(response.body).keys).to match_array ["@context", "@graph"]
|
|
368
|
+
end
|
|
279
369
|
end
|
|
280
370
|
end
|
|
281
371
|
end
|
|
@@ -286,11 +376,150 @@ describe Qa::LinkedDataTermsController, type: :controller do
|
|
|
286
376
|
stub_request(:get, 'http://id.loc.gov/authorities/subjects/sh85118553')
|
|
287
377
|
.to_return(status: 200, body: webmock_fixture('lod_loc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
288
378
|
end
|
|
289
|
-
it 'succeeds' do
|
|
379
|
+
it 'succeeds and defaults to json content type' do
|
|
290
380
|
get :show, params: { id: 'sh85118553', vocab: 'LOC', subauthority: 'subjects' }
|
|
291
|
-
expect(response).to
|
|
381
|
+
expect(response).to be_successful
|
|
382
|
+
expect(response.content_type).to eq 'application/json'
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
describe '#fetch' do
|
|
389
|
+
context 'producing internal server error' do
|
|
390
|
+
context 'when server returns 500' do
|
|
391
|
+
before do
|
|
392
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 500)
|
|
393
|
+
end
|
|
394
|
+
it 'returns 500' do
|
|
395
|
+
expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term http://test.org/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
|
|
396
|
+
get :fetch, params: { vocab: 'LOD_TERM_URI_PARAM_CONFIG', uri: 'http://test.org/530369' }
|
|
397
|
+
expect(response.code).to eq('500')
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
context 'when rdf format error' do
|
|
402
|
+
before do
|
|
403
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 200)
|
|
404
|
+
allow(RDF::Graph).to receive(:load).and_raise(RDF::FormatError)
|
|
405
|
+
end
|
|
406
|
+
it 'returns 500' do
|
|
407
|
+
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. " \
|
|
408
|
+
"You may need to include the linkeddata gem."
|
|
409
|
+
expect(Rails.logger).to receive(:warn).with(msg)
|
|
410
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
|
|
411
|
+
expect(response.code).to eq('500')
|
|
412
|
+
end
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
context "when error isn't specifically handled" do
|
|
416
|
+
before do
|
|
417
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 501)
|
|
418
|
+
end
|
|
419
|
+
it 'returns 500' do
|
|
420
|
+
expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term http://test.org/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
|
|
421
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
|
|
422
|
+
expect(response.code).to eq('500')
|
|
292
423
|
end
|
|
293
424
|
end
|
|
294
425
|
end
|
|
426
|
+
|
|
427
|
+
context 'when service unavailable' do
|
|
428
|
+
before do
|
|
429
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369').to_return(status: 503)
|
|
430
|
+
end
|
|
431
|
+
it 'returns 503' do
|
|
432
|
+
expect(Rails.logger).to receive(:warn).with("Service Unavailable - Fetch term http://test.org/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
|
|
433
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
|
|
434
|
+
expect(response.code).to eq('503')
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
context 'when requested term is not found at the server' do
|
|
439
|
+
before do
|
|
440
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/FAKE_ID').to_return(status: 404, body: '', headers: {})
|
|
441
|
+
end
|
|
442
|
+
it 'returns 404' do
|
|
443
|
+
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')
|
|
444
|
+
get :fetch, params: { uri: 'http://test.org/FAKE_ID', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
|
|
445
|
+
expect(response.code).to eq('404')
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
context 'in LOD_TERM_URI_PARAM_CONFIG authority' do
|
|
450
|
+
context 'term found' do
|
|
451
|
+
before do
|
|
452
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369')
|
|
453
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
it 'succeeds and defaults to json content type' do
|
|
457
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
|
|
458
|
+
expect(response).to be_successful
|
|
459
|
+
expect(response.content_type).to eq 'application/json'
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
context 'and it was requested as json' do
|
|
463
|
+
it 'succeeds and returns term data as json content type' do
|
|
464
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'json' }
|
|
465
|
+
expect(response).to be_successful
|
|
466
|
+
expect(response.content_type).to eq 'application/json'
|
|
467
|
+
end
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
context 'and it was requested as jsonld' do
|
|
471
|
+
it 'succeeds and returns term data as jsonld content type' do
|
|
472
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'jsonld' }
|
|
473
|
+
expect(response).to be_successful
|
|
474
|
+
expect(response.content_type).to eq 'application/ld+json'
|
|
475
|
+
expect(JSON.parse(response.body).keys).to match_array ["@context", "@graph"]
|
|
476
|
+
end
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
context 'when cors headers are enabled' do
|
|
481
|
+
before do
|
|
482
|
+
Qa.config.enable_cors_headers
|
|
483
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369')
|
|
484
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
485
|
+
end
|
|
486
|
+
it 'Access-Control-Allow-Origin is *' do
|
|
487
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
|
|
488
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
context 'when cors headers are disabled' do
|
|
493
|
+
before do
|
|
494
|
+
Qa.config.disable_cors_headers
|
|
495
|
+
stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/530369')
|
|
496
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
|
497
|
+
end
|
|
498
|
+
it 'Access-Control-Allow-Origin is not present' do
|
|
499
|
+
get :fetch, params: { uri: 'http://test.org/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
|
|
500
|
+
expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
describe '#reload' do
|
|
507
|
+
before do
|
|
508
|
+
Qa.config.authorized_reload_token = 'A_TOKEN'
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
context 'when token does not match' do
|
|
512
|
+
it 'returns 401' do
|
|
513
|
+
get :reload, params: { auth_token: 'BAD_TOKEN' }
|
|
514
|
+
expect(response.code).to eq('401')
|
|
515
|
+
end
|
|
516
|
+
end
|
|
517
|
+
|
|
518
|
+
context 'when token does match' do
|
|
519
|
+
it 'returns 200' do
|
|
520
|
+
get :reload, params: { auth_token: 'A_TOKEN' }
|
|
521
|
+
expect(response.code).to eq('200')
|
|
522
|
+
end
|
|
523
|
+
end
|
|
295
524
|
end
|
|
296
525
|
end
|