qa 5.1.0 → 5.5.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.
@@ -2,7 +2,33 @@ module Qa::Authorities
2
2
  class Geonames < Base
3
3
  include WebServiceBase
4
4
 
5
- class_attribute :username, :label
5
+ class_attribute :username, :label, :query_url_host, :find_url_host
6
+
7
+ # You may need to change your query_url_host in your implementation. To do
8
+ # so, in the installed application's config/initializers/qa.rb add the
9
+ # following:
10
+ #
11
+ # @example
12
+ # Qa::Authorities::Geonames.query_url_host = "http://ws.geonames.net"
13
+ #
14
+ # @note This is not exposed as part of the configuration block, but is
15
+ # something you can add after the configuration block.
16
+ # @todo Expose this magic value as a configuration option; Which likely
17
+ # requires consideration about how to do this for the general case
18
+ self.query_url_host = "http://api.geonames.org"
19
+
20
+ # You may need to change your query_url_host in your implementation. To do
21
+ # so, in the installed application's config/initializers/qa.rb add the
22
+ # following:
23
+ #
24
+ # @example
25
+ # Qa::Authorities::Geonames.find_url_host = "http://ws.geonames.net"
26
+ #
27
+ # @note This is not exposed as part of the configuration block, but is
28
+ # something you can add after the configuration block.
29
+ # @todo Expose this magic value as a configuration option; Which likely
30
+ # requires consideration about how to do this for the general case
31
+ self.find_url_host = "http://www.geonames.org"
6
32
 
7
33
  self.label = lambda do |item|
8
34
  [item['name'], item['adminName1'], item['countryName']].compact.join(', ')
@@ -18,7 +44,7 @@ module Qa::Authorities
18
44
 
19
45
  def build_query_url(q)
20
46
  query = ERB::Util.url_encode(untaint(q))
21
- "http://api.geonames.org/searchJSON?q=#{query}&username=#{username}&maxRows=10"
47
+ File.join(query_url_host, "searchJSON?q=#{query}&username=#{username}&maxRows=10")
22
48
  end
23
49
 
24
50
  def untaint(q)
@@ -30,7 +56,7 @@ module Qa::Authorities
30
56
  end
31
57
 
32
58
  def find_url(id)
33
- "http://www.geonames.org/getJSON?geonameId=#{id}&username=#{username}"
59
+ File.join(find_url_host, "getJSON?geonameId=#{id}&username=#{username}")
34
60
  end
35
61
 
36
62
  private
@@ -39,7 +65,7 @@ module Qa::Authorities
39
65
  def parse_authority_response(response)
40
66
  response['geonames'].map do |result|
41
67
  # Note: the trailing slash is meaningful.
42
- { 'id' => "http://sws.geonames.org/#{result['geonameId']}/",
68
+ { 'id' => "https://sws.geonames.org/#{result['geonameId']}/",
43
69
  'label' => label.call(result) }
44
70
  end
45
71
  end
@@ -15,8 +15,8 @@ module Qa::Authorities
15
15
  @term_config = term_config
16
16
  end
17
17
 
18
- attr_reader :term_config, :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :subauthority, :request_header
19
- private :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :subauthority, :request_header
18
+ attr_reader :term_config, :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :subauthority, :request_header, :request_id, :request
19
+ private :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :subauthority, :request_header, :request_id, :request
20
20
 
21
21
  delegate :term_subauthority?, :prefixes, :authority_name, to: :term_config
22
22
 
@@ -92,6 +92,8 @@ module Qa::Authorities
92
92
 
93
93
  def unpack_request_header(request_header)
94
94
  @request_header = request_header
95
+ @request = request_header.fetch(:request, nil)
96
+ @request_id = request_header.fetch(:request_id, 'UNASSIGNED')
95
97
  @subauthority = request_header.fetch(:subauthority, nil)
96
98
  @format = request_header.fetch(:format, 'json')
97
99
  @performance_data = request_header.fetch(:performance_data, false)
@@ -110,8 +112,8 @@ module Qa::Authorities
110
112
  predicate_map = preds_for_term
111
113
  ldpath_map = ldpaths_for_term
112
114
 
113
- raise Qa::InvalidConfiguration, "do not specify results using both predicates and ldpath in term configuration for linked data authority #{authority_name} (ldpath is preferred)" if predicate_map.present? && ldpath_map.present? # rubocop:disable Metrics/LineLength
114
- raise Qa::InvalidConfiguration, "must specify label_ldpath or label_predicate in term configuration for linked data authority #{authority_name} (label_ldpath is preferred)" unless ldpath_map.key?(:label) || predicate_map.key?(:label) # rubocop:disable Metrics/LineLength
115
+ raise Qa::InvalidConfiguration, "do not specify results using both predicates and ldpath in term configuration for linked data authority #{authority_name} (ldpath is preferred)" if predicate_map.present? && ldpath_map.present? # rubocop:disable Layout/LineLength
116
+ raise Qa::InvalidConfiguration, "must specify label_ldpath or label_predicate in term configuration for linked data authority #{authority_name} (label_ldpath is preferred)" unless ldpath_map.key?(:label) || predicate_map.key?(:label) # rubocop:disable Layout/LineLength
115
117
 
116
118
  if predicate_map.present?
117
119
  Qa.deprecation_warning(
@@ -15,8 +15,8 @@ module Qa::Authorities
15
15
  @search_config = search_config
16
16
  end
17
17
 
18
- attr_reader :search_config, :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :subauthority, :request_header
19
- private :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :subauthority, :request_header
18
+ attr_reader :search_config, :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :subauthority, :request_header, :request_id, :request
19
+ private :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :subauthority, :request_header, :request_id, :request
20
20
 
21
21
  delegate :subauthority?, :supports_sort?, :prefixes, :authority_name, to: :search_config
22
22
 
@@ -74,8 +74,8 @@ module Qa::Authorities
74
74
  predicate_map = preds_for_search
75
75
  ldpath_map = ldpaths_for_search
76
76
 
77
- raise Qa::InvalidConfiguration, "do not specify results using both predicates and ldpath in search configuration for linked data authority #{authority_name} (ldpath is preferred)" if predicate_map.present? && ldpath_map.present? # rubocop:disable Metrics/LineLength
78
- raise Qa::InvalidConfiguration, "must specify label_ldpath or label_predicate in search configuration for linked data authority #{authority_name} (label_ldpath is preferred)" unless ldpath_map.key?(:label) || predicate_map.key?(:label) # rubocop:disable Metrics/LineLength
77
+ raise Qa::InvalidConfiguration, "do not specify results using both predicates and ldpath in search configuration for linked data authority #{authority_name} (ldpath is preferred)" if predicate_map.present? && ldpath_map.present? # rubocop:disable Layout/LineLength
78
+ raise Qa::InvalidConfiguration, "must specify label_ldpath or label_predicate in search configuration for linked data authority #{authority_name} (label_ldpath is preferred)" unless ldpath_map.key?(:label) || predicate_map.key?(:label) # rubocop:disable Layout/LineLength
79
79
 
80
80
  if predicate_map.present?
81
81
  Qa.deprecation_warning(
@@ -91,6 +91,8 @@ module Qa::Authorities
91
91
 
92
92
  def unpack_request_header(request_header)
93
93
  @request_header = request_header
94
+ @request = request_header.fetch(:request, nil)
95
+ @request_id = request_header.fetch(:request_id, 'UNASSIGNED')
94
96
  @subauthority = request_header.fetch(:subauthority, nil)
95
97
  @context = request_header.fetch(:context, false)
96
98
  @performance_data = request_header.fetch(:performance_data, false)
@@ -26,7 +26,7 @@ module Qa::Authorities
26
26
  def build_query_url(q)
27
27
  escaped_query = ERB::Util.url_encode(q)
28
28
  authority_fragment = Loc.get_url_for_authority(subauthority) + ERB::Util.url_encode(subauthority)
29
- "http://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
29
+ "https://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
30
30
  end
31
31
 
32
32
  def find(id)
@@ -34,7 +34,7 @@ module Qa::Authorities
34
34
  end
35
35
 
36
36
  def find_url(id)
37
- "http://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
37
+ "https://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
38
38
  end
39
39
 
40
40
  private
@@ -70,18 +70,18 @@ module Qa::Authorities::LocSubauthority
70
70
  private
71
71
 
72
72
  def vocab_base_url
73
- "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F"
73
+ "cs%3Ahttps%3A%2F%2Fid.loc.gov%2Fvocabulary%2F"
74
74
  end
75
75
 
76
76
  def authority_base_url
77
- "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F"
77
+ "cs%3Ahttps%3A%2F%2Fid.loc.gov%2Fauthorities%2F"
78
78
  end
79
79
 
80
80
  def datatype_base_url
81
- "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F"
81
+ "cs%3Ahttps%3A%2F%2Fid.loc.gov%2Fdatatypes%2F"
82
82
  end
83
83
 
84
84
  def vocab_preservation_base_url
85
- "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F"
85
+ "cs%3Ahttps%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F"
86
86
  end
87
87
  end
@@ -54,5 +54,14 @@ module Qa
54
54
  @property_map_default_for_optional = false if @property_map_default_for_optional.nil?
55
55
  @property_map_default_for_optional
56
56
  end
57
+
58
+ # IP data including IP address, city, state, and country will be logged with each request.
59
+ # When false, IP data is logged
60
+ # When true, IP data will not be logged (default for backward compatibility)
61
+ attr_writer :suppress_ip_data_from_log
62
+ def suppress_ip_data_from_log
63
+ @suppress_ip_data_from_log = true if @suppress_ip_data_from_log.nil?
64
+ @suppress_ip_data_from_log
65
+ end
57
66
  end
58
67
  end
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "5.1.0".freeze
2
+ VERSION = "5.5.0".freeze
3
3
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'json'
3
3
 
4
4
  describe Qa::LinkedDataTermsController, type: :controller do
5
+ let(:graph_load_failure) { /^\*\*\*\*\*\*\*\* RDF\:\:Graph\#load failure/ }
5
6
  before do
6
7
  @routes = Qa::Engine.routes
7
8
  end
@@ -140,6 +141,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
140
141
  .to_return(status: 500)
141
142
  end
142
143
  it 'returns 500' do
144
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
143
145
  expect(Rails.logger).to receive(:warn).with("Internal Server Error - Search query my_query unsuccessful for authority OCLC_FAST")
144
146
  get :search, params: { q: 'my_query', vocab: 'OCLC_FAST', maximumRecords: '3' }
145
147
  expect(response.code).to eq('500')
@@ -154,6 +156,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
154
156
  end
155
157
  it 'returns 500' do
156
158
  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."
159
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
157
160
  expect(Rails.logger).to receive(:warn).with(msg)
158
161
  get :search, params: { q: 'my_query', vocab: 'OCLC_FAST', maximumRecords: '3' }
159
162
  expect(response.code).to eq('500')
@@ -166,6 +169,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
166
169
  .to_return(status: 501)
167
170
  end
168
171
  it 'returns 500' do
172
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
169
173
  expect(Rails.logger).to receive(:warn).with("Internal Server Error - Search query my_query unsuccessful for authority OCLC_FAST")
170
174
  get :search, params: { q: 'my_query', vocab: 'OCLC_FAST', maximumRecords: '3' }
171
175
  expect(response.code).to eq('500')
@@ -179,6 +183,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
179
183
  .to_return(status: 503)
180
184
  end
181
185
  it 'returns 503' do
186
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
182
187
  expect(Rails.logger).to receive(:warn).with("Service Unavailable - Search query my_query unsuccessful for authority OCLC_FAST")
183
188
  get :search, params: { q: 'my_query', vocab: 'OCLC_FAST', maximumRecords: '3' }
184
189
  expect(response.code).to eq('503')
@@ -355,6 +360,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
355
360
  stub_request(:get, 'http://id.worldcat.org/fast/530369').to_return(status: 500)
356
361
  end
357
362
  it 'returns 500' do
363
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
358
364
  expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term 530369 unsuccessful for authority OCLC_FAST")
359
365
  get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
360
366
  expect(response.code).to eq('500')
@@ -380,6 +386,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
380
386
  end
381
387
  it 'returns 500' do
382
388
  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."
389
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
383
390
  expect(Rails.logger).to receive(:warn).with(msg)
384
391
  get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
385
392
  expect(response.code).to eq('500')
@@ -391,6 +398,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
391
398
  stub_request(:get, 'http://id.worldcat.org/fast/530369').to_return(status: 501)
392
399
  end
393
400
  it 'returns 500' do
401
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
394
402
  expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term 530369 unsuccessful for authority OCLC_FAST")
395
403
  get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
396
404
  expect(response.code).to eq('500')
@@ -403,6 +411,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
403
411
  stub_request(:get, 'http://id.worldcat.org/fast/530369').to_return(status: 503)
404
412
  end
405
413
  it 'returns 503' do
414
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
406
415
  expect(Rails.logger).to receive(:warn).with("Service Unavailable - Fetch term 530369 unsuccessful for authority OCLC_FAST")
407
416
  get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
408
417
  expect(response.code).to eq('503')
@@ -414,6 +423,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
414
423
  stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID').to_return(status: 404, body: '', headers: {})
415
424
  end
416
425
  it 'returns 404' do
426
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
417
427
  expect(Rails.logger).to receive(:warn).with('Term Not Found - Fetch term FAKE_ID unsuccessful for authority OCLC_FAST')
418
428
  get :show, params: { id: 'FAKE_ID', vocab: 'OCLC_FAST' }
419
429
  expect(response.code).to eq('404')
@@ -566,6 +576,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
566
576
  stub_request(:get, 'http://localhost/test_default/term?uri=http://id.worldcat.org/fast/530369').to_return(status: 500)
567
577
  end
568
578
  it 'returns 500' do
579
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
569
580
  expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term http://id.worldcat.org/fast/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
570
581
  get :fetch, params: { vocab: 'LOD_TERM_URI_PARAM_CONFIG', uri: 'http://id.worldcat.org/fast/530369' }
571
582
  expect(response.code).to eq('500')
@@ -580,6 +591,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
580
591
  it 'returns 500' do
581
592
  msg = "RDF Format Error - Results from fetch term http://id.worldcat.org/fast/530369 for authority LOD_TERM_URI_PARAM_CONFIG was not identified as a valid RDF format. " \
582
593
  "You may need to include the linkeddata gem."
594
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
583
595
  expect(Rails.logger).to receive(:warn).with(msg)
584
596
  get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
585
597
  expect(response.code).to eq('500')
@@ -591,6 +603,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
591
603
  stub_request(:get, 'http://localhost/test_default/term?uri=http://id.worldcat.org/fast/530369').to_return(status: 501)
592
604
  end
593
605
  it 'returns 500' do
606
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
594
607
  expect(Rails.logger).to receive(:warn).with("Internal Server Error - Fetch term http://id.worldcat.org/fast/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
595
608
  get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
596
609
  expect(response.code).to eq('500')
@@ -603,6 +616,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
603
616
  stub_request(:get, 'http://localhost/test_default/term?uri=http://id.worldcat.org/fast/530369').to_return(status: 503)
604
617
  end
605
618
  it 'returns 503' do
619
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
606
620
  expect(Rails.logger).to receive(:warn).with("Service Unavailable - Fetch term http://id.worldcat.org/fast/530369 unsuccessful for authority LOD_TERM_URI_PARAM_CONFIG")
607
621
  get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
608
622
  expect(response.code).to eq('503')
@@ -614,6 +628,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
614
628
  stub_request(:get, 'http://localhost/test_default/term?uri=http://test.org/FAKE_ID').to_return(status: 404, body: '', headers: {})
615
629
  end
616
630
  it 'returns 404' do
631
+ expect(Rails.logger).to receive(:warn).with(graph_load_failure)
617
632
  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')
618
633
  get :fetch, params: { uri: 'http://test.org/FAKE_ID', vocab: 'LOD_TERM_URI_PARAM_CONFIG' }
619
634
  expect(response.code).to eq('404')
@@ -82,7 +82,7 @@ describe Qa::TermsController, type: :controller do
82
82
 
83
83
  context "loc" do
84
84
  before do
85
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
85
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:https://id.loc.gov/authorities/names")
86
86
  .with(headers: { 'Accept' => 'application/json' })
87
87
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
88
88
  end
@@ -188,7 +188,7 @@ describe Qa::TermsController, type: :controller do
188
188
  describe "#show" do
189
189
  context "with supported authorities" do
190
190
  before do
191
- stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json")
191
+ stub_request(:get, "https://id.loc.gov/authorities/subjects/sh85077565.json")
192
192
  .with(headers: { 'Accept' => 'application/json' })
193
193
  .to_return(status: 200, body: webmock_fixture("loc-names-response.txt"), headers: {})
194
194
  end
@@ -0,0 +1 @@
1
+ {"pagination": {"per_page": 10, "pages": 2, "page": 1, "urls": {"last": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=10&type=master&page=2", "next": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=10&type=master&page=2"}, "items": 17}, "results": [{"style": ["Acoustic", "Soft Rock"], "thumb": "https://img.discogs.com/PDVaKISZBGLJnTkHxLdacDZx8AY=/fit-in/150x150/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/R-2304876-1521522385-7719.jpeg.jpg", "format": ["CD", "Album"], "country": "US", "barcode": ["0 7464-46038-2", "1A CK46038 01 B", "1A CK46038 10 B1", "CMU P 112"], "uri": "/James-Taylor-New-Moon-Shine/master/297372", "master_url": "https://api.discogs.com/masters/297372", "label": ["Columbia", "Skyline Studios", "Power Station", "A&M Studios", "Studio F", "Skyline Studios", "Sterling Sound"], "genre": ["Rock"], "catno": "CK 46038", "community": {"want": 224, "have": 761}, "year": "1991", "cover_image": "https://img.discogs.com/cr-KOWrcvF8_3z6kx3go4ikTOcw=/fit-in/600x597/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-2304876-1521522385-7719.jpeg.jpg", "title": "James Taylor (2) - New Moon Shine", "resource_url": "https://api.discogs.com/masters/297372", "master_id": 297372, "type": "master", "id": 297372}, {"id": 123}, {"id":234},{"id":345},{"id": 456}, {"id": 567}, {"id": 678}, {"id": 789}, {"id": 890}, {"id": 901}]}
@@ -0,0 +1 @@
1
+ {"pagination": {"per_page": 5, "pages": 4, "page": 4, "urls": {"prev": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=5&type=master&page=3", "first": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=5&type=master&page=1"}, "items": 17}, "results": [{"style": ["Big Band"], "thumb": "https://img.discogs.com/discogs-images/R-5420943-1507027002-2700.jpeg.jpg", "format": ["CD", "Compilation", "Limited Edition", "Box Set"], "country": "US", "barcode": [], "uri": "/Stan-Kenton-The-Complete-Capitol-Studio-Recordings-Of-Stan-Kenton-1943-47/master/866349", "master_url": "https://api.discogs.com/masters/866349", "label": ["Mosaic Records", "CEMA Special Markets"], "genre": ["Jazz"], "catno": "MD7-163", "community": {"want": 36, "have": 70}, "year": "1995", "cover_image": "https://img.discogs.com/2700.jpeg.jpg", "title": "Stan Kenton - The Complete Capitol Studio Recordings Of Stan Kenton 1943-47", "resource_url": "https://api.discogs.com/masters/866349", "master_id": 866349, "type": "master", "id": 866349}, {"style": ["Prog Rock", "Classic Rock"], "thumb": "https://img.discogs.com/discogs-images/R-1570546-1229281515.jpeg.jpg", "format": ["CD", "Album", "Reissue", "Remastered", "Box Set", "Compilation"], "country": "Europe", "uri": "/Pink-Floyd-Oh-By-The-Way/master/437149", "master_url": "https://api.discogs.com/masters/437149", "label": ["EMI", "EMI", "EMI", "EMI"], "genre": ["Rock", "Pop"], "catno": "50999 511267 2 8", "community": {"want": 0, "have": 0}, "year": "2007", "cover_image": "https://img.discogs.com/discogs-images/R-1570546-1229281515.jpeg.jpg", "title": "Pink Floyd - Oh By The Way", "resource_url": "https://api.discogs.com/masters/437149", "master_id": 437149, "type": "master", "id": 437149}]}
@@ -9,8 +9,26 @@ describe Qa::Authorities::Discogs::GenericAuthority do
9
9
  let(:authority) { described_class.new "all" }
10
10
 
11
11
  describe "#build_query_url" do
12
- subject { authority.build_query_url("foo", 'master') }
13
- it { is_expected.to eq 'https://api.discogs.com/database/search?q=foo&type=master&key=dummy_key&secret=dummy_secret' }
12
+ context "build_query_url startRecord" do
13
+ subject { authority.build_query_url("foo", tc) }
14
+ let(:tc) { instance_double(Qa::TermsController) }
15
+ before do
16
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
17
+ allow(tc).to receive(:params).and_return('startRecord' => "16", 'maxRecords' => "5", 'subauthority' => "master")
18
+ end
19
+
20
+ it { is_expected.to eq 'https://api.discogs.com/database/search?q=foo&type=master&page=4&per_page=5&key=dummy_key&secret=dummy_secret' }
21
+ end
22
+ context "build_query_url per_page" do
23
+ subject { authority.build_query_url("foo", tc) }
24
+ let(:tc) { instance_double(Qa::TermsController) }
25
+ before do
26
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
27
+ allow(tc).to receive(:params).and_return('page' => "1", 'per_page' => "10", 'subauthority' => "master")
28
+ end
29
+
30
+ it { is_expected.to eq 'https://api.discogs.com/database/search?q=foo&type=master&page=1&per_page=10&key=dummy_key&secret=dummy_secret' }
31
+ end
14
32
  end
15
33
 
16
34
  describe "#find_url" do
@@ -263,7 +281,7 @@ describe Qa::Authorities::Discogs::GenericAuthority do
263
281
  context "with subauthority all" do
264
282
  let(:tc) { instance_double(Qa::TermsController) }
265
283
  let :results do
266
- stub_request(:get, "https://api.discogs.com/database/search?q=melody+gardot+who+will+comfort+me+over+the+rainbo&type=all&key=dummy_key&secret=dummy_secret")
284
+ stub_request(:get, "https://api.discogs.com/database/search?q=melody+gardot+who+will+comfort+me+over+the+rainbo&type=all&page=&per_page=&key=dummy_key&secret=dummy_secret")
267
285
  .to_return(status: 200, body: webmock_fixture("discogs-search-response-no-subauth.json"))
268
286
  authority.search("melody gardot who will comfort me over the rainbo", tc)
269
287
  end
@@ -286,7 +304,7 @@ describe Qa::Authorities::Discogs::GenericAuthority do
286
304
  context "with subauthority master" do
287
305
  let(:tc) { instance_double(Qa::TermsController) }
288
306
  let :results do
289
- stub_request(:get, "https://api.discogs.com/database/search?q=wes+montgomery+tequila+bumpin'+on+sunse&type=master&key=dummy_key&secret=dummy_secret")
307
+ stub_request(:get, "https://api.discogs.com/database/search?q=wes+montgomery+tequila+bumpin'+on+sunse&type=master&page=&per_page=&key=dummy_key&secret=dummy_secret")
290
308
  .to_return(status: 200, body: webmock_fixture("discogs-search-response-subauth.json"))
291
309
  authority.search("wes montgomery tequila bumpin' on sunse", tc)
292
310
  end
@@ -305,6 +323,46 @@ describe Qa::Authorities::Discogs::GenericAuthority do
305
323
  end
306
324
  end
307
325
 
326
+ context "with setRecord and maxRecords" do
327
+ let(:tc) { instance_double(Qa::TermsController) }
328
+ let :results do
329
+ stub_request(:get, "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&type=master&page=4&per_page=5&key=dummy_key&secret=dummy_secret")
330
+ .to_return(status: 200, body: webmock_fixture("discogs-search-response-set-record.json"))
331
+ authority.search("james taylor new moon shine", tc)
332
+ end
333
+ before do
334
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
335
+ allow(tc).to receive(:params).and_return('subauthority' => "master", 'startRecord' => 16, 'maxRecords' => 5, 'response_header' => 'true')
336
+ end
337
+
338
+ it "has id and label keys" do
339
+ expect(results['response_header']['start_record']).to eq 16
340
+ expect(results['response_header']['requested_records']).to eq 5
341
+ expect(results['response_header']['retrieved_records']).to eq 2
342
+ expect(results['response_header']['total_records']).to eq 17
343
+ end
344
+ end
345
+
346
+ context "with page and per_page" do
347
+ let(:tc) { instance_double(Qa::TermsController) }
348
+ let :results do
349
+ stub_request(:get, "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&type=master&page=1&per_page=10&key=dummy_key&secret=dummy_secret")
350
+ .to_return(status: 200, body: webmock_fixture("discogs-search-response-per-page.json"))
351
+ authority.search("james taylor new moon shine", tc)
352
+ end
353
+ before do
354
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
355
+ allow(tc).to receive(:params).and_return('subauthority' => "master", 'page' => 1, 'per_page' => 10, 'response_header' => 'true')
356
+ end
357
+
358
+ it "has id and label keys" do
359
+ expect(results['response_header']['start_record']).to eq 1
360
+ expect(results['response_header']['requested_records']).to eq 10
361
+ expect(results['response_header']['retrieved_records']).to eq 10
362
+ expect(results['response_header']['total_records']).to eq 17
363
+ end
364
+ end
365
+
308
366
  context "when authentication isn't set" do
309
367
  let(:tc) { instance_double(Qa::TermsController) }
310
368
  let :results do
@@ -7,6 +7,34 @@ describe Qa::Authorities::Geonames do
7
7
 
8
8
  let(:authority) { described_class.new }
9
9
 
10
+ describe ".query_url_host" do
11
+ subject { described_class.query_url_host }
12
+ it { is_expected.to eq "http://api.geonames.org" }
13
+ it "can be overridden" do
14
+ begin
15
+ before_change = described_class.query_url_host
16
+ described_class.query_url_host = "http://myhost.com"
17
+ expect(described_class.query_url_host).to eq("http://myhost.com")
18
+ ensure
19
+ described_class.query_url_host = before_change
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".find_url_host" do
25
+ subject { described_class.find_url_host }
26
+ it { is_expected.to eq "http://www.geonames.org" }
27
+ it "can be overridden" do
28
+ begin
29
+ before_change = described_class.find_url_host
30
+ described_class.find_url_host = "http://myhost.com"
31
+ expect(described_class.find_url_host).to eq("http://myhost.com")
32
+ ensure
33
+ described_class.find_url_host = before_change
34
+ end
35
+ end
36
+ end
37
+
10
38
  describe "#build_query_url" do
11
39
  subject { authority.build_query_url("foo") }
12
40
  it { is_expected.to eq 'http://api.geonames.org/searchJSON?q=foo&username=dummy&maxRows=10' }
@@ -28,9 +56,9 @@ describe Qa::Authorities::Geonames do
28
56
 
29
57
  context "with default label" do
30
58
  it "has id and label keys" do
31
- expect(subject.first).to eq("id" => 'http://sws.geonames.org/2088122/',
59
+ expect(subject.first).to eq("id" => 'https://sws.geonames.org/2088122/',
32
60
  "label" => "Port Moresby, National Capital, Papua New Guinea")
33
- expect(subject.last).to eq("id" => 'http://sws.geonames.org/377039/',
61
+ expect(subject.last).to eq("id" => 'https://sws.geonames.org/377039/',
34
62
  "label" => "Port Sudan, Red Sea, Sudan")
35
63
  expect(subject.size).to eq(10)
36
64
  end