qa 0.4.3 → 0.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -13
  3. data/app/controllers/qa/terms_controller.rb +7 -3
  4. data/config/routes.rb +3 -3
  5. data/lib/qa.rb +2 -2
  6. data/lib/qa/authorities/authority_with_sub_authority.rb +17 -8
  7. data/lib/qa/authorities/base.rb +1 -1
  8. data/lib/qa/authorities/getty.rb +6 -52
  9. data/lib/qa/authorities/getty/aat.rb +55 -0
  10. data/lib/qa/authorities/loc.rb +9 -64
  11. data/lib/qa/authorities/loc/generic_authority.rb +71 -0
  12. data/lib/qa/authorities/local.rb +66 -31
  13. data/lib/qa/authorities/local/file_based_authority.rb +49 -0
  14. data/lib/qa/authorities/local_subauthority.rb +5 -5
  15. data/lib/qa/authorities/oclcts.rb +11 -32
  16. data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +42 -0
  17. data/lib/qa/version.rb +1 -1
  18. data/spec/controllers/terms_controller_spec.rb +9 -9
  19. data/spec/internal/db/development.sqlite3 +0 -0
  20. data/spec/internal/log/development.log +10910 -0
  21. data/spec/lib/{authorities_local_spec.rb → authorities/file_based_authority_spec.rb} +8 -20
  22. data/spec/lib/{authorities_getty_spec.rb → authorities/getty/aat_spec.rb} +13 -19
  23. data/spec/lib/authorities/getty_spec.rb +30 -0
  24. data/spec/lib/{authorities_loc_spec.rb → authorities/loc_spec.rb} +12 -11
  25. data/spec/lib/authorities/local_spec.rb +48 -0
  26. data/spec/lib/{authorities_mesh_spec.rb → authorities/mesh_spec.rb} +0 -0
  27. data/spec/lib/{authorities_oclcts_spec.rb → authorities/oclcts_spec.rb} +2 -2
  28. data/spec/lib/{authorities_tgnlang_spec.rb → authorities/tgnlang_spec.rb} +0 -0
  29. data/spec/lib/authorities_loc_subauthorities.rb +3 -3
  30. data/spec/lib/authorities_local_subauthorities_spec.rb +3 -3
  31. data/spec/routing/route_spec.rb +3 -3
  32. metadata +22 -14
@@ -1,22 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Qa::Authorities::Local do
4
-
5
- let(:authority_a) { Qa::Authorities::Local.new("authority_A") }
6
- let(:authority_b) { Qa::Authorities::Local.new("authority_B") }
7
- let(:authority_c) { Qa::Authorities::Local.new("authority_C") }
8
- let(:authority_d) { Qa::Authorities::Local.new("authority_D") }
9
-
10
- describe "::new" do
11
- context "without a sub-authority" do
12
- it "should raise an error is the sub-authority is not provided" do
13
- expect { Qa::Authorities::Local.new }.to raise_error
14
- end
15
- it "should raise an error is the sub-authority does not exist" do
16
- expect { Qa::Authorities::Local.new("foo") }.to raise_error
17
- end
18
- end
19
- end
3
+ describe Qa::Authorities::Local::FileBasedAuthority do
4
+ let(:authority_a) { Qa::Authorities::Local.subauthority_for("authority_A") }
5
+ let(:authority_b) { Qa::Authorities::Local.subauthority_for("authority_B") }
6
+ let(:authority_c) { Qa::Authorities::Local.subauthority_for("authority_C") }
7
+ let(:authority_d) { Qa::Authorities::Local.subauthority_for("authority_D") }
20
8
 
21
9
  describe "#all" do
22
10
  let(:expected) { [ { 'id'=> "A1", 'label' => "Abc Term A1" },
@@ -34,12 +22,12 @@ describe Qa::Authorities::Local do
34
22
  end
35
23
  end
36
24
  context "authority YAML file is a list of terms" do
37
- let(:expected) { [ { 'id' => "Term C1", 'label' => "Term C1" },
25
+ let(:expected) { [ { 'id' => "Term C1", 'label' => "Term C1" },
38
26
  { 'id' => "Term C2", 'label' => "Term C2" },
39
27
  { 'id' => "Term C3", 'label' => "Term C3" } ] }
40
28
  it "should use the terms as labels" do
41
29
  expect(authority_c.all).to eq(expected)
42
- end
30
+ end
43
31
  end
44
32
  context "YAML file is malformed" do
45
33
  it "should raise an error" do
@@ -75,7 +63,7 @@ describe Qa::Authorities::Local do
75
63
  end
76
64
  end
77
65
  end
78
-
66
+
79
67
  describe "#find" do
80
68
  context "source is a hash" do
81
69
  let(:id) { "A2" }
@@ -1,26 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Qa::Authorities::Getty do
3
+ describe Qa::Authorities::Getty::AAT do
4
4
 
5
- describe "#new" do
6
- context "without a sub-authority" do
7
- it "should raise an exception" do
8
- expect { described_class.new }.to raise_error
9
- end
10
- end
11
- context "with an invalid sub-authority" do
12
- it "should raise an exception" do
13
- expect { described_class.new("foo") }.to raise_error
14
- end
15
- end
16
- context "with a valid sub-authority" do
17
- it "should create the authority" do
18
- expect(described_class.new("aat")).to be_kind_of described_class
19
- end
20
- end
21
- end
5
+ let(:authority) { described_class.new }
22
6
 
23
- let(:authority) { described_class.new("aat") }
24
7
  describe "#build_query_url" do
25
8
  subject { authority.build_query_url("foo") }
26
9
  it { is_expected.to match /^http:\/\/vocab\.getty\.edu\// }
@@ -84,5 +67,16 @@ describe Qa::Authorities::Getty do
84
67
  it { is_expected.to eq(accept: "application/sparql-results+json") }
85
68
  end
86
69
 
70
+ describe "#sparql" do
71
+ subject { authority.sparql('search_term') }
72
+ it { is_expected.to eq 'SELECT ?s ?name {
73
+ ?s a skos:Concept; luc:term "search_term";
74
+ skos:inScheme <http://vocab.getty.edu/aat/> ;
75
+ gvp:prefLabelGVP [skosxl:literalForm ?name].
76
+ FILTER regex(?name, "search_term", "i") .
77
+ } LIMIT 10' }
78
+ end
79
+
87
80
  end
88
81
 
82
+
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qa::Authorities::Getty do
4
+
5
+ describe "#new" do
6
+ it "should raise an exception" do
7
+ expect { described_class.new }.to raise_error
8
+ end
9
+ end
10
+
11
+ describe "#subauthority_for" do
12
+ context "without a sub-authority" do
13
+ it "should raise an exception" do
14
+ expect { described_class.subauthority_for }.to raise_error
15
+ end
16
+ end
17
+
18
+ context "with an invalid sub-authority" do
19
+ it "should raise an exception" do
20
+ expect { described_class.subauthority_for("foo") }.to raise_error
21
+ end
22
+ end
23
+
24
+ context "with a valid sub-authority" do
25
+ it "should create the authority" do
26
+ expect(described_class.subauthority_for("aat")).to be_kind_of Qa::Authorities::Getty::AAT
27
+ end
28
+ end
29
+ end
30
+ end
@@ -8,24 +8,26 @@ describe Qa::Authorities::Loc do
8
8
  expect { Qa::Authorities::Loc.new }.to raise_error
9
9
  end
10
10
  end
11
+ end
12
+
13
+ describe "#subauthority_for" do
11
14
  context "with an invalid sub-authority" do
12
15
  it "should raise an exception" do
13
- expect { Qa::Authorities::Loc.new("foo") }.to raise_error
16
+ expect { Qa::Authorities::Loc.subauthority_for("foo") }.to raise_error
14
17
  end
15
18
  end
16
19
  context "with a valid sub-authority" do
17
20
  it "should create the authority" do
18
- expect(Qa::Authorities::Loc.new("subjects")).to be_kind_of Qa::Authorities::Loc
21
+ expect(Qa::Authorities::Loc.subauthority_for("subjects")).to be_kind_of Qa::Authorities::Loc::GenericAuthority
19
22
  end
20
23
  end
21
24
  end
22
-
23
- describe "urls" do
24
25
 
26
+ describe "urls" do
25
27
  let :authority do
26
- Qa::Authorities::Loc.new("subjects")
28
+ Qa::Authorities::Loc.subauthority_for("subjects")
27
29
  end
28
-
30
+
29
31
  context "for searching" do
30
32
  it "should return a url" do
31
33
  url = 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json'
@@ -39,7 +41,6 @@ describe Qa::Authorities::Loc do
39
41
  expect(authority.find_url("sh2002003586")).to eq(url)
40
42
  end
41
43
  end
42
-
43
44
  end
44
45
 
45
46
  describe "#search" do
@@ -49,7 +50,7 @@ describe Qa::Authorities::Loc do
49
50
  stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas").
50
51
  with(:headers => {'Accept'=>'application/json'}).
51
52
  to_return(:body => webmock_fixture("loc-response.txt"), :status => 200)
52
- Qa::Authorities::Loc.new("geographicAreas")
53
+ Qa::Authorities::Loc.subauthority_for("geographicAreas")
53
54
  end
54
55
 
55
56
  it "should retain the raw respsonse from the LC service in JSON" do
@@ -80,7 +81,7 @@ describe Qa::Authorities::Loc do
80
81
  stub_request(:get, "http://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects").
81
82
  with(:headers => {'Accept'=>'application/json'}).
82
83
  to_return(:body => webmock_fixture("loc-subjects-response.txt"), :status => 200)
83
- Qa::Authorities::Loc.new("subjects").search("History--")
84
+ Qa::Authorities::Loc.subauthority_for("subjects").search("History--")
84
85
  end
85
86
  it "should have a URI for the id and a string label" do
86
87
  expect(results.count).to eq(20)
@@ -96,7 +97,7 @@ describe Qa::Authorities::Loc do
96
97
  stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names").
97
98
  with(:headers => {'Accept'=>'application/json'}).
98
99
  to_return(:body => webmock_fixture("loc-names-response.txt"), :status => 200)
99
- Qa::Authorities::Loc.new("names").search("Berry")
100
+ Qa::Authorities::Loc.subauthority_for("names").search("Berry")
100
101
  end
101
102
  it "should retrieve names via search" do
102
103
  expect(results.first["label"]).to eq("Berry, James W. (James William), 1938-")
@@ -111,7 +112,7 @@ describe Qa::Authorities::Loc do
111
112
  stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json").
112
113
  with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
113
114
  to_return(:status => 200, :body => webmock_fixture("loc-subject-find-response.txt"), :headers => {})
114
- Qa::Authorities::Loc.new("subjects").find("sh2002003586")
115
+ Qa::Authorities::Loc.subauthority_for("subjects").find("sh2002003586")
115
116
  end
116
117
  it "returns the complete record for a given subject" do
117
118
  expect(results.count).to eq(20)
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qa::Authorities::Local do
4
+
5
+ describe "new" do
6
+ it "should raise an error" do
7
+ expect { described_class.new }.to raise_error
8
+ end
9
+ end
10
+
11
+ describe ".subauthority_for" do
12
+ context "without a sub-authority" do
13
+ it "should raise an error is the sub-authority is not provided" do
14
+ expect { described_class.subauthority_for }.to raise_error
15
+ end
16
+ it "should raise an error is the sub-authority does not exist" do
17
+ expect { described_class.subauthority_for("foo") }.to raise_error
18
+ end
19
+ end
20
+
21
+ context "with a sub authority" do
22
+ subject { described_class.subauthority_for("authority_A") }
23
+ it "should return a file authority" do
24
+ expect(subject).to be_kind_of Qa::Authorities::Local::FileBasedAuthority
25
+ end
26
+ end
27
+ end
28
+
29
+ describe ".register" do
30
+ before do
31
+ class SolrAuthority
32
+ def initialize(one)
33
+ end
34
+ end
35
+ described_class.register_subauthority('new_sub', 'SolrAuthority')
36
+ end
37
+
38
+ after { Object.send(:remove_const, :SolrAuthority) }
39
+
40
+ it "adds an entry to subauthorities" do
41
+ expect(described_class.subauthorities).to include 'new_sub'
42
+ end
43
+
44
+ it "creates authorities of the proper type" do
45
+ expect(described_class.subauthority_for('new_sub')).to be_kind_of SolrAuthority
46
+ end
47
+ end
48
+ end
@@ -10,10 +10,10 @@ describe Qa::Authorities::Oclcts do
10
10
  stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=dc.identifier%20exact%20%22D031329Q000821%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1").
11
11
  to_return(:body => webmock_fixture("oclcts-response-mesh-3.txt"), :status => 200)
12
12
 
13
- @first_query = Qa::Authorities::Oclcts.new("mesh")
13
+ @first_query = Qa::Authorities::Oclcts.subauthority_for("mesh")
14
14
  @terms = @first_query.search("ball")
15
15
  @term_record = @first_query.find(@terms.first["id"])
16
- @second_query = Qa::Authorities::Oclcts.new("mesh")
16
+ @second_query = Qa::Authorities::Oclcts.subauthority_for("mesh")
17
17
  @second_query.search("alph")
18
18
  end
19
19
 
@@ -11,8 +11,8 @@ describe Qa::Authorities::LocSubauthority do
11
11
 
12
12
  context "with a valid subauthority" do
13
13
  it "should return a url" do
14
- sub_authority_table.keys.each do |authority|
15
- expect(subject.get_url_for_authority(authority)).to eq(sub_authority_table[authority])
14
+ subauthority_table.keys.each do |authority|
15
+ expect(subject.get_url_for_authority(authority)).to eq(subauthority_table[authority])
16
16
  end
17
17
  end
18
18
  end
@@ -25,7 +25,7 @@ describe Qa::Authorities::LocSubauthority do
25
25
 
26
26
  # This is the original data structure that was used to define subauthority urls
27
27
  # It is retained here to ensure our refactor succeeded
28
- def sub_authority_table
28
+ def subauthority_table
29
29
  begin
30
30
  vocab_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F'
31
31
  authority_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F'
@@ -15,13 +15,13 @@ describe Qa::Authorities::LocalSubauthority do
15
15
  before { @original_path = AUTHORITIES_CONFIG[:local_path] }
16
16
  after { AUTHORITIES_CONFIG[:local_path] = @original_path }
17
17
 
18
- describe "#sub_authorities_path" do
18
+ describe "#subauthorities_path" do
19
19
  before { AUTHORITIES_CONFIG[:local_path] = path }
20
20
  context "configured with a full path" do
21
21
  let(:path) { "/full/path" }
22
22
 
23
23
  it "returns a full path" do
24
- expect(test.sub_authorities_path).to eq(path)
24
+ expect(test.subauthorities_path).to eq(path)
25
25
  end
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ describe Qa::Authorities::LocalSubauthority do
29
29
  let(:path) { "relative/path" }
30
30
 
31
31
  it "returns a path relative to the Rails applicaition" do
32
- expect(test.sub_authorities_path).to eq(File.join(Rails.root, path))
32
+ expect(test.subauthorities_path).to eq(File.join(Rails.root, path))
33
33
  end
34
34
  end
35
35
  end
@@ -9,7 +9,7 @@ describe "QA Routes", :type => :routing do
9
9
  expect({ get: '/terms/vocab' }).to route_to(controller: 'qa/terms', action: 'index', vocab: 'vocab')
10
10
  end
11
11
  it "should route to index with an authority and a subauthority" do
12
- expect({ get: '/terms/vocab/sub' }).to route_to(controller: 'qa/terms', action: 'index', vocab: 'vocab', sub_authority: 'sub')
12
+ expect({ get: '/terms/vocab/sub' }).to route_to(controller: 'qa/terms', action: 'index', vocab: 'vocab', subauthority: 'sub')
13
13
  end
14
14
  end
15
15
 
@@ -18,7 +18,7 @@ describe "QA Routes", :type => :routing do
18
18
  expect({ get: '/search/vocab' }).to route_to(controller: 'qa/terms', action: 'search', vocab: 'vocab')
19
19
  end
20
20
  it "should route to searching for an authority and a subauthority" do
21
- expect({ get: '/search/vocab/sub' }).to route_to(controller: 'qa/terms', action: 'search', vocab: 'vocab', sub_authority: 'sub')
21
+ expect({ get: '/search/vocab/sub' }).to route_to(controller: 'qa/terms', action: 'search', vocab: 'vocab', subauthority: 'sub')
22
22
  end
23
23
  end
24
24
 
@@ -27,7 +27,7 @@ describe "QA Routes", :type => :routing do
27
27
  expect({ get: '/show/vocab/term_id' }).to route_to(controller: 'qa/terms', action: 'show', vocab: 'vocab', id: 'term_id')
28
28
  end
29
29
  it "should route to an authority with a subauthority" do
30
- expect({ get: '/show/vocab/sub/term_id' }).to route_to(controller: 'qa/terms', action: 'show', vocab: 'vocab', sub_authority: 'sub', id: 'term_id')
30
+ expect({ get: '/show/vocab/sub/term_id' }).to route_to(controller: 'qa/terms', action: 'show', vocab: 'vocab', subauthority: 'sub', id: 'term_id')
31
31
  end
32
32
  end
33
33
 
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.4.3
4
+ version: 0.5.0
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: 2015-04-09 00:00:00.000000000 Z
18
+ date: 2015-04-17 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails
@@ -216,15 +216,19 @@ files:
216
216
  - lib/qa/authorities/authority_with_sub_authority.rb
217
217
  - lib/qa/authorities/base.rb
218
218
  - lib/qa/authorities/getty.rb
219
+ - lib/qa/authorities/getty/aat.rb
219
220
  - lib/qa/authorities/loc.rb
221
+ - lib/qa/authorities/loc/generic_authority.rb
220
222
  - lib/qa/authorities/loc_subauthority.rb
221
223
  - lib/qa/authorities/local.rb
224
+ - lib/qa/authorities/local/file_based_authority.rb
222
225
  - lib/qa/authorities/local_subauthority.rb
223
226
  - lib/qa/authorities/mesh.rb
224
227
  - lib/qa/authorities/mesh_tools.rb
225
228
  - lib/qa/authorities/mesh_tools/mesh_data_parser.rb
226
229
  - lib/qa/authorities/mesh_tools/mesh_importer.rb
227
230
  - lib/qa/authorities/oclcts.rb
231
+ - lib/qa/authorities/oclcts/generic_oclc_authority.rb
228
232
  - lib/qa/authorities/tgnlang.rb
229
233
  - lib/qa/authorities/web_service_base.rb
230
234
  - lib/qa/data/TGN_LANGUAGES.xml
@@ -301,14 +305,16 @@ files:
301
305
  - spec/internal/public/favicon.ico
302
306
  - spec/internal/public/robots.txt
303
307
  - spec/internal/test/test_helper.rb
304
- - spec/lib/authorities_getty_spec.rb
305
- - spec/lib/authorities_loc_spec.rb
308
+ - spec/lib/authorities/file_based_authority_spec.rb
309
+ - spec/lib/authorities/getty/aat_spec.rb
310
+ - spec/lib/authorities/getty_spec.rb
311
+ - spec/lib/authorities/loc_spec.rb
312
+ - spec/lib/authorities/local_spec.rb
313
+ - spec/lib/authorities/mesh_spec.rb
314
+ - spec/lib/authorities/oclcts_spec.rb
315
+ - spec/lib/authorities/tgnlang_spec.rb
306
316
  - spec/lib/authorities_loc_subauthorities.rb
307
- - spec/lib/authorities_local_spec.rb
308
317
  - spec/lib/authorities_local_subauthorities_spec.rb
309
- - spec/lib/authorities_mesh_spec.rb
310
- - spec/lib/authorities_oclcts_spec.rb
311
- - spec/lib/authorities_tgnlang_spec.rb
312
318
  - spec/lib/mesh_data_parser_spec.rb
313
319
  - spec/lib/tasks/mesh.rake_spec.rb
314
320
  - spec/models/subject_mesh_term_spec.rb
@@ -409,14 +415,16 @@ test_files:
409
415
  - spec/internal/Rakefile
410
416
  - spec/internal/README.rdoc
411
417
  - spec/internal/test/test_helper.rb
412
- - spec/lib/authorities_getty_spec.rb
413
- - spec/lib/authorities_loc_spec.rb
418
+ - spec/lib/authorities/file_based_authority_spec.rb
419
+ - spec/lib/authorities/getty/aat_spec.rb
420
+ - spec/lib/authorities/getty_spec.rb
421
+ - spec/lib/authorities/loc_spec.rb
422
+ - spec/lib/authorities/local_spec.rb
423
+ - spec/lib/authorities/mesh_spec.rb
424
+ - spec/lib/authorities/oclcts_spec.rb
425
+ - spec/lib/authorities/tgnlang_spec.rb
414
426
  - spec/lib/authorities_loc_subauthorities.rb
415
- - spec/lib/authorities_local_spec.rb
416
427
  - spec/lib/authorities_local_subauthorities_spec.rb
417
- - spec/lib/authorities_mesh_spec.rb
418
- - spec/lib/authorities_oclcts_spec.rb
419
- - spec/lib/authorities_tgnlang_spec.rb
420
428
  - spec/lib/mesh_data_parser_spec.rb
421
429
  - spec/lib/tasks/mesh.rake_spec.rb
422
430
  - spec/models/subject_mesh_term_spec.rb