qa 0.10.1 → 0.10.2
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/Rakefile +12 -2
- data/app/controllers/qa/terms_controller.rb +14 -16
- data/app/models/qa/mesh_tree.rb +3 -5
- data/app/models/qa/subject_mesh_term.rb +15 -15
- data/config/routes.rb +1 -1
- data/lib/generators/qa/install/install_generator.rb +2 -3
- data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +3 -5
- data/lib/generators/qa/local/tables/tables_generator.rb +4 -6
- data/lib/qa/authorities/assign_fast/generic_authority.rb +16 -19
- data/lib/qa/authorities/assign_fast_subauthority.rb +3 -5
- data/lib/qa/authorities/authority_with_sub_authority.rb +1 -2
- data/lib/qa/authorities/base.rb +2 -3
- data/lib/qa/authorities/geonames.rb +11 -12
- data/lib/qa/authorities/getty.rb +7 -8
- data/lib/qa/authorities/getty/aat.rb +11 -12
- data/lib/qa/authorities/getty/tgn.rb +15 -15
- data/lib/qa/authorities/getty/ulan.rb +15 -16
- data/lib/qa/authorities/loc/generic_authority.rb +32 -33
- data/lib/qa/authorities/loc_subauthority.rb +17 -20
- data/lib/qa/authorities/local.rb +41 -40
- data/lib/qa/authorities/local/file_based_authority.rb +18 -19
- data/lib/qa/authorities/local/mysql_table_based_authority.rb +8 -6
- data/lib/qa/authorities/local/registry.rb +5 -5
- data/lib/qa/authorities/local/table_based_authority.rb +26 -19
- data/lib/qa/authorities/mesh.rb +8 -16
- data/lib/qa/authorities/mesh_tools.rb +5 -5
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +4 -6
- data/lib/qa/authorities/mesh_tools/mesh_importer.rb +11 -13
- data/lib/qa/authorities/oclcts.rb +0 -1
- data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +16 -16
- data/lib/qa/authorities/tgnlang.rb +7 -12
- data/lib/qa/version.rb +1 -1
- data/spec/controllers/terms_controller_spec.rb +44 -54
- data/spec/lib/authorities/assign_fast_spec.rb +25 -27
- data/spec/lib/authorities/file_based_authority_spec.rb +25 -26
- data/spec/lib/authorities/geonames_spec.rb +5 -6
- data/spec/lib/authorities/getty/aat_spec.rb +6 -10
- data/spec/lib/authorities/getty/tgn_spec.rb +6 -10
- data/spec/lib/authorities/getty/ulan_spec.rb +6 -10
- data/spec/lib/authorities/getty_spec.rb +4 -5
- data/spec/lib/authorities/loc_spec.rb +30 -36
- data/spec/lib/authorities/local_spec.rb +5 -7
- data/spec/lib/authorities/mesh_spec.rb +9 -9
- data/spec/lib/authorities/mysql_table_based_authority_spec.rb +13 -5
- data/spec/lib/authorities/oclcts_spec.rb +17 -21
- data/spec/lib/authorities/table_based_authority_spec.rb +21 -12
- data/spec/lib/authorities/tgnlang_spec.rb +4 -6
- data/spec/lib/authorities_loc_subauthorities.rb +50 -54
- data/spec/lib/mesh_data_parser_spec.rb +73 -79
- data/spec/lib/services/rdf_authority_parser_spec.rb +2 -7
- data/spec/lib/tasks/mesh.rake_spec.rb +16 -12
- data/spec/models/subject_mesh_term_spec.rb +4 -4
- data/spec/routing/route_spec.rb +13 -15
- data/spec/spec_helper.rb +3 -4
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -1
- metadata +45 -17
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Qa::Authorities::Loc do
|
4
|
-
|
5
4
|
describe "#new" do
|
6
5
|
context "without a sub-authority" do
|
7
|
-
it "
|
6
|
+
it "raises an exception" do
|
8
7
|
expect { described_class.new }.to raise_error RuntimeError, "Initializing with as sub authority is removed. use Module.subauthority_for(nil) instead"
|
9
8
|
end
|
10
9
|
end
|
@@ -12,24 +11,24 @@ describe Qa::Authorities::Loc do
|
|
12
11
|
|
13
12
|
describe "#subauthority_for" do
|
14
13
|
context "with an invalid sub-authority" do
|
15
|
-
it "
|
16
|
-
expect {
|
14
|
+
it "raises an exception" do
|
15
|
+
expect { described_class.subauthority_for("foo") }.to raise_error Qa::InvalidSubAuthority
|
17
16
|
end
|
18
17
|
end
|
19
18
|
context "with a valid sub-authority" do
|
20
|
-
it "
|
21
|
-
expect(
|
19
|
+
it "creates the authority" do
|
20
|
+
expect(described_class.subauthority_for("subjects")).to be_kind_of Qa::Authorities::Loc::GenericAuthority
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
25
|
describe "urls" do
|
27
26
|
let :authority do
|
28
|
-
|
27
|
+
described_class.subauthority_for("subjects")
|
29
28
|
end
|
30
29
|
|
31
30
|
context "for searching" do
|
32
|
-
it "
|
31
|
+
it "returns a url" do
|
33
32
|
url = 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json'
|
34
33
|
expect(authority.build_query_url("foo")).to eq(url)
|
35
34
|
end
|
@@ -44,46 +43,43 @@ describe Qa::Authorities::Loc do
|
|
44
43
|
end
|
45
44
|
|
46
45
|
describe "#search" do
|
47
|
-
|
48
46
|
context "any LOC authorities" do
|
49
47
|
let :authority do
|
50
|
-
stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
|
49
|
+
.with(headers: { 'Accept' => 'application/json' })
|
50
|
+
.to_return(body: webmock_fixture("loc-response.txt"), status: 200)
|
51
|
+
described_class.subauthority_for("geographicAreas")
|
54
52
|
end
|
55
53
|
|
56
|
-
it "
|
57
|
-
expect { authority.search("s") }.to change { authority.raw_response }
|
58
|
-
from(nil)
|
59
|
-
to(JSON.parse(webmock_fixture("loc-response.txt").read))
|
54
|
+
it "retains the raw respsonse from the LC service in JSON" do
|
55
|
+
expect { authority.search("s") }.to change { authority.raw_response }
|
56
|
+
.from(nil)
|
57
|
+
.to(JSON.parse(webmock_fixture("loc-response.txt").read))
|
60
58
|
end
|
61
59
|
|
62
60
|
describe "the returned results" do
|
63
|
-
|
64
61
|
let :results do
|
65
62
|
authority.search("s")
|
66
63
|
end
|
67
64
|
|
68
|
-
it "
|
65
|
+
it "has :id and :label elements" do
|
69
66
|
expect(results.first["label"]).to eq("West (U.S.)")
|
70
67
|
expect(results.first["id"]).to eq("info:lc/vocabulary/geographicAreas/n-usp")
|
71
68
|
expect(results.last["label"]).to eq("Baltic States")
|
72
69
|
expect(results.last["id"]).to eq("info:lc/vocabulary/geographicAreas/eb")
|
73
70
|
expect(results.size).to eq(20)
|
74
71
|
end
|
75
|
-
|
76
72
|
end
|
77
73
|
end
|
78
74
|
|
79
75
|
context "subject terms" do
|
80
76
|
let :results do
|
81
|
-
stub_request(:get, "http://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
stub_request(:get, "http://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
|
78
|
+
.with(headers: { 'Accept' => 'application/json' })
|
79
|
+
.to_return(body: webmock_fixture("loc-subjects-response.txt"), status: 200)
|
80
|
+
described_class.subauthority_for("subjects").search("History--")
|
85
81
|
end
|
86
|
-
it "
|
82
|
+
it "has a URI for the id and a string label" do
|
87
83
|
expect(results.count).to eq(20)
|
88
84
|
expect(results.first["label"]).to eq("History--Philosophy--History--20th century")
|
89
85
|
expect(results.first["id"]).to eq("info:lc/authorities/subjects/sh2008121753")
|
@@ -94,25 +90,24 @@ describe Qa::Authorities::Loc do
|
|
94
90
|
|
95
91
|
context "name terms" do
|
96
92
|
let :results do
|
97
|
-
stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
|
98
|
-
|
99
|
-
|
100
|
-
|
93
|
+
stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
|
94
|
+
.with(headers: { 'Accept' => 'application/json' })
|
95
|
+
.to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
|
96
|
+
described_class.subauthority_for("names").search("Berry")
|
101
97
|
end
|
102
|
-
it "
|
98
|
+
it "retrieves names via search" do
|
103
99
|
expect(results.first["label"]).to eq("Berry, James W. (James William), 1938-")
|
104
100
|
end
|
105
101
|
end
|
106
|
-
|
107
102
|
end
|
108
103
|
|
109
104
|
describe "#find" do
|
110
105
|
context "using a subject id" do
|
111
106
|
let :results do
|
112
|
-
stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json")
|
113
|
-
with(:
|
114
|
-
to_return(:
|
115
|
-
|
107
|
+
stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json")
|
108
|
+
.with(headers: { 'Accept' => 'application/json' })
|
109
|
+
.to_return(status: 200, body: webmock_fixture("loc-subject-find-response.txt"), headers: {})
|
110
|
+
described_class.subauthority_for("subjects").find("sh2002003586")
|
116
111
|
end
|
117
112
|
it "returns the complete record for a given subject" do
|
118
113
|
expect(results.count).to eq(20)
|
@@ -120,5 +115,4 @@ describe Qa::Authorities::Loc do
|
|
120
115
|
end
|
121
116
|
end
|
122
117
|
end
|
123
|
-
|
124
118
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Qa::Authorities::Local do
|
4
|
-
|
5
4
|
describe "new" do
|
6
|
-
it "
|
5
|
+
it "raises an error" do
|
7
6
|
expect { described_class.new }.to raise_error RuntimeError, "Initializing with as sub authority is removed. use Module.subauthority_for(nil) instead"
|
8
7
|
end
|
9
8
|
end
|
@@ -40,7 +39,7 @@ describe Qa::Authorities::Local do
|
|
40
39
|
context "when the path doesn't exist" do
|
41
40
|
before do
|
42
41
|
@original_path = described_class.config[:local_path]
|
43
|
-
described_class.config[:local_path] = '/foo/bar'
|
42
|
+
described_class.config[:local_path] = '/foo/bar'
|
44
43
|
end
|
45
44
|
after { described_class.config[:local_path] = @original_path }
|
46
45
|
|
@@ -50,20 +49,19 @@ describe Qa::Authorities::Local do
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
|
54
52
|
describe ".subauthority_for" do
|
55
53
|
context "without a sub-authority" do
|
56
|
-
it "
|
54
|
+
it "raises an error is the sub-authority is not provided" do
|
57
55
|
expect { described_class.subauthority_for }.to raise_error ArgumentError
|
58
56
|
end
|
59
|
-
it "
|
57
|
+
it "raises an error is the sub-authority does not exist" do
|
60
58
|
expect { described_class.subauthority_for("foo") }.to raise_error Qa::InvalidSubAuthority
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
64
62
|
context "with a sub authority" do
|
65
63
|
subject { described_class.subauthority_for("authority_A") }
|
66
|
-
it "
|
64
|
+
it "returns a file authority" do
|
67
65
|
expect(subject).to be_kind_of Qa::Authorities::Local::FileBasedAuthority
|
68
66
|
end
|
69
67
|
end
|
@@ -10,9 +10,9 @@ describe Qa::Authorities::Mesh do
|
|
10
10
|
File.open(webmock_fixture('mesh.txt').path) do |f|
|
11
11
|
m.import_from_file(f)
|
12
12
|
end
|
13
|
-
where_unique_record(Qa::SubjectMeshTerm,
|
14
|
-
where_unique_record(Qa::SubjectMeshTerm,
|
15
|
-
where_unique_record(Qa::SubjectMeshTerm,
|
13
|
+
where_unique_record(Qa::SubjectMeshTerm, term_lower: "malaria")
|
14
|
+
where_unique_record(Qa::SubjectMeshTerm, term: "Malaria")
|
15
|
+
where_unique_record(Qa::SubjectMeshTerm, term_id: "D008288")
|
16
16
|
expect(Qa::SubjectMeshTerm.all.length).to eq(11)
|
17
17
|
end
|
18
18
|
|
@@ -27,24 +27,24 @@ describe Qa::Authorities::Mesh do
|
|
27
27
|
Qa::SubjectMeshTerm.delete_all
|
28
28
|
end
|
29
29
|
|
30
|
-
let(:m) {
|
30
|
+
let(:m) { described_class.new }
|
31
31
|
|
32
32
|
it "handles queries" do
|
33
33
|
results = m.search('mr ')
|
34
34
|
expect(results.length).to eq(2)
|
35
|
-
expect(results).to include(
|
36
|
-
expect(results).to include(
|
37
|
-
expect(results).not_to include(
|
35
|
+
expect(results).to include(id: '1', label: 'Mr Plow')
|
36
|
+
expect(results).to include(id: '2', label: 'Mr Snow')
|
37
|
+
expect(results).not_to include(id: '3', label: 'Mrs Fields')
|
38
38
|
end
|
39
39
|
|
40
40
|
it "returns individual records" do
|
41
41
|
result = m.find('2')
|
42
|
-
expect(result).to eq(
|
42
|
+
expect(result).to eq(id: '2', label: 'Mr Snow', synonyms: [])
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns all records" do
|
46
46
|
expect(m.all.count).to eq(3)
|
47
|
-
expect(m.all).to include(
|
47
|
+
expect(m.all).to include(id: "2", label: "Mr Snow")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -8,6 +8,16 @@ describe Qa::Authorities::Local::MysqlTableBasedAuthority do
|
|
8
8
|
Qa::Authorities::Local.register_subauthority('language', described_class.to_s)
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "::table_name" do
|
12
|
+
subject { described_class.table_name }
|
13
|
+
it { is_expected.to eq("qa_local_authority_entries") }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "::table_index" do
|
17
|
+
subject { described_class.table_index }
|
18
|
+
it { is_expected.to eq("index_qa_local_authority_entries_on_lower_label_and_authority") }
|
19
|
+
end
|
20
|
+
|
11
21
|
describe "#check_for_index" do
|
12
22
|
let(:connection) { ActiveRecord::Base.connection }
|
13
23
|
before do
|
@@ -15,7 +25,7 @@ describe Qa::Authorities::Local::MysqlTableBasedAuthority do
|
|
15
25
|
end
|
16
26
|
context "with no index" do
|
17
27
|
before do
|
18
|
-
#allow(connection).to receive(:index_name_exists?).and_return(nil)
|
28
|
+
# allow(connection).to receive(:index_name_exists?).and_return(nil)
|
19
29
|
end
|
20
30
|
it "outputs an error message" do
|
21
31
|
expect(Rails.logger).to receive(:error)
|
@@ -36,7 +46,7 @@ describe Qa::Authorities::Local::MysqlTableBasedAuthority do
|
|
36
46
|
describe "#search" do
|
37
47
|
context "with an empty query string" do
|
38
48
|
let(:expected) { [] }
|
39
|
-
it "
|
49
|
+
it "returns no results" do
|
40
50
|
expect(Qa::LocalAuthorityEntry).not_to receive(:where)
|
41
51
|
expect(language.search("")).to eq(expected)
|
42
52
|
end
|
@@ -44,12 +54,10 @@ describe Qa::Authorities::Local::MysqlTableBasedAuthority do
|
|
44
54
|
context "with at least one matching entry" do
|
45
55
|
it "is case insensitive by using lower_lable column" do
|
46
56
|
expect(Qa::LocalAuthorityEntry).to receive(:where).with(local_authority: language_auth).and_return(base_relation)
|
47
|
-
expect(base_relation).to receive(:where).with("lower_label like ?","fre%").and_return(base_relation)
|
57
|
+
expect(base_relation).to receive(:where).with("lower_label like ?", "fre%").and_return(base_relation)
|
48
58
|
expect(base_relation).to receive(:limit).and_return([])
|
49
59
|
language.search("fRe")
|
50
60
|
end
|
51
61
|
end
|
52
|
-
|
53
62
|
end
|
54
|
-
|
55
63
|
end
|
@@ -1,50 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Qa::Authorities::Oclcts do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@first_query = Qa::Authorities::Oclcts.subauthority_for("mesh")
|
4
|
+
before do
|
5
|
+
stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts.rootHeading%20exact%20%22ball*%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1")
|
6
|
+
.to_return(body: webmock_fixture("oclcts-response-mesh-1.txt"), status: 200)
|
7
|
+
stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts.rootHeading%20exact%20%22alph*%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1")
|
8
|
+
.to_return(body: webmock_fixture("oclcts-response-mesh-2.txt"), status: 200)
|
9
|
+
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")
|
10
|
+
.to_return(body: webmock_fixture("oclcts-response-mesh-3.txt"), status: 200)
|
11
|
+
|
12
|
+
@first_query = described_class.subauthority_for("mesh")
|
14
13
|
@terms = @first_query.search("ball")
|
15
14
|
@term_record = @first_query.find(@terms.first["id"])
|
16
|
-
@second_query =
|
15
|
+
@second_query = described_class.subauthority_for("mesh")
|
17
16
|
@second_query.search("alph")
|
18
17
|
end
|
19
18
|
|
20
19
|
describe "a query for terms" do
|
21
|
-
|
22
|
-
it "should have an array of hashes that match the query" do
|
20
|
+
it "has an array of hashes that match the query" do
|
23
21
|
expect(@terms).to be_kind_of Array
|
24
22
|
expect(@terms.first).to be_kind_of Hash
|
25
23
|
expect(@terms.first["label"]).to be_kind_of String
|
26
24
|
expect(@terms.first["label"]).to include "Ballota"
|
27
25
|
end
|
28
26
|
|
29
|
-
it "
|
27
|
+
it "has an array of hashes containing unique id and label" do
|
30
28
|
expect(@terms.first).to have_key("id")
|
31
29
|
expect(@terms.first).to have_key("label")
|
32
30
|
end
|
33
|
-
|
34
31
|
end
|
35
32
|
|
36
33
|
describe "a query for a single item" do
|
37
|
-
it "
|
34
|
+
it "has a hash of values that represent the item requested" do
|
38
35
|
expect(@term_record).to be_kind_of Hash
|
39
|
-
expect(@term_record.values).to include @terms.first["id"]
|
36
|
+
expect(@term_record.values).to include @terms.first["id"]
|
40
37
|
expect(@term_record.values).to include @terms.first["label"]
|
41
38
|
end
|
42
|
-
|
43
|
-
it "
|
39
|
+
|
40
|
+
it "succeeds for valid ids, even if the id is not in the initial list of responses" do
|
44
41
|
record = @second_query.find(@terms.first["id"])
|
45
42
|
expect(record.values).to include @terms.first["id"]
|
46
43
|
expect(record.values).to include @terms.first["label"]
|
47
44
|
end
|
48
45
|
end
|
49
|
-
|
50
|
-
end
|
46
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Qa::Authorities::Local::TableBasedAuthority do
|
4
|
-
|
5
4
|
let(:language) { Qa::Authorities::Local.subauthority_for("language") }
|
6
5
|
let(:subj) { Qa::Authorities::Local.subauthority_for("subject") }
|
7
6
|
|
@@ -15,28 +14,38 @@ describe Qa::Authorities::Local::TableBasedAuthority do
|
|
15
14
|
Qa::LocalAuthorityEntry.create(local_authority: alternate_auth, label: 'French', uri: 'http://example.com/french')
|
16
15
|
end
|
17
16
|
|
17
|
+
describe "::table_name" do
|
18
|
+
subject { described_class.table_name }
|
19
|
+
it { is_expected.to eq("qa_local_authority_entries") }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "::table_index" do
|
23
|
+
subject { described_class.table_index }
|
24
|
+
it { is_expected.to eq("index_qa_local_authority_entries_on_lower_label") }
|
25
|
+
end
|
26
|
+
|
18
27
|
describe "#all" do
|
19
|
-
let(:expected) { [
|
20
|
-
|
21
|
-
|
22
|
-
it "
|
28
|
+
let(:expected) { [{ 'id' => "A1", 'label' => "Abc Term A1" },
|
29
|
+
{ 'id' => "A2", 'label' => "Term A2" },
|
30
|
+
{ 'id' => "A3", 'label' => "Abc Term A3" }] }
|
31
|
+
it "returns all the entries" do
|
23
32
|
expect(language.all).to eq [
|
24
|
-
{"id"=>"http://id.loc.gov/vocabulary/languages/fre", "label"=>"French"},
|
25
|
-
{"id"=>"http://id.loc.gov/vocabulary/languages/uig", "label"=>"Uighur"}
|
26
|
-
|
33
|
+
{ "id" => "http://id.loc.gov/vocabulary/languages/fre", "label" => "French" },
|
34
|
+
{ "id" => "http://id.loc.gov/vocabulary/languages/uig", "label" => "Uighur" }
|
35
|
+
]
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
30
39
|
describe "#search" do
|
31
40
|
context "with an empty query string" do
|
32
41
|
let(:expected) { [] }
|
33
|
-
it "
|
42
|
+
it "returns no results" do
|
34
43
|
expect(language.search("")).to eq(expected)
|
35
44
|
end
|
36
45
|
end
|
37
46
|
context "with at least one matching entry" do
|
38
47
|
it "is case insensitive" do
|
39
|
-
expect(language.search("fRe")).to eq [{"id"=>"http://id.loc.gov/vocabulary/languages/fre", "label"=>"French"}]
|
48
|
+
expect(language.search("fRe")).to eq [{ "id" => "http://id.loc.gov/vocabulary/languages/fre", "label" => "French" }]
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
@@ -49,7 +58,7 @@ describe Qa::Authorities::Local::TableBasedAuthority do
|
|
49
58
|
|
50
59
|
describe "#find" do
|
51
60
|
context "term exists" do
|
52
|
-
it "
|
61
|
+
it "returns the full term record" do
|
53
62
|
record = language.find('http://id.loc.gov/vocabulary/languages/fre')
|
54
63
|
expect(record).to be_a HashWithIndifferentAccess
|
55
64
|
expect(record).to eq('id' => "http://id.loc.gov/vocabulary/languages/fre",
|
@@ -59,7 +68,7 @@ describe Qa::Authorities::Local::TableBasedAuthority do
|
|
59
68
|
context "term does not exist" do
|
60
69
|
let(:id) { "NonID" }
|
61
70
|
let(:expected) { {} }
|
62
|
-
it "
|
71
|
+
it "returns an empty hash" do
|
63
72
|
expect(language.find('http://id.loc.gov/vocabulary/languages/eng')).to be_nil
|
64
73
|
end
|
65
74
|
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Qa::Authorities::Tgnlang do
|
4
|
-
|
5
|
-
let(:subject) { @terms = Qa::Authorities::Tgnlang.new }
|
4
|
+
let(:subject) { @terms = described_class.new }
|
6
5
|
|
7
6
|
describe "#search" do
|
8
|
-
it "
|
9
|
-
expect(subject.search("Tibetan")).to eq([{"id"=>"75446", "label"=>"Tibetan"}])
|
7
|
+
it "returns unique record with query of Tibetan" do
|
8
|
+
expect(subject.search("Tibetan")).to eq([{ "id" => "75446", "label" => "Tibetan" }])
|
10
9
|
end
|
11
|
-
it "
|
10
|
+
it "returns type Array" do
|
12
11
|
expect(subject.search("Tibetan")).to be_kind_of(Array)
|
13
12
|
end
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Qa::Authorities::LocSubauthority do
|
4
|
-
|
5
4
|
let(:subject) do
|
6
5
|
class TestAuthority
|
7
6
|
include Qa::Authorities::LocSubauthority
|
@@ -10,7 +9,7 @@ describe Qa::Authorities::LocSubauthority do
|
|
10
9
|
end
|
11
10
|
|
12
11
|
context "with a valid subauthority" do
|
13
|
-
it "
|
12
|
+
it "returns a url" do
|
14
13
|
subauthority_table.keys.each do |authority|
|
15
14
|
expect(subject.get_url_for_authority(authority)).to eq(subauthority_table[authority])
|
16
15
|
end
|
@@ -18,7 +17,7 @@ describe Qa::Authorities::LocSubauthority do
|
|
18
17
|
end
|
19
18
|
|
20
19
|
context "with a non-existent subauthority" do
|
21
|
-
it "
|
20
|
+
it "returns nil" do
|
22
21
|
expect(subject.get_url_for_authority("fake")).to be_nil
|
23
22
|
end
|
24
23
|
end
|
@@ -26,56 +25,53 @@ describe Qa::Authorities::LocSubauthority do
|
|
26
25
|
# This is the original data structure that was used to define subauthority urls
|
27
26
|
# It is retained here to ensure our refactor succeeded
|
28
27
|
def subauthority_table
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
78
|
-
end
|
28
|
+
vocab_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F'
|
29
|
+
authority_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F'
|
30
|
+
datatype_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F'
|
31
|
+
vocab_preservation_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F'
|
32
|
+
{
|
33
|
+
'subjects' => authority_base_url,
|
34
|
+
'names' => authority_base_url,
|
35
|
+
'classification' => authority_base_url,
|
36
|
+
'childrensSubjects' => authority_base_url,
|
37
|
+
'genreForms' => authority_base_url,
|
38
|
+
'performanceMediums' => authority_base_url,
|
39
|
+
'graphicMaterials' => vocab_base_url,
|
40
|
+
'organizations' => vocab_base_url,
|
41
|
+
'relators' => vocab_base_url,
|
42
|
+
'countries' => vocab_base_url,
|
43
|
+
'ethnographicTerms' => vocab_base_url,
|
44
|
+
'geographicAreas' => vocab_base_url,
|
45
|
+
'languages' => vocab_base_url,
|
46
|
+
'iso639-1' => vocab_base_url,
|
47
|
+
'iso639-2' => vocab_base_url,
|
48
|
+
'iso639-5' => vocab_base_url,
|
49
|
+
'edtf' => datatype_base_url,
|
50
|
+
'preservation' => vocab_base_url,
|
51
|
+
'actionsGranted' => vocab_base_url,
|
52
|
+
'agentType' => vocab_base_url,
|
53
|
+
'contentLocationType' => vocab_preservation_base_url,
|
54
|
+
'copyrightStatus' => vocab_preservation_base_url,
|
55
|
+
'cryptographicHashFunctions' => vocab_preservation_base_url,
|
56
|
+
'environmentCharacteristic' => vocab_preservation_base_url,
|
57
|
+
'environmentPurpose' => vocab_preservation_base_url,
|
58
|
+
'eventRelatedAgentRole' => vocab_preservation_base_url,
|
59
|
+
'eventRelatedObjectRole' => vocab_preservation_base_url,
|
60
|
+
'eventType' => vocab_preservation_base_url,
|
61
|
+
'formatRegistryRole' => vocab_preservation_base_url,
|
62
|
+
'hardwareType' => vocab_preservation_base_url,
|
63
|
+
'inhibitorTarget' => vocab_preservation_base_url,
|
64
|
+
'inhibitorType' => vocab_preservation_base_url,
|
65
|
+
'objectCategory' => vocab_preservation_base_url,
|
66
|
+
'preservationLevelRole' => vocab_preservation_base_url,
|
67
|
+
'relationshipSubType' => vocab_preservation_base_url,
|
68
|
+
'relationshipType' => vocab_preservation_base_url,
|
69
|
+
'rightsBasis' => vocab_preservation_base_url,
|
70
|
+
'rightsRelatedAgentRole' => vocab_preservation_base_url,
|
71
|
+
'signatureEncoding' => vocab_preservation_base_url,
|
72
|
+
'signatureMethod' => vocab_preservation_base_url,
|
73
|
+
'softwareType' => vocab_preservation_base_url,
|
74
|
+
'storageMedium' => vocab_preservation_base_url
|
75
|
+
}
|
79
76
|
end
|
80
|
-
|
81
77
|
end
|