qa 5.7.0 → 5.9.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 +4 -4
- data/README.md +8 -3
- data/app/controllers/qa/terms_controller.rb +26 -24
- data/app/services/qa/linked_data/graph_service.rb +1 -1
- data/app/services/qa/pagination_service.rb +586 -0
- data/config/initializers/mime_types.rb +4 -0
- data/lib/qa/authorities/assign_fast/generic_authority.rb +2 -0
- data/lib/qa/authorities/crossref/generic_authority.rb +1 -0
- data/lib/qa/authorities/discogs/generic_authority.rb +1 -0
- data/lib/qa/authorities/geonames.rb +1 -1
- data/lib/qa/authorities/linked_data/config.rb +2 -2
- data/lib/qa/authorities/linked_data/find_term.rb +9 -3
- data/lib/qa/authorities/linked_data/generic_authority.rb +1 -0
- data/lib/qa/authorities/loc/generic_authority.rb +1 -0
- data/lib/qa/authorities/local/file_based_authority.rb +1 -0
- data/lib/qa/authorities/local/registry.rb +1 -3
- data/lib/qa/authorities/local/table_based_authority.rb +1 -0
- data/lib/qa/authorities/local.rb +2 -4
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +3 -1
- data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +2 -1
- data/lib/qa/version.rb +1 -1
- data/spec/controllers/terms_controller_spec.rb +74 -1
- data/spec/lib/authorities/getty/aat_spec.rb +4 -1
- data/spec/lib/authorities/getty/tgn_spec.rb +4 -1
- data/spec/lib/authorities/getty/ulan_spec.rb +4 -1
- data/spec/services/pagination_service_spec.rb +682 -0
- data/spec/spec_helper.rb +0 -14
- data/spec/test_app_templates/Gemfile.extra +13 -0
- metadata +147 -145
data/lib/qa/authorities/local.rb
CHANGED
@@ -7,7 +7,9 @@ module Qa::Authorities
|
|
7
7
|
@file = file
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
# rubocop:disable Metrics/MethodLength
|
11
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
12
|
+
def each_mesh_record
|
11
13
|
current_data = {}
|
12
14
|
in_record = false
|
13
15
|
file.each_line do |line|
|
@@ -3,6 +3,7 @@ module Qa::Authorities
|
|
3
3
|
attr_reader :subauthority
|
4
4
|
|
5
5
|
def initialize(subauthority)
|
6
|
+
super()
|
6
7
|
@subauthority = subauthority
|
7
8
|
end
|
8
9
|
include WebServiceBase
|
@@ -34,7 +35,7 @@ module Qa::Authorities
|
|
34
35
|
|
35
36
|
def get_raw_response(query_type, id)
|
36
37
|
query_url = Oclcts.url_pattern(query_type).gsub("{query}", id).gsub("{id}", id).gsub("{authority-id}", subauthority)
|
37
|
-
@raw_response = Nokogiri::XML(open(query_url))
|
38
|
+
@raw_response = Nokogiri::XML(URI.open(query_url))
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/qa/version.rb
CHANGED
@@ -65,11 +65,12 @@ describe Qa::TermsController, type: :controller do
|
|
65
65
|
class Qa::Authorities::Local::TwoArgs < Qa::Authorities::Base
|
66
66
|
attr_reader :subauthority
|
67
67
|
def initialize(subauthority)
|
68
|
+
super()
|
68
69
|
@subauthority = subauthority
|
69
70
|
end
|
70
71
|
|
71
72
|
def search(_arg1, _arg2)
|
72
|
-
|
73
|
+
[]
|
73
74
|
end
|
74
75
|
end
|
75
76
|
Qa::Authorities::Local.register_subauthority('two_args', 'Qa::Authorities::Local::TwoArgs')
|
@@ -122,6 +123,78 @@ describe Qa::TermsController, type: :controller do
|
|
122
123
|
expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
127
|
+
context 'when pagination parameters are set' do
|
128
|
+
context 'and no format is specified' do
|
129
|
+
let(:params) do
|
130
|
+
{
|
131
|
+
q: "Berry", vocab: "loc", subauthority: "names",
|
132
|
+
page_limit: "5", page_offset: "6"
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
it "returns a subset of results as an Array<Hash>" do
|
137
|
+
# query without pagination is expected to return 20 results
|
138
|
+
get :search, params: params
|
139
|
+
expect(response).to be_successful
|
140
|
+
expect(response.content_type.split(';')).to include 'application/json'
|
141
|
+
results = JSON.parse(response.body)
|
142
|
+
expect(results.count).to eq 5
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'and format is specified as :jsonapi' do
|
147
|
+
let(:params) do
|
148
|
+
{
|
149
|
+
q: "Berry", vocab: "loc", subauthority: "names",
|
150
|
+
page_limit: "5", page_offset: "6", format: "jsonapi"
|
151
|
+
}
|
152
|
+
end
|
153
|
+
let(:total_num_found) { "20" } # query without pagination is expected to return 20 results
|
154
|
+
|
155
|
+
it "returns a subset of results in the JSON-API format" do
|
156
|
+
get :search, params: params
|
157
|
+
expect(response).to be_successful
|
158
|
+
expect(response.content_type.split(';')).to include 'application/vnd.api+json'
|
159
|
+
json_api_response = JSON.parse(response.body)
|
160
|
+
expect(json_api_response['data'].count).to eq 5
|
161
|
+
end
|
162
|
+
|
163
|
+
it "sets meta['page'] stats" do
|
164
|
+
get :search, params: params
|
165
|
+
json_api_response = JSON.parse(response.body)
|
166
|
+
expect(json_api_response["meta"]["page"]["page_offset"]).to eq "6"
|
167
|
+
expect(json_api_response["meta"]["page"]["page_limit"]).to eq "5"
|
168
|
+
expect(json_api_response["meta"]["page"]["actual_page_size"]).to eq "5"
|
169
|
+
expect(json_api_response["meta"]["page"]["total_num_found"]).to eq total_num_found
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'sets links with prev and next having values' do
|
173
|
+
get :search, params: params
|
174
|
+
|
175
|
+
base_url = request.base_url
|
176
|
+
url_path = request.path
|
177
|
+
first_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=1"
|
178
|
+
second_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=6"
|
179
|
+
third_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=11"
|
180
|
+
fourth_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=16"
|
181
|
+
last_page = fourth_page
|
182
|
+
|
183
|
+
json_api_response = JSON.parse(response.body)
|
184
|
+
expect(json_api_response['links']["self"]).to eq second_page
|
185
|
+
expect(json_api_response['links']["first"]).to eq first_page
|
186
|
+
expect(json_api_response['links']["prev"]).to eq first_page
|
187
|
+
expect(json_api_response['links']["next"]).to eq third_page
|
188
|
+
expect(json_api_response['links']["last"]).to eq last_page
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'does not include errors' do
|
192
|
+
get :search, params: params
|
193
|
+
json_api_response = JSON.parse(response.body)
|
194
|
+
expect(json_api_response.key?('errors')).to eq false
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
125
198
|
end
|
126
199
|
|
127
200
|
context "assign_fast" do
|
@@ -35,7 +35,10 @@ describe Qa::Authorities::Getty::AAT do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'logs error and returns empty results' do
|
38
|
-
|
38
|
+
# Rails 3.1 actually quotes the failing code in the error message,
|
39
|
+
# so let's match this error message with a multiline regex instead of
|
40
|
+
# a string.
|
41
|
+
expect(Rails.logger).to receive(:warn).with(/ERROR fetching Getty response: .*undefined method.*for nil:NilClass.*; cause: UNKNOWN/m)
|
39
42
|
expect(subject).to be {}
|
40
43
|
end
|
41
44
|
end
|
@@ -35,7 +35,10 @@ describe Qa::Authorities::Getty::TGN do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'logs error and returns empty results' do
|
38
|
-
|
38
|
+
# Rails 3.1 actually quotes the failing code in the error message,
|
39
|
+
# so let's match this error message with a multiline regex instead of
|
40
|
+
# a string.
|
41
|
+
expect(Rails.logger).to receive(:warn).with(/ERROR fetching Getty response: .*undefined method.*for nil:NilClass.*; cause: UNKNOWN/m)
|
39
42
|
expect(subject).to be {}
|
40
43
|
end
|
41
44
|
end
|
@@ -35,7 +35,10 @@ describe Qa::Authorities::Getty::Ulan do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'logs error and returns empty results' do
|
38
|
-
|
38
|
+
# Rails 3.1 actually quotes the failing code in the error message,
|
39
|
+
# so let's match this error message with a multiline regex instead of
|
40
|
+
# a string.
|
41
|
+
expect(Rails.logger).to receive(:warn).with(/ERROR fetching Getty response: .*undefined method.*for nil:NilClass.*; cause: UNKNOWN/m)
|
39
42
|
expect(subject).to be {}
|
40
43
|
end
|
41
44
|
end
|