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.
@@ -20,6 +20,7 @@ module Qa::Authorities
20
20
  delegate :subauthority?, :subauthorities?, to: :search_config, prefix: 'search'
21
21
 
22
22
  def initialize(auth_name)
23
+ super()
23
24
  @authority_config = Qa::Authorities::LinkedData::Config.new(auth_name)
24
25
  end
25
26
 
@@ -2,6 +2,7 @@ module Qa::Authorities
2
2
  class Loc::GenericAuthority < Base
3
3
  attr_reader :subauthority
4
4
  def initialize(subauthority)
5
+ super()
5
6
  @subauthority = subauthority
6
7
  end
7
8
 
@@ -2,6 +2,7 @@ module Qa::Authorities
2
2
  class Local::FileBasedAuthority < Base
3
3
  attr_reader :subauthority
4
4
  def initialize(subauthority)
5
+ super()
5
6
  @subauthority = subauthority
6
7
  end
7
8
 
@@ -19,9 +19,7 @@ module Qa::Authorities
19
19
  end
20
20
 
21
21
  def self.logger
22
- @logger ||= begin
23
- ::Rails.logger if defined? Rails && Rails.respond_to?(:logger)
24
- end
22
+ @logger ||= ::Rails.logger if defined? Rails && Rails.respond_to?(:logger)
25
23
  end
26
24
 
27
25
  class << self
@@ -34,6 +34,7 @@ module Qa::Authorities
34
34
  attr_reader :subauthority
35
35
 
36
36
  def initialize(subauthority)
37
+ super()
37
38
  self.class.check_for_index
38
39
  @subauthority = subauthority
39
40
  end
@@ -36,10 +36,8 @@ module Qa::Authorities
36
36
  end
37
37
 
38
38
  def registry
39
- @registry ||= begin
40
- Registry.new do |reg|
41
- register_defaults(reg)
42
- end
39
+ @registry ||= Registry.new do |reg|
40
+ register_defaults(reg)
43
41
  end
44
42
  end
45
43
 
@@ -7,7 +7,9 @@ module Qa::Authorities
7
7
  @file = file
8
8
  end
9
9
 
10
- def each_mesh_record # rubocop:disable Metrics/MethodLength
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
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "5.7.0".freeze
2
+ VERSION = "5.9.0".freeze
3
3
  end
@@ -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
- true
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
- expect(Rails.logger).to receive(:warn).with(" ERROR fetching Getty response: undefined method `[]' for nil:NilClass; cause: UNKNOWN")
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
- expect(Rails.logger).to receive(:warn).with(" ERROR fetching Getty response: undefined method `[]' for nil:NilClass; cause: UNKNOWN")
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
- expect(Rails.logger).to receive(:warn).with(" ERROR fetching Getty response: undefined method `[]' for nil:NilClass; cause: UNKNOWN")
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