qa 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -10
- data/app/controllers/qa/terms_controller.rb +5 -1
- data/app/models/qa/mesh_tree.rb +1 -1
- data/lib/qa/authorities.rb +3 -0
- data/lib/qa/authorities/assign_fast/generic_authority.rb +1 -1
- data/lib/qa/authorities/base.rb +28 -10
- data/lib/qa/authorities/geonames.rb +0 -5
- data/lib/qa/authorities/getty/aat.rb +0 -5
- data/lib/qa/authorities/getty/tgn.rb +0 -5
- data/lib/qa/authorities/getty/ulan.rb +0 -5
- data/lib/qa/authorities/loc/generic_authority.rb +13 -2
- data/lib/qa/authorities/local.rb +4 -0
- data/lib/qa/authorities/web_service_base.rb +24 -5
- data/lib/qa/version.rb +1 -1
- data/spec/controllers/terms_controller_spec.rb +18 -18
- data/spec/lib/authorities/base_spec.rb +15 -0
- data/spec/lib/authorities/loc_spec.rb +24 -3
- metadata +43 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1767f3db0da908bb80048b5bf2539e1fb8322915
|
4
|
+
data.tar.gz: 46bd2169de41a30e399fdd7496b5c2606ac311e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e289fd3af18812d896da8dd849d51a13eb7dac73f393aa2c11416c95502a4d0ae0683b1ca95d2bdcec56c3179c082e7835789ecc19db7fe7f5402ebe1ef80e1
|
7
|
+
data.tar.gz: 28879ebb900b2efde296d6f981af7fd0cc18e5e20155c8fbbcbdc909a88321888d36f19644d04ef2e148afd8b1b9550333db8e45cbb4b66ee836133e65a25b15
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ You should question your authorities.
|
|
8
8
|
|
9
9
|
Provides a set of uniform RESTful routes to query any controlled vocabulary or set of authority terms.
|
10
10
|
Results are returned in JSON and can be used within the context of a Rails application or any other
|
11
|
-
Ruby environment. Primary examples would include providing auto-complete functionality via Javascript
|
11
|
+
Ruby environment. Primary examples would include providing auto-complete functionality via Javascript
|
12
12
|
or populating a dropdown menu with a set of terms.
|
13
13
|
|
14
14
|
## How does it work?
|
@@ -163,8 +163,31 @@ Then you can set your username like this:
|
|
163
163
|
Qa::Authorities::Geonames.username = 'myAccountName'
|
164
164
|
|
165
165
|
```
|
166
|
+
### Adding your own authorities
|
166
167
|
|
167
|
-
|
168
|
+
Create an authority file inside your app.
|
169
|
+
|
170
|
+
```
|
171
|
+
app/authorities/qa/authorities/your_authority.rb
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
Write module code with at least a search method.
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
module Qa::Authorities
|
179
|
+
class YourAuthority < Qa::Authorities::Base
|
180
|
+
# Arguments can be (query) or (query, terms_controller)
|
181
|
+
def search(_q)
|
182
|
+
# Should return array of hashes with ids, labels, and values(optional)
|
183
|
+
{ id: '123', label: 'Title', value: 'The Title' }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
### Local Sub-Authorities
|
168
191
|
|
169
192
|
#### In YAML files
|
170
193
|
For simple use cases when you have a few terms that don't change very often.
|
@@ -217,7 +240,7 @@ using the file's name as the sub-authority. For example, if I create `foo.yml`,
|
|
217
240
|
active: false
|
218
241
|
|
219
242
|
|
220
|
-
#### Adding your own local authorities
|
243
|
+
#### Adding your own local sub-authorities
|
221
244
|
|
222
245
|
If you'd like to add your own local authority that isn't necessarily backed by yaml, create an initializer and tell the local authority about your custom sub-authority:
|
223
246
|
|
@@ -256,7 +279,7 @@ This will create two tables/models Qa::LocalAuthority and Qa::LocalAuthorityEntr
|
|
256
279
|
|
257
280
|
Unfortunately, Rails doesn't have a mechnism for adding functional indexes to tables, so if you have a lot of rows, you'll want to add an index:
|
258
281
|
|
259
|
-
CREATE INDEX "index_qa_local_authority_entries_on_lower_label" ON
|
282
|
+
CREATE INDEX "index_qa_local_authority_entries_on_lower_label" ON
|
260
283
|
"qa_local_authority_entries" (local_authority_id, lower(label))
|
261
284
|
|
262
285
|
**Note: If you are using MYSQL as your database and used the MSQL database gerator we tried to execute the correct SQL to create the virtual fields and indexes for you**
|
@@ -267,7 +290,7 @@ Finall you want register your authority in an initializer:
|
|
267
290
|
|
268
291
|
**Note: If you are using MYSQL as your database and used the MSQL database gerator register the MysqlTableBasedAuthority instead of the TableBasedAuthority**
|
269
292
|
|
270
|
-
Then you can search for
|
293
|
+
Then you can search for
|
271
294
|
|
272
295
|
/qa/search/local/languages?q=Fre
|
273
296
|
|
@@ -278,12 +301,12 @@ Results are in JSON.
|
|
278
301
|
The entire list (up to the first 1000 terms) can also be returned using:
|
279
302
|
|
280
303
|
/qa/terms/local/languages/
|
281
|
-
|
304
|
+
|
282
305
|
#### Loading RDF data into database tables
|
283
|
-
|
306
|
+
|
284
307
|
You can use the Qa::Services::RDFAuthorityParser to import rdf files into yopur database tables. See the class file, lib/qa/services/rdf_authority_parser.rb, for examples and more information.
|
285
308
|
To run the class in your local project you must include `gem 'linkeddata'` into your Gemfile and `require 'linkeddata'` into an initializer or your application.rb
|
286
|
-
|
309
|
+
|
287
310
|
### Medical Subject Headings (MeSH)
|
288
311
|
|
289
312
|
Provides autocompletion of [MeSH terms](http://www.nlm.nih.gov/mesh/introduction.html). This
|
@@ -321,7 +344,7 @@ To develop this gem, clone the repository, then run:
|
|
321
344
|
bundle install
|
322
345
|
rake ci
|
323
346
|
|
324
|
-
This will install the gems, create a dummy application under spec/internal and run the tests. After you've made changes,
|
347
|
+
This will install the gems, create a dummy application under spec/internal and run the tests. After you've made changes,
|
325
348
|
make sure you've included tests and run the test suite with a new sample application:
|
326
349
|
|
327
350
|
rake engine_cart:clean
|
@@ -333,7 +356,7 @@ Commit your features into a new branch and submit a pull request.
|
|
333
356
|
|
334
357
|
Currently, it is compatible with Rails 4.0 and 4.1 under both Ruby 2.0 and 2.1.
|
335
358
|
|
336
|
-
# Help
|
359
|
+
# Help
|
337
360
|
|
338
361
|
For help with Questioning Authority, contact <hydra-tech@googlegroups.com>.
|
339
362
|
|
@@ -9,7 +9,11 @@ class Qa::TermsController < ApplicationController
|
|
9
9
|
|
10
10
|
# If the subauthority supports it, return a list of all terms in the authority
|
11
11
|
def index
|
12
|
-
render json:
|
12
|
+
render json: begin
|
13
|
+
@authority.all
|
14
|
+
rescue NotImplementedError
|
15
|
+
nil
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
# Return a list of terms based on a query
|
data/app/models/qa/mesh_tree.rb
CHANGED
data/lib/qa/authorities.rb
CHANGED
data/lib/qa/authorities/base.rb
CHANGED
@@ -1,25 +1,43 @@
|
|
1
1
|
require 'deprecation'
|
2
2
|
|
3
3
|
module Qa::Authorities
|
4
|
+
##
|
5
|
+
# @abstract The base class for all authorites. Implementing subclasses must
|
6
|
+
# provide {#all} and #{find} methods.
|
7
|
+
# @todo What about {#search}?
|
4
8
|
class Base
|
5
9
|
extend Deprecation
|
6
10
|
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
+
##
|
12
|
+
# @abstract By default, #all is not implemented. A subclass authority must
|
13
|
+
# implement this method to conform to the generic interface.
|
14
|
+
#
|
15
|
+
# @return [Enumerable]
|
16
|
+
# @raise [NotImplementedError] when this method is abstract.
|
17
|
+
#
|
18
|
+
# @todo better specify return type
|
11
19
|
def all
|
20
|
+
raise NotImplementedError, "#{self.class}#all is unimplemented."
|
12
21
|
end
|
13
22
|
|
14
|
-
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
23
|
+
##
|
24
|
+
# @abstract By default, #find is not implemented. A subclass authority must
|
25
|
+
# implement this method to conform to the generic interface.
|
26
|
+
#
|
27
|
+
# @param id [String] the id string for the authority to lookup
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
# @raise [NotImplementedError] when this method is abstract.
|
31
|
+
#
|
32
|
+
# @todo better specify return type
|
33
|
+
def find(_id)
|
34
|
+
raise NotImplementedError, "#{self.class}#all is unimplemented."
|
19
35
|
end
|
20
36
|
|
37
|
+
##
|
38
|
+
# @deprecated use {#find} instead
|
21
39
|
def full_record(id, _subauthority = nil)
|
22
|
-
Deprecation.warn(
|
40
|
+
Deprecation.warn('#full_record is deprecated. Use #find instead')
|
23
41
|
find(id)
|
24
42
|
end
|
25
43
|
end
|
@@ -16,11 +16,6 @@ module Qa::Authorities
|
|
16
16
|
parse_authority_response(json(build_query_url(q)))
|
17
17
|
end
|
18
18
|
|
19
|
-
# get_json is not ideomatic, so we'll make an alias
|
20
|
-
def json(*args)
|
21
|
-
get_json(*args)
|
22
|
-
end
|
23
|
-
|
24
19
|
def build_query_url(q)
|
25
20
|
query = URI.escape(untaint(q))
|
26
21
|
"http://api.geonames.org/searchJSON?q=#{query}&username=#{username}&maxRows=10"
|
@@ -6,11 +6,6 @@ module Qa::Authorities
|
|
6
6
|
parse_authority_response(json(build_query_url(q)))
|
7
7
|
end
|
8
8
|
|
9
|
-
# get_json is not ideomatic, so we'll make an alias
|
10
|
-
def json(*args)
|
11
|
-
get_json(*args)
|
12
|
-
end
|
13
|
-
|
14
9
|
def build_query_url(q)
|
15
10
|
"http://vocab.getty.edu/sparql.json?query=#{URI.escape(sparql(q))}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
|
16
11
|
end
|
@@ -6,11 +6,6 @@ module Qa::Authorities
|
|
6
6
|
parse_authority_response(json(build_query_url(q)))
|
7
7
|
end
|
8
8
|
|
9
|
-
# get_json is not ideomatic, so we'll make an alias
|
10
|
-
def json(*args)
|
11
|
-
get_json(*args)
|
12
|
-
end
|
13
|
-
|
14
9
|
def build_query_url(q)
|
15
10
|
query = URI.escape(sparql(untaint(q)))
|
16
11
|
# Replace ampersands, otherwise the query will fail
|
@@ -6,11 +6,6 @@ module Qa::Authorities
|
|
6
6
|
parse_authority_response(json(build_query_url(q)))
|
7
7
|
end
|
8
8
|
|
9
|
-
# get_json is not ideomatic, so we'll make an alias
|
10
|
-
def json(*args)
|
11
|
-
get_json(*args)
|
12
|
-
end
|
13
|
-
|
14
9
|
# Replace ampersands, otherwise the query will fail
|
15
10
|
def build_query_url(q)
|
16
11
|
"http://vocab.getty.edu/sparql.json?query=#{URI.escape(sparql(q)).gsub('&', '%26')}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
|
@@ -7,8 +7,19 @@ module Qa::Authorities
|
|
7
7
|
|
8
8
|
include WebServiceBase
|
9
9
|
|
10
|
+
def response(url)
|
11
|
+
uri = URI(url)
|
12
|
+
conn = Faraday.new "#{uri.scheme}://#{uri.host}"
|
13
|
+
conn.options.params_encoder = Faraday::FlatParamsEncoder
|
14
|
+
conn.get do |req|
|
15
|
+
req.headers['Accept'] = 'application/json'
|
16
|
+
req.url uri.path
|
17
|
+
req.params = Rack::Utils.parse_query(uri.query)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
def search(q)
|
11
|
-
@raw_response =
|
22
|
+
@raw_response = json(build_query_url(q))
|
12
23
|
parse_authority_response
|
13
24
|
end
|
14
25
|
|
@@ -19,7 +30,7 @@ module Qa::Authorities
|
|
19
30
|
end
|
20
31
|
|
21
32
|
def find(id)
|
22
|
-
|
33
|
+
json(find_url(id))
|
23
34
|
end
|
24
35
|
|
25
36
|
def find_url(id)
|
data/lib/qa/authorities/local.rb
CHANGED
@@ -45,6 +45,10 @@ module Qa::Authorities
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
##
|
49
|
+
# Lookup and add the subauthority to the registry. This should only be used for sub-authorities, not stand-alone authorities such as Tgnlang, MESH, etc.
|
50
|
+
# @param subauthority [String] a string representation of the subauthority (e.g. "language")
|
51
|
+
# @param class_name [String] a string representation of an authority class (e.g. "Qa::Authorities::Local::MysqlTableBasedAuthority")
|
48
52
|
def register_subauthority(subauthority, class_name)
|
49
53
|
registry.add(subauthority, class_name)
|
50
54
|
end
|
@@ -1,19 +1,38 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
|
3
3
|
module Qa::Authorities
|
4
|
+
##
|
5
|
+
# Mix-in to retreive and parse JSON content from the web with Faraday.
|
4
6
|
module WebServiceBase
|
7
|
+
##
|
8
|
+
# @!attribute [rw] raw_response
|
5
9
|
attr_accessor :raw_response
|
6
10
|
|
7
|
-
|
8
|
-
|
11
|
+
##
|
12
|
+
# Make a web request & retieve a JSON response for a given URL.
|
13
|
+
#
|
14
|
+
# @param url [String]
|
15
|
+
# @return [Hash] a parsed JSON response
|
16
|
+
def json(url)
|
9
17
|
r = response(url).body
|
10
18
|
JSON.parse(r)
|
11
19
|
end
|
12
20
|
|
21
|
+
##
|
22
|
+
# @deprecated Use #json instead
|
23
|
+
def get_json(url)
|
24
|
+
warn '[DEPRECATED] #get_json is deprecated; use #json instead.' \
|
25
|
+
"Called from #{Gem.location_of_caller.join(':')}."
|
26
|
+
json(url)
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Make a web request and retrieve the response.
|
31
|
+
#
|
32
|
+
# @param url [String]
|
33
|
+
# @return [Faraday::Response]
|
13
34
|
def response(url)
|
14
|
-
Faraday.get(url)
|
15
|
-
req.headers['Accept'] = 'application/json'
|
16
|
-
end
|
35
|
+
Faraday.get(url) { |req| req.headers['Accept'] = 'application/json' }
|
17
36
|
end
|
18
37
|
end
|
19
38
|
end
|
data/lib/qa/version.rb
CHANGED
@@ -7,14 +7,14 @@ describe Qa::TermsController, type: :controller do
|
|
7
7
|
|
8
8
|
describe "#check_vocab_param" do
|
9
9
|
it "returns 404 if the vocabulary is missing" do
|
10
|
-
get :search, q: "a query", vocab: ""
|
10
|
+
get :search, params: { q: "a query", vocab: "" }
|
11
11
|
expect(response.code).to eq("404")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#check_query_param" do
|
16
16
|
it "returns 404 if the query is missing" do
|
17
|
-
get :search, q: "", vocab: "tgnlang"
|
17
|
+
get :search, params: { q: "", vocab: "tgnlang" }
|
18
18
|
expect(response.code).to eq("404")
|
19
19
|
end
|
20
20
|
end
|
@@ -23,24 +23,24 @@ describe Qa::TermsController, type: :controller do
|
|
23
23
|
context "when the authority does not exist" do
|
24
24
|
it "returns 404" do
|
25
25
|
expect(Rails.logger).to receive(:warn).with("Unable to initialize authority Qa::Authorities::Non-existent-authority")
|
26
|
-
get :search, q: "a query", vocab: "non-existent-authority"
|
26
|
+
get :search, params: { q: "a query", vocab: "non-existent-authority" }
|
27
27
|
expect(response.code).to eq("404")
|
28
28
|
end
|
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
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\"]")
|
33
|
-
get :search, q: "a query", vocab: "loc", subauthority: "non-existent-subauthority"
|
33
|
+
get :search, params: { q: "a query", vocab: "loc", subauthority: "non-existent-subauthority" }
|
34
34
|
expect(response.code).to eq("404")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
context "when a sub-authority is absent" do
|
38
38
|
it "returns 404 for LOC" do
|
39
|
-
get :search, q: "a query", vocab: "loc"
|
39
|
+
get :search, params: { q: "a query", vocab: "loc" }
|
40
40
|
expect(response.code).to eq("404")
|
41
41
|
end
|
42
42
|
it "returns 404 for oclcts" do
|
43
|
-
get :search, q: "a query", vocab: "oclcts"
|
43
|
+
get :search, params: { q: "a query", vocab: "oclcts" }
|
44
44
|
expect(response.code).to eq("404")
|
45
45
|
end
|
46
46
|
end
|
@@ -62,7 +62,7 @@ describe Qa::TermsController, type: :controller do
|
|
62
62
|
Qa::Authorities::Local.register_subauthority('two_args', 'Qa::Authorities::Local::TwoArgs')
|
63
63
|
end
|
64
64
|
it "succeeds" do
|
65
|
-
get :search, q: "a query", vocab: "local", subauthority: "two_args"
|
65
|
+
get :search, params: { q: "a query", vocab: "local", subauthority: "two_args" }
|
66
66
|
expect(response).to be_success
|
67
67
|
end
|
68
68
|
end
|
@@ -75,12 +75,12 @@ describe Qa::TermsController, type: :controller do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "returns a set of terms for a tgnlang query" do
|
78
|
-
get :search, q: "Tibetan", vocab: "tgnlang"
|
78
|
+
get :search, params: { q: "Tibetan", vocab: "tgnlang" }
|
79
79
|
expect(response).to be_success
|
80
80
|
end
|
81
81
|
|
82
82
|
it "does not return 404 if subauthority is valid" do
|
83
|
-
get :search, q: "Berry", vocab: "loc", subauthority: "names"
|
83
|
+
get :search, params: { q: "Berry", vocab: "loc", subauthority: "names" }
|
84
84
|
expect(response).to be_success
|
85
85
|
end
|
86
86
|
end
|
@@ -92,7 +92,7 @@ describe Qa::TermsController, type: :controller do
|
|
92
92
|
.to_return(body: webmock_fixture("assign-fast-topical-result.json"), status: 200, headers: {})
|
93
93
|
end
|
94
94
|
it "succeeds if authority class is camelcase" do
|
95
|
-
get :search, q: "word", vocab: "assign_fast", subauthority: "topical"
|
95
|
+
get :search, params: { q: "word", vocab: "assign_fast", subauthority: "topical" }
|
96
96
|
expect(response).to be_success
|
97
97
|
end
|
98
98
|
end
|
@@ -101,26 +101,26 @@ describe Qa::TermsController, type: :controller do
|
|
101
101
|
describe "#index" do
|
102
102
|
context "with supported authorities" do
|
103
103
|
it "returns all local authority state terms" do
|
104
|
-
get :index, vocab: "local", subauthority: "states"
|
104
|
+
get :index, params: { vocab: "local", subauthority: "states" }
|
105
105
|
expect(response).to be_success
|
106
106
|
end
|
107
107
|
it "returns all MeSH terms" do
|
108
|
-
get :index, vocab: "mesh"
|
108
|
+
get :index, params: { vocab: "mesh" }
|
109
109
|
expect(response).to be_success
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
context "when the authority does not support #all" do
|
114
114
|
it "returns null for tgnlang" do
|
115
|
-
get :index, vocab: "tgnlang"
|
115
|
+
get :index, params: { vocab: "tgnlang" }
|
116
116
|
expect(response.body).to eq("null")
|
117
117
|
end
|
118
118
|
it "returns null for oclcts" do
|
119
|
-
get :index, vocab: "oclcts", subauthority: "mesh"
|
119
|
+
get :index, params: { vocab: "oclcts", subauthority: "mesh" }
|
120
120
|
expect(response.body).to eq("null")
|
121
121
|
end
|
122
122
|
it "returns null for LOC authorities" do
|
123
|
-
get :index, vocab: "loc", subauthority: "relators"
|
123
|
+
get :index, params: { vocab: "loc", subauthority: "relators" }
|
124
124
|
expect(response.body).to eq("null")
|
125
125
|
end
|
126
126
|
end
|
@@ -135,17 +135,17 @@ describe Qa::TermsController, type: :controller do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "returns an individual state term" do
|
138
|
-
get :show, vocab: "local", subauthority: "states", id: "OH"
|
138
|
+
get :show, params: { vocab: "local", subauthority: "states", id: "OH" }
|
139
139
|
expect(response).to be_success
|
140
140
|
end
|
141
141
|
|
142
142
|
it "returns an individual MeSH term" do
|
143
|
-
get :show, vocab: "mesh", id: "D000001"
|
143
|
+
get :show, params: { vocab: "mesh", id: "D000001" }
|
144
144
|
expect(response).to be_success
|
145
145
|
end
|
146
146
|
|
147
147
|
it "returns an individual subject term" do
|
148
|
-
get :show, vocab: "loc", subauthority: "subjects", id: "sh85077565"
|
148
|
+
get :show, params: { vocab: "loc", subauthority: "subjects", id: "sh85077565" }
|
149
149
|
expect(response).to be_success
|
150
150
|
end
|
151
151
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Base do
|
4
|
+
describe '#all' do
|
5
|
+
it 'is unimplemeted' do
|
6
|
+
expect { subject.all }.to raise_error NotImplementedError
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#find' do
|
11
|
+
it 'is unimplemeted' do
|
12
|
+
expect { subject.find('moomin') }.to raise_error NotImplementedError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -28,20 +28,41 @@ describe Qa::Authorities::Loc do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context "for searching" do
|
31
|
+
let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
|
31
32
|
it "returns a url" do
|
32
|
-
url = 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json'
|
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) { "http://id.loc.gov/authorities/subjects/sh2002003586.json" }
|
38
39
|
it "returns a url with an authority and id" do
|
39
|
-
url = "http://id.loc.gov/authorities/subjects/sh2002003586.json"
|
40
40
|
expect(authority.find_url("sh2002003586")).to eq(url)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe "#response" do
|
46
|
+
subject { authority.response(url) }
|
47
|
+
let :authority do
|
48
|
+
described_class.subauthority_for("subjects")
|
49
|
+
end
|
50
|
+
|
51
|
+
before do
|
52
|
+
stub_request(:get, "http://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
|
53
|
+
.with(headers: { 'Accept' => 'application/json' })
|
54
|
+
.to_return(status: 200, body: "")
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with flat params encoded" do
|
58
|
+
let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
|
59
|
+
it "returns a response" do
|
60
|
+
flat_params_url = "http://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
|
61
|
+
expect(subject.env.url.to_s).to eq(flat_params_url)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
45
66
|
describe "#search" do
|
46
67
|
context "any LOC authorities" do
|
47
68
|
let :authority do
|
@@ -51,7 +72,7 @@ describe Qa::Authorities::Loc do
|
|
51
72
|
described_class.subauthority_for("geographicAreas")
|
52
73
|
end
|
53
74
|
|
54
|
-
it "retains the raw
|
75
|
+
it "retains the raw response from the LC service in JSON" do
|
55
76
|
expect { authority.search("s") }.to change { authority.raw_response }
|
56
77
|
.from(nil)
|
57
78
|
.to(JSON.parse(webmock_fixture("loc-response.txt").read))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Anderson
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2017-
|
18
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|
@@ -319,6 +319,7 @@ files:
|
|
319
319
|
- spec/fixtures/tgn-response.txt
|
320
320
|
- spec/fixtures/ulan-response.txt
|
321
321
|
- spec/lib/authorities/assign_fast_spec.rb
|
322
|
+
- spec/lib/authorities/base_spec.rb
|
322
323
|
- spec/lib/authorities/file_based_authority_spec.rb
|
323
324
|
- spec/lib/authorities/geonames_spec.rb
|
324
325
|
- spec/lib/authorities/getty/aat_spec.rb
|
@@ -366,52 +367,53 @@ signing_key:
|
|
366
367
|
specification_version: 4
|
367
368
|
summary: You should question your authorities.
|
368
369
|
test_files:
|
369
|
-
- spec/controllers/terms_controller_spec.rb
|
370
|
-
- spec/fixtures/aat-response.txt
|
371
|
-
- spec/fixtures/assign-fast-noheader.json
|
372
|
-
- spec/fixtures/assign-fast-noresults.json
|
373
|
-
- spec/fixtures/assign-fast-oneresult.json
|
374
|
-
- spec/fixtures/assign-fast-topical-result.json
|
375
|
-
- spec/fixtures/authorities/authority_A.yml
|
376
|
-
- spec/fixtures/authorities/authority_B.yml
|
377
|
-
- spec/fixtures/authorities/authority_C.yml
|
378
|
-
- spec/fixtures/authorities/authority_D.yml
|
379
|
-
- spec/fixtures/geonames-find-response.json
|
380
|
-
- spec/fixtures/geonames-response.json
|
381
|
-
- spec/fixtures/getty-aat-find-response.json
|
382
|
-
- spec/fixtures/getty-tgn-find-response.json
|
383
|
-
- spec/fixtures/getty-ulan-find-response.json
|
384
|
-
- spec/fixtures/lexvo_snippet.rdf
|
385
|
-
- spec/fixtures/loc-names-response.txt
|
386
|
-
- spec/fixtures/loc-response.txt
|
387
|
-
- spec/fixtures/loc-subject-find-response.txt
|
388
|
-
- spec/fixtures/loc-subjects-response.txt
|
389
|
-
- spec/fixtures/mesh.txt
|
390
|
-
- spec/fixtures/oclcts-response-mesh-1.txt
|
391
|
-
- spec/fixtures/oclcts-response-mesh-2.txt
|
392
|
-
- spec/fixtures/oclcts-response-mesh-3.txt
|
393
|
-
- spec/fixtures/tgn-response.txt
|
394
|
-
- spec/fixtures/ulan-response.txt
|
395
|
-
- spec/lib/authorities/assign_fast_spec.rb
|
396
|
-
- spec/lib/authorities/file_based_authority_spec.rb
|
397
|
-
- spec/lib/authorities/geonames_spec.rb
|
398
|
-
- spec/lib/authorities/getty/aat_spec.rb
|
399
|
-
- spec/lib/authorities/getty/tgn_spec.rb
|
400
|
-
- spec/lib/authorities/getty/ulan_spec.rb
|
401
|
-
- spec/lib/authorities/getty_spec.rb
|
402
|
-
- spec/lib/authorities/loc_spec.rb
|
403
|
-
- spec/lib/authorities/local_spec.rb
|
404
|
-
- spec/lib/authorities/mesh_spec.rb
|
405
370
|
- spec/lib/authorities/mysql_table_based_authority_spec.rb
|
406
371
|
- spec/lib/authorities/oclcts_spec.rb
|
407
372
|
- spec/lib/authorities/space_fix_encoder.rb
|
373
|
+
- spec/lib/authorities/assign_fast_spec.rb
|
408
374
|
- spec/lib/authorities/table_based_authority_spec.rb
|
375
|
+
- spec/lib/authorities/local_spec.rb
|
376
|
+
- spec/lib/authorities/mesh_spec.rb
|
377
|
+
- spec/lib/authorities/geonames_spec.rb
|
378
|
+
- spec/lib/authorities/base_spec.rb
|
379
|
+
- spec/lib/authorities/file_based_authority_spec.rb
|
380
|
+
- spec/lib/authorities/getty/ulan_spec.rb
|
381
|
+
- spec/lib/authorities/getty/tgn_spec.rb
|
382
|
+
- spec/lib/authorities/getty/aat_spec.rb
|
409
383
|
- spec/lib/authorities/tgnlang_spec.rb
|
410
|
-
- spec/lib/
|
411
|
-
- spec/lib/
|
384
|
+
- spec/lib/authorities/loc_spec.rb
|
385
|
+
- spec/lib/authorities/getty_spec.rb
|
412
386
|
- spec/lib/services/rdf_authority_parser_spec.rb
|
413
387
|
- spec/lib/tasks/mesh.rake_spec.rb
|
388
|
+
- spec/lib/authorities_loc_subauthorities.rb
|
389
|
+
- spec/lib/mesh_data_parser_spec.rb
|
390
|
+
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
414
391
|
- spec/models/subject_mesh_term_spec.rb
|
415
392
|
- spec/routing/route_spec.rb
|
393
|
+
- spec/controllers/terms_controller_spec.rb
|
416
394
|
- spec/spec_helper.rb
|
417
|
-
- spec/
|
395
|
+
- spec/fixtures/loc-subjects-response.txt
|
396
|
+
- spec/fixtures/ulan-response.txt
|
397
|
+
- spec/fixtures/loc-names-response.txt
|
398
|
+
- spec/fixtures/mesh.txt
|
399
|
+
- spec/fixtures/loc-subject-find-response.txt
|
400
|
+
- spec/fixtures/loc-response.txt
|
401
|
+
- spec/fixtures/oclcts-response-mesh-1.txt
|
402
|
+
- spec/fixtures/authorities/authority_C.yml
|
403
|
+
- spec/fixtures/authorities/authority_B.yml
|
404
|
+
- spec/fixtures/authorities/authority_D.yml
|
405
|
+
- spec/fixtures/authorities/authority_A.yml
|
406
|
+
- spec/fixtures/aat-response.txt
|
407
|
+
- spec/fixtures/assign-fast-topical-result.json
|
408
|
+
- spec/fixtures/geonames-response.json
|
409
|
+
- spec/fixtures/lexvo_snippet.rdf
|
410
|
+
- spec/fixtures/getty-aat-find-response.json
|
411
|
+
- spec/fixtures/tgn-response.txt
|
412
|
+
- spec/fixtures/geonames-find-response.json
|
413
|
+
- spec/fixtures/getty-tgn-find-response.json
|
414
|
+
- spec/fixtures/getty-ulan-find-response.json
|
415
|
+
- spec/fixtures/assign-fast-noheader.json
|
416
|
+
- spec/fixtures/assign-fast-oneresult.json
|
417
|
+
- spec/fixtures/assign-fast-noresults.json
|
418
|
+
- spec/fixtures/oclcts-response-mesh-2.txt
|
419
|
+
- spec/fixtures/oclcts-response-mesh-3.txt
|