qa 4.2.0 → 4.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.
Files changed (28) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/qa/linked_data_terms_controller.rb +17 -39
  3. data/app/controllers/qa/terms_controller.rb +26 -2
  4. data/app/services/qa/linked_data/authority_url_service.rb +35 -21
  5. data/app/services/qa/linked_data/graph_service.rb +2 -4
  6. data/app/services/qa/linked_data/request_header_service.rb +97 -0
  7. data/lib/qa/authorities/discogs/discogs_instance_builder.rb +17 -19
  8. data/lib/qa/authorities/discogs/discogs_translation.rb +26 -22
  9. data/lib/qa/authorities/discogs/discogs_utils.rb +32 -20
  10. data/lib/qa/authorities/discogs/discogs_works_builder.rb +26 -47
  11. data/lib/qa/authorities/discogs/generic_authority.rb +64 -33
  12. data/lib/qa/authorities/getty/tgn.rb +1 -1
  13. data/lib/qa/authorities/linked_data/find_term.rb +60 -18
  14. data/lib/qa/authorities/linked_data/search_query.rb +43 -15
  15. data/lib/qa/authorities/loc/generic_authority.rb +2 -2
  16. data/lib/qa/version.rb +1 -1
  17. data/spec/controllers/linked_data_terms_controller_spec.rb +36 -0
  18. data/spec/controllers/terms_controller_spec.rb +26 -2
  19. data/spec/fixtures/discogs-find-response-json.json +1 -1
  20. data/spec/lib/authorities/discogs/generic_authority_spec.rb +103 -9
  21. data/spec/lib/authorities/getty/tgn_spec.rb +2 -2
  22. data/spec/lib/authorities/linked_data/find_term_spec.rb +11 -11
  23. data/spec/lib/authorities/linked_data/search_query_spec.rb +9 -9
  24. data/spec/lib/authorities/loc_spec.rb +9 -9
  25. data/spec/services/linked_data/authority_url_service_spec.rb +14 -8
  26. data/spec/services/linked_data/graph_service_spec.rb +2 -1
  27. data/spec/services/linked_data/request_header_service_spec.rb +124 -0
  28. metadata +9 -7
@@ -82,13 +82,13 @@ describe Qa::Authorities::Getty::TGN do
82
82
  context "using a single subject term" do
83
83
  subject { authority.sparql('search_term') }
84
84
  it {
85
- is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search_term"; skos:inScheme <http://vocab.getty.edu/ulan/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER regex(?name, "search_term", "i") . } ORDER BY ?name ASC(?par))
85
+ is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search_term"; skos:inScheme <http://vocab.getty.edu/tgn/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER regex(?name, "search_term", "i") . } ORDER BY ?name ASC(?par))
86
86
  }
87
87
  end
88
88
  context "using a two subject terms" do
89
89
  subject { authority.sparql('search term') }
90
90
  it {
91
- is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search term"; skos:inScheme <http://vocab.getty.edu/ulan/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER ((regex(?name, "search", "i") || regex(?alt, "search", "i")) && (regex(?name, "term", "i") || regex(?alt, "term", "i"))) . } ORDER BY ?name ASC(?par))
91
+ is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search term"; skos:inScheme <http://vocab.getty.edu/tgn/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER ((regex(?name, "search", "i") || regex(?alt, "search", "i")) && (regex(?name, "term", "i") || regex(?alt, "term", "i"))) . } ORDER BY ?name ASC(?par))
92
92
  }
93
93
  end
94
94
  end
@@ -24,7 +24,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
24
24
  end
25
25
  context 'when set to true' do
26
26
  let :results do
27
- lod_oclc.find('530369', performance_data: true)
27
+ lod_oclc.find('530369', request_header: { performance_data: true })
28
28
  end
29
29
  it 'includes performance in return hash' do
30
30
  expect(results.keys).to match_array [:performance, :results]
@@ -38,7 +38,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
38
38
 
39
39
  context 'when set to false' do
40
40
  let :results do
41
- lod_oclc.find('530369', performance_data: false)
41
+ lod_oclc.find('530369', request_header: { performance_data: false })
42
42
  end
43
43
  it 'does NOT include performance in return hash' do
44
44
  expect(results.keys).not_to include(:performance)
@@ -114,7 +114,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
114
114
  .to_return(status: 200, body: webmock_fixture('lod_loc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
115
115
  end
116
116
 
117
- let(:results) { lod_loc.find('sh 85118553', subauth: 'subjects') }
117
+ let(:results) { lod_loc.find('sh 85118553', request_header: { subauthority: 'subjects' }) }
118
118
 
119
119
  it 'has correct primary predicate values' do
120
120
  expect(results[:uri]).to eq 'http://id.loc.gov/authorities/subjects/sh85118553'
@@ -182,8 +182,8 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
182
182
  .to_return(status: 200, body: webmock_fixture('lod_loc_second_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
183
183
  end
184
184
 
185
- let(:results) { lod_loc.find('sh 85118553', subauth: 'subjects') }
186
- let(:second_results) { lod_loc.find('sh 1234', subauth: 'subjects') }
185
+ let(:results) { lod_loc.find('sh 85118553', request_header: { subauthority: 'subjects' }) }
186
+ let(:second_results) { lod_loc.find('sh 1234', request_header: { subauthority: 'subjects' }) }
187
187
 
188
188
  it 'has correct primary predicate values for second request' do
189
189
  expect(results[:uri]).to eq 'http://id.loc.gov/authorities/subjects/sh85118553'
@@ -201,7 +201,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
201
201
  .to_return(status: 200, body: webmock_fixture('lod_loc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
202
202
  end
203
203
 
204
- let(:results_without_blank) { lod_loc.find('sh85118553', subauth: 'subjects') }
204
+ let(:results_without_blank) { lod_loc.find('sh85118553', request_header: { subauthority: 'subjects' }) }
205
205
 
206
206
  it 'extracts correct uri' do
207
207
  expect(results_without_blank[:uri]).to eq 'http://id.loc.gov/authorities/subjects/sh85118553'
@@ -215,7 +215,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
215
215
  end
216
216
 
217
217
  it 'raises DataNormalizationError' do
218
- expect { lod_loc.find('sh85118553', subauth: 'subjects') }.to raise_error Qa::DataNormalizationError, "Unable to extract URI based on ID: sh85118553"
218
+ expect { lod_loc.find('sh85118553', request_header: { subauthority: 'subjects' }) }.to raise_error Qa::DataNormalizationError, "Unable to extract URI based on ID: sh85118553"
219
219
  end
220
220
  end
221
221
 
@@ -226,7 +226,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
226
226
  allow(lod_loc.term_config).to receive(:authority_name).and_return('ALT_LOC_AUTHORITY')
227
227
  end
228
228
 
229
- let(:results) { lod_loc.find('sh 85118553', subauth: 'subjects') }
229
+ let(:results) { lod_loc.find('sh 85118553', request_header: { subauthority: 'subjects' }) }
230
230
 
231
231
  it 'does special processing to remove blank from id' do
232
232
  expect(results[:uri]).to eq 'http://id.loc.gov/authorities/subjects/sh85118553'
@@ -313,7 +313,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
313
313
  let :results do
314
314
  stub_request(:get, "http://aims.fao.org/aos/agrovoc/c_9513")
315
315
  .to_return(status: 200, body: webmock_fixture("lod_lang_term_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
316
- lod_lang_defaults.find('http://aims.fao.org/aos/agrovoc/c_9513', language: 'fr')
316
+ lod_lang_defaults.find('http://aims.fao.org/aos/agrovoc/c_9513', request_header: { language: 'fr' })
317
317
  end
318
318
  it "is filtered to specified language" do
319
319
  expect(results[:label]).to eq ['Babeurre']
@@ -328,7 +328,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
328
328
  let :results do
329
329
  stub_request(:get, "http://aims.fao.org/aos/agrovoc/c_9513")
330
330
  .to_return(status: 200, body: webmock_fixture("lod_lang_term_enfr_noalt.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
331
- lod_lang_defaults.find('http://aims.fao.org/aos/agrovoc/c_9513', language: 'fr')
331
+ lod_lang_defaults.find('http://aims.fao.org/aos/agrovoc/c_9513', request_header: { language: 'fr' })
332
332
  end
333
333
  it "is filtered to specified language" do
334
334
  expect(results[:label]).to eq ['Babeurre']
@@ -357,7 +357,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
357
357
  let :results do
358
358
  stub_request(:get, "http://aims.fao.org/aos/agrovoc/c_9513?lang=fr")
359
359
  .to_return(status: 200, body: webmock_fixture("lod_lang_term_fr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
360
- lod_lang_param.find('http://aims.fao.org/aos/agrovoc/c_9513', replacements: { 'lang' => 'fr' })
360
+ lod_lang_param.find('http://aims.fao.org/aos/agrovoc/c_9513', request_header: { replacements: { 'lang' => 'fr' } })
361
361
  end
362
362
  it "is correctly parsed" do
363
363
  expect(results[:label]).to eq ['Babeurre']
@@ -11,7 +11,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
11
11
  end
12
12
  context 'when set to true' do
13
13
  let :results do
14
- lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' }, performance_data: true)
14
+ lod_oclc.search('cornell', request_header: { subauthority: 'personal_name', replacements: { 'maximumRecords' => '3' }, performance_data: true })
15
15
  end
16
16
  it 'includes performance in return hash' do
17
17
  expect(results).to be_kind_of Hash
@@ -27,7 +27,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
27
27
 
28
28
  context 'when set to false' do
29
29
  let :results do
30
- lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' }, performance_data: false)
30
+ lod_oclc.search('cornell', request_header: { subauthority: 'personal_name', replacements: { 'maximumRecords' => '3' }, performance_data: false })
31
31
  end
32
32
  it 'does NOT include performance in return hash' do
33
33
  expect(results).to be_kind_of Array
@@ -36,7 +36,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
36
36
 
37
37
  context 'when using default setting' do
38
38
  let :results do
39
- lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
39
+ lod_oclc.search('cornell', request_header: { subauthority: 'personal_name', replacements: { 'maximumRecords' => '3' } })
40
40
  end
41
41
  it 'does NOT include performance in return hash' do
42
42
  expect(results).to be_kind_of Array
@@ -49,7 +49,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
49
49
  let :results do
50
50
  stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=cql.any%20all%20%22supercalifragilisticexpialidocious%22&sortKeys=usage')
51
51
  .to_return(status: 200, body: webmock_fixture('lod_oclc_query_no_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
52
- lod_oclc.search('supercalifragilisticexpialidocious', replacements: { 'maximumRecords' => '3' })
52
+ lod_oclc.search('supercalifragilisticexpialidocious', request_header: { replacements: { 'maximumRecords' => '3' } })
53
53
  end
54
54
  it 'returns an empty array' do
55
55
  expect(results).to eq([])
@@ -60,7 +60,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
60
60
  let :results do
61
61
  stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=cql.any%20all%20%22cornell%22&sortKeys=usage')
62
62
  .to_return(status: 200, body: webmock_fixture('lod_oclc_all_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
63
- lod_oclc.search('cornell', replacements: { 'maximumRecords' => '3' })
63
+ lod_oclc.search('cornell', request_header: { replacements: { 'maximumRecords' => '3' } })
64
64
  end
65
65
  it 'is correctly parsed' do
66
66
  expect(results.count).to eq(3)
@@ -76,7 +76,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
76
76
  let :results do
77
77
  stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22supercalifragilisticexpialidocious%22&sortKeys=usage')
78
78
  .to_return(status: 200, body: webmock_fixture('lod_oclc_query_no_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
79
- lod_oclc.search('supercalifragilisticexpialidocious', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
79
+ lod_oclc.search('supercalifragilisticexpialidocious', request_header: { subauthority: 'personal_name', replacements: { 'maximumRecords' => '3' } })
80
80
  end
81
81
  it 'returns an empty array' do
82
82
  expect(results).to eq([])
@@ -87,7 +87,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
87
87
  let :results do
88
88
  stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22cornell%22&sortKeys=usage')
89
89
  .to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
90
- lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
90
+ lod_oclc.search('cornell', request_header: { subauthority: 'personal_name', replacements: { 'maximumRecords' => '3' } })
91
91
  end
92
92
  it 'is correctly parsed' do
93
93
  expect(results.count).to eq(3)
@@ -197,7 +197,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
197
197
  let :results do
198
198
  stub_request(:get, "http://localhost/test_default/search?query=milk")
199
199
  .to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
200
- lod_lang_defaults.search('milk', language: :fr)
200
+ lod_lang_defaults.search('milk', request_header: { language: :fr })
201
201
  end
202
202
  it "is filtered to specified language" do
203
203
  expect(results.first[:label]).to eq('Babeurre (délicieux)')
@@ -226,7 +226,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
226
226
  let :results do
227
227
  stub_request(:get, "http://localhost/test_replacement/search?query=milk&lang=fr")
228
228
  .to_return(status: 200, body: webmock_fixture("lod_lang_search_fr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
229
- lod_lang_param.search("milk", replacements: { 'lang' => 'fr' })
229
+ lod_lang_param.search("milk", request_header: { replacements: { 'lang' => 'fr' } })
230
230
  end
231
231
  it "is correctly parsed" do
232
232
  expect(results.first[:label]).to eq('Babeurre (délicieux)')
@@ -28,14 +28,14 @@ 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
+ let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
32
32
  it "returns a url" do
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
+ let(:url) { "https://id.loc.gov/authorities/subjects/sh2002003586.json" }
39
39
  it "returns a url with an authority and id" do
40
40
  expect(authority.find_url("sh2002003586")).to eq(url)
41
41
  end
@@ -49,15 +49,15 @@ describe Qa::Authorities::Loc do
49
49
  end
50
50
 
51
51
  before do
52
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
52
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
53
53
  .with(headers: { 'Accept' => 'application/json' })
54
54
  .to_return(status: 200, body: "")
55
55
  end
56
56
 
57
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' }
58
+ let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
59
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"
60
+ flat_params_url = "https://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
61
61
  expect(subject.env.url.to_s).to eq(flat_params_url)
62
62
  end
63
63
  end
@@ -66,7 +66,7 @@ describe Qa::Authorities::Loc do
66
66
  describe "#search" do
67
67
  context "any LOC authorities" do
68
68
  let :authority do
69
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
69
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
70
70
  .with(headers: { 'Accept' => 'application/json' })
71
71
  .to_return(body: webmock_fixture("loc-response.txt"), status: 200)
72
72
  described_class.subauthority_for("geographicAreas")
@@ -95,7 +95,7 @@ describe Qa::Authorities::Loc do
95
95
 
96
96
  context "subject terms" do
97
97
  let :results do
98
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
98
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
99
99
  .with(headers: { 'Accept' => 'application/json' })
100
100
  .to_return(body: webmock_fixture("loc-subjects-response.txt"), status: 200)
101
101
  described_class.subauthority_for("subjects").search("History--")
@@ -111,7 +111,7 @@ describe Qa::Authorities::Loc do
111
111
 
112
112
  context "name terms" do
113
113
  let :results do
114
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
114
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
115
115
  .with(headers: { 'Accept' => 'application/json' })
116
116
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
117
117
  described_class.subauthority_for("names").search("Berry")
@@ -125,7 +125,7 @@ describe Qa::Authorities::Loc do
125
125
  describe "#find" do
126
126
  context "using a subject id" do
127
127
  let :results do
128
- stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json")
128
+ stub_request(:get, "https://id.loc.gov/authorities/subjects/sh2002003586.json")
129
129
  .with(headers: { 'Accept' => 'application/json' })
130
130
  .to_return(status: 200, body: webmock_fixture("loc-subject-find-response.txt"), headers: {})
131
131
  described_class.subauthority_for("subjects").find("sh2002003586")
@@ -14,13 +14,19 @@ RSpec.describe Qa::LinkedData::AuthorityUrlService do
14
14
  end
15
15
 
16
16
  describe '.build_url' do
17
+ let(:request_header) do
18
+ {
19
+ subauthority: subauthority,
20
+ replacements: substitutions
21
+ }
22
+ end
17
23
  context 'when authority is not registered' do
18
24
  let(:authority) { :BAD_AUTHORITY }
19
25
 
20
26
  it 'raises error' do
21
27
  expected_error = Qa::InvalidLinkedDataAuthority
22
28
  expected_error_message = "Unable to initialize linked data authority 'BAD_AUTHORITY'"
23
- expect { described_class.build_url(action_config: action_config, subauthority: subauthority, action: action, action_request: action_request, substitutions: substitutions) }
29
+ expect { described_class.build_url(action_config: action_config, action: action, action_request: action_request, request_header: request_header) }
24
30
  .to raise_error(expected_error, expected_error_message)
25
31
  end
26
32
  end
@@ -33,7 +39,7 @@ RSpec.describe Qa::LinkedData::AuthorityUrlService do
33
39
  skip "Pending better handling of unsupported subauthorities"
34
40
  expected_error = Qa::InvalidLinkedDataAuthority
35
41
  expected_error_message = "Unable to initialize linked data sub-authority BAD_SUBAUTHORITY"
36
- expect { described_class.build_url(action_config: action_config, subauthority: subauthority, action: action, action_request: action_request, substitutions: substitutions) }
42
+ expect { described_class.build_url(action_config: action_config, action: action, action_request: action_request, request_header: request_header) }
37
43
  .to raise_error(expected_error, expected_error_message)
38
44
  end
39
45
  end
@@ -44,7 +50,7 @@ RSpec.describe Qa::LinkedData::AuthorityUrlService do
44
50
  it 'raises error' do
45
51
  expected_error = Qa::UnsupportedAction
46
52
  expected_error_message = "BAD_ACTION Not Supported - Action must be one of the supported actions (e.g. :term, :search)"
47
- expect { described_class.build_url(action_config: action_config, subauthority: subauthority, action: action, action_request: action_request, substitutions: substitutions) }
53
+ expect { described_class.build_url(action_config: action_config, action: action, action_request: action_request, request_header: request_header) }
48
54
  .to raise_error(expected_error, expected_error_message)
49
55
  end
50
56
  end
@@ -55,16 +61,16 @@ RSpec.describe Qa::LinkedData::AuthorityUrlService do
55
61
  it 'raises error' do
56
62
  expected_error = Qa::IriTemplate::MissingParameter
57
63
  expected_error_message = "query is required, but missing"
58
- expect { described_class.build_url(action_config: action_config, subauthority: subauthority, action: action, action_request: action_request, substitutions: substitutions) }
64
+ expect { described_class.build_url(action_config: action_config, action: action, action_request: action_request, request_header: request_header) }
59
65
  .to raise_error(expected_error, expected_error_message)
60
66
  end
61
67
  end
62
68
 
63
- subject do
64
- described_class.build_url(action_config: action_config, subauthority: subauthority, action: action, action_request: action_request, substitutions: substitutions)
65
- end
66
-
67
69
  context 'when no errors' do
70
+ subject do
71
+ described_class.build_url(action_config: action_config, action: action, action_request: action_request, request_header: request_header)
72
+ end
73
+
68
74
  context 'and performing search action' do
69
75
  context 'and all substitutions specified' do
70
76
  let(:substitutions) do
@@ -66,6 +66,7 @@ RSpec.describe Qa::LinkedData::GraphService do
66
66
  subject { described_class.load_graph(url: url) }
67
67
 
68
68
  let(:url) { 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=cql.any%20all%20%22cornell%22&sortKeys=usage' }
69
+ let(:regurl) { 'http:\/\/experimental.worldcat.org\/fast\/search\?maximumRecords=3&query=cql.any%20all%20%22cornell%22&sortKeys=usage' }
69
70
  let(:uri) { URI(url) }
70
71
 
71
72
  before do
@@ -74,7 +75,7 @@ RSpec.describe Qa::LinkedData::GraphService do
74
75
  end
75
76
 
76
77
  it 'raises error' do
77
- expect { subject }.to raise_error(Qa::ServiceError, "Unknown error for #{uri.hostname} on port #{uri.port}. Try again later. (Cause - <#{url}>: (504))")
78
+ expect { subject }.to raise_error(Qa::ServiceError, /Unknown error for #{uri.hostname} on port #{uri.port}. Try again later. \(Cause - <#{regurl}>: \(?504\)?\)/)
78
79
  end
79
80
  end
80
81
  end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Qa::LinkedData::RequestHeaderService do
4
+ let(:request) { double }
5
+
6
+ describe '#search_header' do
7
+ context 'when optional params are defined' do
8
+ let(:search_params) do
9
+ {
10
+ 'subauthority' => 'person',
11
+ 'lang' => 'sp',
12
+ 'maxRecords' => '4',
13
+ 'context' => 'true',
14
+ 'performance_data' => 'true'
15
+ }.with_indifferent_access
16
+ end
17
+ before { allow(request).to receive(:env).and_return('HTTP_ACCEPT_LANGUAGE' => 'de') }
18
+
19
+ it 'uses passed in params' do
20
+ expected_results =
21
+ {
22
+ context: true,
23
+ performance_data: true,
24
+ replacements: { 'maxRecords' => '4' },
25
+ subauthority: 'person',
26
+ user_language: ['sp']
27
+ }
28
+ expect(described_class.new(request, search_params).search_header).to eq expected_results
29
+ end
30
+ end
31
+
32
+ context 'when none of the optional params are defined' do
33
+ context 'and request does not define language' do
34
+ before { allow(request).to receive(:env).and_return('HTTP_ACCEPT_LANGUAGE' => nil) }
35
+ it 'returns defaults' do
36
+ expected_results =
37
+ {
38
+ context: false,
39
+ performance_data: false,
40
+ replacements: {},
41
+ subauthority: nil,
42
+ user_language: nil
43
+ }
44
+ expect(described_class.new(request, {}).search_header).to eq expected_results
45
+ end
46
+ end
47
+
48
+ context 'and request does define language' do
49
+ before { allow(request).to receive(:env).and_return('HTTP_ACCEPT_LANGUAGE' => 'de') }
50
+ it 'returns defaults with language set to request language' do
51
+ expected_results =
52
+ {
53
+ context: false,
54
+ performance_data: false,
55
+ replacements: {},
56
+ subauthority: nil,
57
+ user_language: ['de']
58
+ }
59
+ expect(described_class.new(request, {}).search_header).to eq expected_results
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#fetch_header' do
66
+ context 'when optional params are defined' do
67
+ let(:fetch_params) do
68
+ {
69
+ 'subauthority' => 'person',
70
+ 'lang' => 'sp',
71
+ 'extra' => 'data',
72
+ 'even' => 'more data',
73
+ 'format' => 'n3',
74
+ 'performance_data' => 'true'
75
+ }.with_indifferent_access
76
+ end
77
+ before { allow(request).to receive(:env).and_return('HTTP_ACCEPT_LANGUAGE' => 'de') }
78
+
79
+ it 'uses passed in params' do
80
+ expected_results =
81
+ {
82
+ format: 'n3',
83
+ performance_data: true,
84
+ replacements: { 'extra' => 'data', 'even' => 'more data' },
85
+ subauthority: 'person',
86
+ user_language: ['sp']
87
+ }
88
+ expect(described_class.new(request, fetch_params).fetch_header).to eq expected_results
89
+ end
90
+ end
91
+
92
+ context 'when none of the optional params are defined' do
93
+ context 'and request does not define language' do
94
+ before { allow(request).to receive(:env).and_return('HTTP_ACCEPT_LANGUAGE' => nil) }
95
+ it 'returns defaults' do
96
+ expected_results =
97
+ {
98
+ format: 'json',
99
+ performance_data: false,
100
+ replacements: {},
101
+ subauthority: nil,
102
+ user_language: nil
103
+ }
104
+ expect(described_class.new(request, {}).fetch_header).to eq expected_results
105
+ end
106
+ end
107
+
108
+ context 'and request does define language' do
109
+ before { allow(request).to receive(:env).and_return('HTTP_ACCEPT_LANGUAGE' => 'de') }
110
+ it 'returns defaults with language set to request language' do
111
+ expected_results =
112
+ {
113
+ format: 'json',
114
+ performance_data: false,
115
+ replacements: {},
116
+ subauthority: nil,
117
+ user_language: ['de']
118
+ }
119
+ expect(described_class.new(request, {}).fetch_header).to eq expected_results
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end