qa 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +24 -21
- data/Rakefile +1 -1
- data/app/controllers/qa/terms_controller.rb +22 -53
- data/config/routes.rb +4 -7
- data/lib/qa/authorities.rb +3 -1
- data/lib/qa/authorities/base.rb +27 -8
- data/lib/qa/authorities/getty.rb +56 -0
- data/lib/qa/authorities/loc.rb +27 -131
- data/lib/qa/authorities/loc_subauthority.rb +90 -0
- data/lib/qa/authorities/local.rb +38 -21
- data/lib/qa/authorities/local_subauthority.rb +18 -0
- data/lib/qa/authorities/mesh.rb +16 -23
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +0 -25
- data/lib/qa/authorities/mesh_tools/mesh_importer.rb +0 -2
- data/lib/qa/authorities/oclcts.rb +17 -24
- data/lib/qa/authorities/tgnlang.rb +4 -18
- data/lib/qa/authorities/web_service_base.rb +3 -10
- data/lib/qa/version.rb +1 -1
- data/spec/controllers/terms_controller_spec.rb +93 -44
- data/spec/fixtures/aat-response.txt +108 -0
- data/spec/fixtures/getty-aat-find-response.json +2494 -0
- data/spec/fixtures/loc-response.txt +1521 -17
- data/spec/fixtures/loc-subject-find-response.txt +24 -0
- data/spec/internal/Gemfile +16 -13
- data/spec/internal/Gemfile.lock +121 -86
- data/spec/internal/app/assets/javascripts/application.js +1 -1
- data/spec/internal/app/assets/stylesheets/application.css +1 -1
- data/spec/internal/bin/rails +1 -5
- data/spec/internal/bin/rake +0 -4
- data/spec/internal/bin/setup +29 -0
- data/spec/internal/config.ru +1 -1
- data/spec/internal/config/application.rb +3 -0
- data/spec/internal/config/boot.rb +1 -2
- data/spec/internal/config/environments/development.rb +4 -0
- data/spec/internal/config/environments/production.rb +14 -18
- data/spec/internal/config/environments/test.rb +5 -2
- data/spec/internal/config/initializers/assets.rb +11 -0
- data/spec/internal/config/initializers/cookies_serializer.rb +1 -1
- data/spec/internal/config/secrets.yml +2 -2
- data/spec/internal/db/development.sqlite3 +0 -0
- data/spec/internal/db/migrate/{20140620210534_create_qa_subject_mesh_terms.qa.rb → 20150311214117_create_qa_subject_mesh_terms.qa.rb} +0 -0
- data/spec/internal/db/migrate/{20140620210535_create_qa_mesh_tree.qa.rb → 20150311214118_create_qa_mesh_tree.qa.rb} +0 -0
- data/spec/internal/db/migrate/{20140620210536_add_term_lower_to_qa_subject_mesh_terms.qa.rb → 20150311214119_add_term_lower_to_qa_subject_mesh_terms.qa.rb} +0 -0
- data/spec/internal/db/schema.rb +3 -3
- data/spec/internal/db/test.sqlite3 +0 -0
- data/spec/internal/lib/generators/test_app_generator.rb +0 -1
- data/spec/internal/log/development.log +498 -207
- data/spec/internal/test/test_helper.rb +0 -3
- data/spec/lib/authorities_getty_spec.rb +71 -0
- data/spec/lib/authorities_loc_spec.rb +98 -65
- data/spec/lib/authorities_loc_subauthorities.rb +81 -0
- data/spec/lib/authorities_local_spec.rb +53 -79
- data/spec/lib/authorities_local_subauthorities_spec.rb +43 -0
- data/spec/lib/authorities_mesh_spec.rb +16 -12
- data/spec/lib/authorities_oclcts_spec.rb +17 -17
- data/spec/lib/authorities_tgnlang_spec.rb +4 -7
- data/spec/lib/mesh_data_parser_spec.rb +13 -13
- data/spec/lib/tasks/mesh.rake_spec.rb +4 -4
- data/spec/models/subject_mesh_term_spec.rb +5 -5
- data/spec/routing/route_spec.rb +34 -0
- data/spec/spec_helper.rb +5 -22
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -1
- metadata +44 -12
- data/lib/qa/authorities/local/subauthority.rb +0 -65
- data/spec/internal/bin/spring +0 -18
@@ -4,9 +4,6 @@ require 'rails/test_help'
|
|
4
4
|
|
5
5
|
class ActiveSupport::TestCase
|
6
6
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
7
|
-
#
|
8
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
-
# -- they do not yet inherit this setting
|
10
7
|
fixtures :all
|
11
8
|
|
12
9
|
# Add more helper methods to be used by all tests here...
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Getty do
|
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
|
22
|
+
|
23
|
+
let(:authority) { described_class.new("aat") }
|
24
|
+
describe "#build_query_url" do
|
25
|
+
subject { authority.build_query_url("foo") }
|
26
|
+
it { is_expected.to match /^http:\/\/vocab\.getty\.edu\// }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#find_url" do
|
30
|
+
subject { authority.find_url("300053264") }
|
31
|
+
it { is_expected.to eq "http://vocab.getty.edu/aat/300053264.json" }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#search" do
|
35
|
+
context "authorities" do
|
36
|
+
before do
|
37
|
+
stub_request(:get, /vocab\.getty\.edu.*/).
|
38
|
+
with(:headers => {'Accept'=>'application/json'}).
|
39
|
+
to_return(:body => webmock_fixture("aat-response.txt"), :status => 200)
|
40
|
+
end
|
41
|
+
|
42
|
+
subject { authority.search('whatever') }
|
43
|
+
|
44
|
+
it "should have id and label keys" do
|
45
|
+
expect(subject.first).to eq("id" => 'http://vocab.getty.edu/aat/300053264', "label" => "photocopying")
|
46
|
+
expect(subject.last).to eq("id" => 'http://vocab.getty.edu/aat/300265560', "label" => "photoscreenprints")
|
47
|
+
expect(subject.size).to eq(10)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#find" do
|
53
|
+
context "using a subject id" do
|
54
|
+
before do
|
55
|
+
stub_request(:get, "http://vocab.getty.edu/aat/300265560.json").
|
56
|
+
with(headers: { 'Accept'=>'application/json' }).
|
57
|
+
to_return(status: 200, body: webmock_fixture("getty-aat-find-response.json"))
|
58
|
+
end
|
59
|
+
subject { described_class.new("aat").find("300265560") }
|
60
|
+
|
61
|
+
it "returns the complete record for a given subject" do
|
62
|
+
expect(subject['results']['bindings'].size).to eq 189
|
63
|
+
expect(subject['results']['bindings']).to all(have_key('Subject'))
|
64
|
+
expect(subject['results']['bindings']).to all(have_key('Predicate'))
|
65
|
+
expect(subject['results']['bindings']).to all(have_key('Object'))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
@@ -2,90 +2,123 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Qa::Authorities::Loc do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe "#new" do
|
6
|
+
context "without a sub-authority" do
|
7
|
+
it "should raise an exception" do
|
8
|
+
expect { Qa::Authorities::Loc.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 { Qa::Authorities::Loc.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(Qa::Authorities::Loc.new("subjects")).to be_kind_of Qa::Authorities::Loc
|
19
|
+
end
|
20
|
+
end
|
11
21
|
end
|
22
|
+
|
23
|
+
describe "urls" do
|
12
24
|
|
13
|
-
|
14
|
-
|
15
|
-
it "should instantiate with a query and return data" do
|
16
|
-
expect(@authority).not_to be_nil
|
17
|
-
@authority.raw_response.to_s.should include("id")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return a sub_authority url" do
|
21
|
-
@authority.should_not be_nil
|
22
|
-
url = @authority.sub_authorityURL("geographicAreas")
|
23
|
-
expect(url).not_to be_nil
|
25
|
+
let :authority do
|
26
|
+
Qa::Authorities::Loc.new("subjects")
|
24
27
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
it "should return JSON" do
|
33
|
-
@authority.should_not be_nil
|
34
|
-
json = @authority.parse_authority_response(@authority.raw_response)
|
35
|
-
expect(json).not_to be_empty
|
28
|
+
|
29
|
+
context "for searching" do
|
30
|
+
it "should return a url" do
|
31
|
+
url = 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json'
|
32
|
+
expect(authority.build_query_url("foo")).to eq(url)
|
33
|
+
end
|
36
34
|
end
|
37
35
|
|
36
|
+
context "for returning single terms" do
|
37
|
+
it "returns a url with an authority and id" do
|
38
|
+
url = "http://id.loc.gov/authorities/subjects/sh2002003586.json"
|
39
|
+
expect(authority.find_url("sh2002003586")).to eq(url)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
38
43
|
end
|
39
44
|
|
40
|
-
describe "
|
45
|
+
describe "#search" do
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
context "any LOC authorities" do
|
48
|
+
let :authority do
|
49
|
+
stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas").
|
50
|
+
with(:headers => {'Accept'=>'application/json'}).
|
51
|
+
to_return(:body => webmock_fixture("loc-response.txt"), :status => 200)
|
52
|
+
Qa::Authorities::Loc.new("geographicAreas")
|
53
|
+
end
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
55
|
+
it "should retain the raw respsonse from the LC service in JSON" do
|
56
|
+
expect(authority.raw_response).to be_nil
|
57
|
+
json = Qa::Authorities::WebServiceBase.new.get_json(authority.build_query_url("s"))
|
58
|
+
authority.search("s")
|
59
|
+
expect(authority.raw_response).to eq(json)
|
60
|
+
end
|
52
61
|
|
53
|
-
|
62
|
+
describe "the returned results" do
|
54
63
|
|
55
|
-
|
64
|
+
let :results do
|
65
|
+
authority.search("s")
|
66
|
+
end
|
56
67
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
68
|
+
it "should have :id and :label elements" do
|
69
|
+
expect(results.first["label"]).to eq("West (U.S.)")
|
70
|
+
expect(results.first["id"]).to eq("info:lc/vocabulary/geographicAreas/n-usp")
|
71
|
+
expect(results.last["label"]).to eq("Baltic States")
|
72
|
+
expect(results.last["id"]).to eq("info:lc/vocabulary/geographicAreas/eb")
|
73
|
+
expect(results.size).to eq(20)
|
74
|
+
end
|
62
75
|
|
63
|
-
|
64
|
-
@authority.search("Berry", "names")
|
65
|
-
@authority.results.first["label"].should == "Berry, James W. (James William), 1938-"
|
76
|
+
end
|
66
77
|
end
|
67
|
-
|
68
|
-
end
|
69
78
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
context "subject terms" do
|
80
|
+
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
|
+
with(:headers => {'Accept'=>'application/json'}).
|
83
|
+
to_return(:body => webmock_fixture("loc-subjects-response.txt"), :status => 200)
|
84
|
+
Qa::Authorities::Loc.new("subjects").search("History--")
|
85
|
+
end
|
86
|
+
it "should have a URI for the id and a string label" do
|
87
|
+
expect(results.count).to eq(20)
|
88
|
+
expect(results.first["label"]).to eq("History--Philosophy--History--20th century")
|
89
|
+
expect(results.first["id"]).to eq("info:lc/authorities/subjects/sh2008121753")
|
90
|
+
expect(results[1]["label"]).to eq("History--Philosophy--History--19th century")
|
91
|
+
expect(results[1]["id"]).to eq("info:lc/authorities/subjects/sh2008121752")
|
92
|
+
end
|
76
93
|
end
|
77
94
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
95
|
+
context "name terms" do
|
96
|
+
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
|
+
with(:headers => {'Accept'=>'application/json'}).
|
99
|
+
to_return(:body => webmock_fixture("loc-names-response.txt"), :status => 200)
|
100
|
+
Qa::Authorities::Loc.new("names").search("Berry")
|
101
|
+
end
|
102
|
+
it "should retrieve names via search" do
|
103
|
+
expect(results.first["label"]).to eq("Berry, James W. (James William), 1938-")
|
104
|
+
end
|
82
105
|
end
|
83
106
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#find" do
|
110
|
+
context "using a subject id" do
|
111
|
+
let :results do
|
112
|
+
stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json").
|
113
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
|
114
|
+
to_return(:status => 200, :body => webmock_fixture("loc-subject-find-response.txt"), :headers => {})
|
115
|
+
Qa::Authorities::Loc.new("subjects").find("sh2002003586")
|
116
|
+
end
|
117
|
+
it "returns the complete record for a given subject" do
|
118
|
+
expect(results.count).to eq(20)
|
119
|
+
expect(results.first).to be_kind_of(Hash)
|
120
|
+
end
|
89
121
|
end
|
90
122
|
end
|
123
|
+
|
91
124
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::LocSubauthority do
|
4
|
+
|
5
|
+
let(:subject) do
|
6
|
+
class TestAuthority
|
7
|
+
include Qa::Authorities::LocSubauthority
|
8
|
+
end
|
9
|
+
TestAuthority.new
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with a valid subauthority" do
|
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])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with a non-existent subauthority" do
|
21
|
+
it "should return nil" do
|
22
|
+
expect(subject.get_url_for_authority("fake")).to be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# This is the original data structure that was used to define subauthority urls
|
27
|
+
# It is retained here to ensure our refactor succeeded
|
28
|
+
def sub_authority_table
|
29
|
+
begin
|
30
|
+
vocab_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F'
|
31
|
+
authority_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F'
|
32
|
+
datatype_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F'
|
33
|
+
vocab_preservation_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F'
|
34
|
+
{
|
35
|
+
'subjects' => authority_base_url,
|
36
|
+
'names' => authority_base_url,
|
37
|
+
'classification' => authority_base_url,
|
38
|
+
'childrensSubjects' => authority_base_url,
|
39
|
+
'genreForms' => authority_base_url,
|
40
|
+
'performanceMediums' => authority_base_url,
|
41
|
+
'graphicMaterials' => vocab_base_url,
|
42
|
+
'organizations' => vocab_base_url,
|
43
|
+
'relators' => vocab_base_url,
|
44
|
+
'countries' => vocab_base_url,
|
45
|
+
'ethnographicTerms' => vocab_base_url,
|
46
|
+
'geographicAreas' => vocab_base_url,
|
47
|
+
'languages' => vocab_base_url,
|
48
|
+
'iso639-1' => vocab_base_url,
|
49
|
+
'iso639-2' => vocab_base_url,
|
50
|
+
'iso639-5' => vocab_base_url,
|
51
|
+
'edtf' => datatype_base_url,
|
52
|
+
'preservation' => vocab_base_url,
|
53
|
+
'actionsGranted' => vocab_base_url,
|
54
|
+
'agentType' => vocab_base_url,
|
55
|
+
'contentLocationType' => vocab_preservation_base_url,
|
56
|
+
'copyrightStatus' => vocab_preservation_base_url,
|
57
|
+
'cryptographicHashFunctions' => vocab_preservation_base_url,
|
58
|
+
'environmentCharacteristic' => vocab_preservation_base_url,
|
59
|
+
'environmentPurpose' => vocab_preservation_base_url,
|
60
|
+
'eventRelatedAgentRole' => vocab_preservation_base_url,
|
61
|
+
'eventRelatedObjectRole' => vocab_preservation_base_url,
|
62
|
+
'eventType' => vocab_preservation_base_url,
|
63
|
+
'formatRegistryRole' => vocab_preservation_base_url,
|
64
|
+
'hardwareType' => vocab_preservation_base_url,
|
65
|
+
'inhibitorTarget' => vocab_preservation_base_url,
|
66
|
+
'inhibitorType' => vocab_preservation_base_url,
|
67
|
+
'objectCategory' => vocab_preservation_base_url,
|
68
|
+
'preservationLevelRole' => vocab_preservation_base_url,
|
69
|
+
'relationshipSubType' => vocab_preservation_base_url,
|
70
|
+
'relationshipType' => vocab_preservation_base_url,
|
71
|
+
'rightsBasis' => vocab_preservation_base_url,
|
72
|
+
'rightsRelatedAgentRole' => vocab_preservation_base_url,
|
73
|
+
'signatureEncoding' => vocab_preservation_base_url,
|
74
|
+
'signatureMethod' => vocab_preservation_base_url,
|
75
|
+
'softwareType' => vocab_preservation_base_url,
|
76
|
+
'storageMedium' => vocab_preservation_base_url
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -2,136 +2,110 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Qa::Authorities::Local do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
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") }
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
it "should
|
14
|
-
expect {
|
15
|
-
|
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
|
16
17
|
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should return a sub_authority" do
|
20
|
-
expect { subject.sub_authority('authority_Z')}.to raise_error ArgumentError, "Invalid sub-authority 'authority_Z'"
|
21
|
-
expect(subject.sub_authority('authority_A')).to be_kind_of Qa::Authorities::Subauthority
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
25
|
-
|
21
|
+
describe "#all" do
|
26
22
|
let(:expected) { [ { 'id'=> "A1", 'label' => "Abc Term A1" },
|
27
23
|
{ 'id' => "A2", 'label'=> "Term A2" },
|
28
24
|
{ 'id' => "A3", 'label' => "Abc Term A3" } ] }
|
29
25
|
it "should return all the entries" do
|
30
|
-
|
31
|
-
expect(authorities.search("", "authority_A")).to eq(expected)
|
26
|
+
expect(authority_a.all).to eq(expected)
|
32
27
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
context "when terms do not have ids" do
|
29
|
+
let(:expected) { [ { 'id' => "Term B1", 'label' => "Term B1" },
|
30
|
+
{ 'id' => "Term B2", 'label' => "Term B2" },
|
31
|
+
{ 'id' => "Term B3", 'label' => "Term B3" } ] }
|
32
|
+
it "should set the id to be same as the label" do
|
33
|
+
expect(authority_b.all).to eq(expected)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
context "authority YAML file is a list of terms" do
|
37
|
+
let(:expected) { [ { 'id' => "Term C1", 'label' => "Term C1" },
|
38
|
+
{ 'id' => "Term C2", 'label' => "Term C2" },
|
39
|
+
{ 'id' => "Term C3", 'label' => "Term C3" } ] }
|
40
|
+
it "should use the terms as labels" do
|
41
|
+
expect(authority_c.all).to eq(expected)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context "YAML file is malformed" do
|
45
|
+
it "should raise an error" do
|
46
|
+
expect { authority_d.all }.to raise_error
|
47
|
+
end
|
39
48
|
end
|
40
49
|
end
|
41
|
-
|
42
|
-
context "retrieve a subset of entries for a local sub_authority" do
|
43
50
|
|
44
|
-
|
51
|
+
describe "#search" do
|
52
|
+
context "with an empty query string" do
|
53
|
+
let(:expected) { [] }
|
54
|
+
it "should return no results" do
|
55
|
+
expect(authority_a.search("")).to eq(expected)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context "with at least one matching entry" do
|
45
59
|
let(:expected) { [ { 'id' => "A1", 'label' => "Abc Term A1" },
|
46
60
|
{ 'id' => "A3", 'label' => "Abc Term A3" } ] }
|
47
61
|
it "should return only entries matching the query term" do
|
48
|
-
|
49
|
-
expect(authorities.search("Abc", "authority_A")).to eq(expected)
|
62
|
+
expect(authority_a.search("Abc")).to eq(expected)
|
50
63
|
end
|
51
|
-
|
52
64
|
it "should match parts of words in the middle of the term" do
|
53
|
-
|
54
|
-
|
65
|
+
expect(authority_a.search("Term A1")).to eq([{"id"=>"A1", "label"=>"Abc Term A1"}])
|
66
|
+
end
|
67
|
+
it "should be case insensitive" do
|
68
|
+
expect(authority_a.search("aBc")).to eq(expected)
|
55
69
|
end
|
56
70
|
end
|
57
|
-
|
58
|
-
context "no matching entries" do
|
71
|
+
context "with no matching entries" do
|
59
72
|
let(:expected) { [] }
|
60
73
|
it "should return an empty array" do
|
61
|
-
|
62
|
-
expect(authorities.search("def", "authority_A")).to eq(expected)
|
74
|
+
expect(authority_a.search("def")).to eq(expected)
|
63
75
|
end
|
64
76
|
end
|
65
|
-
|
66
|
-
context "search not case-sensitive" do
|
67
|
-
let(:expected) { [ { 'id' => "A1", 'label' => "Abc Term A1" },
|
68
|
-
{ 'id' => "A3", 'label' => "Abc Term A3" } ] }
|
69
|
-
it "should return entries matching the query term without regard to case" do
|
70
|
-
authorities = Qa::Authorities::Local.new
|
71
|
-
expect(authorities.search("aBc", "authority_A")).to eq(expected)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
77
|
end
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
let(:authorities) { Qa::Authorities::Local.new }
|
80
|
-
|
79
|
+
describe "#find" do
|
81
80
|
context "source is a hash" do
|
82
81
|
let(:id) { "A2" }
|
83
82
|
let(:expected) { { 'id' => "A2", 'term' => "Term A2", 'active' => false } }
|
84
83
|
it "should return the full term record" do
|
85
|
-
record =
|
84
|
+
record = authority_a.find(id)
|
86
85
|
expect(record).to be_a HashWithIndifferentAccess
|
87
86
|
expect(record).to eq(expected)
|
88
87
|
end
|
89
88
|
end
|
90
89
|
context "source is a list" do
|
91
90
|
it "should be indifferent access" do
|
92
|
-
record =
|
91
|
+
record = authority_c.find("Term C1")
|
93
92
|
expect(record).to be_a HashWithIndifferentAccess
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
97
95
|
context "term does not exist" do
|
98
96
|
let(:id) { "NonID" }
|
99
97
|
let(:expected) { {} }
|
100
98
|
it "should return an empty hash" do
|
101
|
-
expect(
|
99
|
+
expect(authority_a.find(id)).to eq(expected)
|
102
100
|
end
|
103
101
|
end
|
104
|
-
|
105
102
|
context "on a sub-authority" do
|
106
103
|
it "should return the full term record" do
|
107
|
-
record =
|
104
|
+
record = authority_a.find("A2")
|
108
105
|
expect(record).to be_a HashWithIndifferentAccess
|
109
106
|
expect(record).to eq('id' => "A2", 'term' => "Term A2", 'active' => false)
|
110
107
|
end
|
111
108
|
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
context "term does not an id" do
|
116
|
-
let(:authorities) { Qa::Authorities::Local.new }
|
117
|
-
let(:expected) { [ { 'id' => "Term B1", 'label' => "Term B1" },
|
118
|
-
{ 'id' => "Term B2", 'label' => "Term B2" },
|
119
|
-
{ 'id' => "Term B3", 'label' => "Term B3" } ] }
|
120
|
-
it "should set the id to be same as the label" do
|
121
|
-
expect(authorities.search("", "authority_B")).to eq(expected)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "authority YAML is a list of terms" do
|
126
|
-
let(:authorities) { Qa::Authorities::Local.new }
|
127
|
-
let(:expected) { [ { 'id' => "Term C1", 'label' => "Term C1" },
|
128
|
-
{ 'id' => "Term C2", 'label' => "Term C2" },
|
129
|
-
{ 'id' => "Term C3", 'label' => "Term C3" } ] }
|
130
|
-
|
131
|
-
it "should use the terms as labels" do
|
132
|
-
expect(authorities.search("", "authority_C")).to eq(expected)
|
133
|
-
end
|
134
|
-
|
135
109
|
end
|
136
110
|
|
137
111
|
end
|