qa 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -8,13 +8,13 @@ module Qa::Authorities
|
|
8
8
|
def search(q)
|
9
9
|
r = q.blank? ? [] : terms.select { |term| /\b#{q.downcase}/.match(term[:term].downcase) }
|
10
10
|
r.map do |res|
|
11
|
-
{ :
|
11
|
+
{ id: res[:id], label: res[:term] }.with_indifferent_access
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def all
|
16
16
|
terms.map do |res|
|
17
|
-
{ :
|
17
|
+
{ id: res[:id], label: res[:term] }.with_indifferent_access
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -24,26 +24,25 @@ module Qa::Authorities
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
def terms
|
28
|
+
subauthority_hash = YAML.load(File.read(subauthority_filename))
|
29
|
+
terms = subauthority_hash.with_indifferent_access.fetch(:terms, [])
|
30
|
+
normalize_terms(terms)
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def subauthority_filename
|
34
|
+
File.join(Local.subauthorities_path, "#{subauthority}.yml")
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
def normalize_terms(terms)
|
38
|
+
terms.map do |term|
|
39
|
+
if term.is_a? String
|
40
|
+
{ id: term, term: term }.with_indifferent_access
|
41
|
+
else
|
42
|
+
term[:id] ||= term[:term]
|
43
|
+
term
|
44
|
+
end
|
44
45
|
end
|
45
46
|
end
|
46
|
-
end
|
47
|
-
|
48
47
|
end
|
49
48
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module Qa
|
2
2
|
module Authorities
|
3
3
|
module Local
|
4
|
-
#
|
5
4
|
class MysqlTableBasedAuthority < Local::TableBasedAuthority
|
5
|
+
self.table_index = "index_qa_local_authority_entries_on_lower_label_and_authority"
|
6
|
+
|
6
7
|
def self.check_for_index
|
7
8
|
conn = ActiveRecord::Base.connection
|
8
|
-
if table_or_view_exists? && conn.index_name_exists?(
|
9
|
-
Rails.logger.error "You've installed mysql local authority tables, but you haven't indexed the lower label.
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
if table_or_view_exists? && conn.index_name_exists?(table_name.to_sym, table_index, :default).blank?
|
10
|
+
Rails.logger.error "You've installed mysql local authority tables, but you haven't indexed the lower label. "
|
11
|
+
"Rails doesn't support functional indexes in migrations, so we tried to execute it for you but something went wrong...\n" \
|
12
|
+
"Make sure your table has a lower_label column, which is virtually created, and that the column is indexed." \
|
13
|
+
" ALTER TABLE #{table_name} ADD lower_label VARCHAR(256) GENERATED ALWAYS AS (lower(label)) VIRTUAL" \
|
14
|
+
" CREATE INDEX #{table_index} ON #{table_name} (local_authority_id, lower_label)"
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
@@ -20,12 +20,12 @@ module Qa::Authorities
|
|
20
20
|
|
21
21
|
def self.logger
|
22
22
|
@logger ||= begin
|
23
|
-
::Rails.logger if defined? Rails
|
23
|
+
::Rails.logger if defined? Rails && Rails.respond_to?(:logger)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
class << self
|
28
|
+
attr_writer :logger
|
29
29
|
end
|
30
30
|
|
31
31
|
def add(subauthority, class_name)
|
@@ -33,10 +33,10 @@ module Qa::Authorities
|
|
33
33
|
@hash[subauthority] = RegistryEntry.new(subauthority, class_name)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
class RegistryEntry
|
38
37
|
def initialize(subauthority, class_name)
|
39
|
-
@subauthority
|
38
|
+
@subauthority = subauthority
|
39
|
+
@class_name = class_name
|
40
40
|
end
|
41
41
|
|
42
42
|
def klass
|
@@ -1,16 +1,33 @@
|
|
1
1
|
module Qa::Authorities
|
2
2
|
class Local::TableBasedAuthority < Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
class_attribute :table_name, :table_index
|
4
|
+
self.table_name = "qa_local_authority_entries"
|
5
|
+
self.table_index = "index_qa_local_authority_entries_on_lower_label"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def check_for_index
|
9
|
+
@checked_for_index ||= begin
|
10
|
+
conn = ActiveRecord::Base.connection
|
11
|
+
if table_or_view_exists? && !conn.indexes(table_name).find { |i| i.name == table_index }
|
12
|
+
Rails.logger.error "You've installed local authority tables, but you haven't indexed the label. Rails doesn't support functional indexes in migrations, so you'll have to add this manually:\n" \
|
13
|
+
"CREATE INDEX \"#{table_index}\" ON \"#{table_name}\" (local_authority_id, lower(label))\n" \
|
14
|
+
" OR on Sqlite: \n" \
|
15
|
+
"CREATE INDEX \"#{table_index}\" ON \"#{table_name}\" (local_authority_id, label collate nocase)\n" \
|
16
|
+
" OR for MySQL use the MSQLTableBasedAuthority instead, since mysql does not support functional indexes."
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def table_or_view_exists?
|
24
|
+
conn = ActiveRecord::Base.connection
|
25
|
+
if conn.respond_to?(:data_source_exists?)
|
26
|
+
conn.data_source_exists?(table_name)
|
27
|
+
else
|
28
|
+
conn.table_exists?(table_name)
|
29
|
+
end
|
30
|
+
end
|
14
31
|
end
|
15
32
|
|
16
33
|
attr_reader :subauthority
|
@@ -37,15 +54,6 @@ module Qa::Authorities
|
|
37
54
|
|
38
55
|
private
|
39
56
|
|
40
|
-
def self.table_or_view_exists?
|
41
|
-
conn = ActiveRecord::Base.connection
|
42
|
-
if conn.respond_to?(:data_source_exists?)
|
43
|
-
conn.data_source_exists?('qa_local_authority_entries')
|
44
|
-
else
|
45
|
-
conn.table_exists?('qa_local_authority_entries')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
57
|
def base_relation
|
50
58
|
Qa::LocalAuthorityEntry.where(local_authority: local_authority)
|
51
59
|
end
|
@@ -61,6 +69,5 @@ module Qa::Authorities
|
|
61
69
|
def local_authority
|
62
70
|
Qa::LocalAuthority.find_by_name(subauthority)
|
63
71
|
end
|
64
|
-
|
65
72
|
end
|
66
73
|
end
|
data/lib/qa/authorities/mesh.rb
CHANGED
@@ -1,26 +1,18 @@
|
|
1
1
|
module Qa::Authorities
|
2
2
|
class Mesh < Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
r = Qa::SubjectMeshTerm.where('term_lower LIKE ?', "#{q}%").limit(10)
|
7
|
-
r.map { |t| {id: t.term_id, label: t.term} }
|
8
|
-
end
|
3
|
+
def search(q)
|
4
|
+
r = Qa::SubjectMeshTerm.where('term_lower LIKE ?', "#{q}%").limit(10)
|
5
|
+
r.map { |t| { id: t.term_id, label: t.term } }
|
9
6
|
end
|
10
7
|
|
11
|
-
def find
|
12
|
-
|
13
|
-
|
14
|
-
r.nil? ? nil : {id: r.term_id, label: r.term, synonyms: r.synonyms}
|
15
|
-
end
|
8
|
+
def find(id)
|
9
|
+
r = Qa::SubjectMeshTerm.where(term_id: id).limit(1).first
|
10
|
+
r.nil? ? nil : { id: r.term_id, label: r.term, synonyms: r.synonyms }
|
16
11
|
end
|
17
12
|
|
18
13
|
def all
|
19
|
-
|
20
|
-
|
21
|
-
r.map { |t| {id: t.term_id, label: t.term} }
|
22
|
-
end
|
14
|
+
r = Qa::SubjectMeshTerm.all
|
15
|
+
r.map { |t| { id: t.term_id, label: t.term } }
|
23
16
|
end
|
24
|
-
|
25
17
|
end
|
26
18
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Qa::Authorities::MeshTools
|
2
|
+
extend ActiveSupport::Autoload
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
autoload :MeshDataParser
|
5
|
+
autoload :MeshImporter
|
6
|
+
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module Qa::Authorities
|
2
2
|
module MeshTools
|
3
3
|
class MeshDataParser
|
4
|
-
|
5
4
|
attr_accessor :file
|
6
5
|
|
7
6
|
def initialize(file)
|
8
7
|
@file = file
|
9
8
|
end
|
10
9
|
|
11
|
-
def each_mesh_record
|
10
|
+
def each_mesh_record
|
12
11
|
current_data = {}
|
13
12
|
in_record = false
|
14
|
-
|
13
|
+
file.each_line do |line|
|
15
14
|
case line
|
16
15
|
when /\A\*NEWRECORD/
|
17
16
|
yield(current_data) if in_record
|
@@ -31,10 +30,9 @@ module Qa::Authorities
|
|
31
30
|
|
32
31
|
def all_records
|
33
32
|
result = []
|
34
|
-
|
35
|
-
|
33
|
+
each_mesh_record { |rec| result << rec }
|
34
|
+
result
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -12,11 +12,10 @@ module Qa::Authorities
|
|
12
12
|
entry << record['MH'].first.downcase
|
13
13
|
entry << get_synonyms(record).join('|')
|
14
14
|
entries << entry
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
next if record['MN'].nil?
|
16
|
+
trees += record['MN'].map do |tree_number|
|
17
|
+
[record['UI'].first,
|
18
|
+
tree_number]
|
20
19
|
end
|
21
20
|
end
|
22
21
|
Qa::SubjectMeshTerm.import([:term_id, :term, :term_lower, :synonyms], entries)
|
@@ -25,15 +24,14 @@ module Qa::Authorities
|
|
25
24
|
|
26
25
|
private
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def first_terms(record, field)
|
33
|
-
return [] if record[field].nil?
|
34
|
-
record[field].map { |s| s.split('|').first }
|
35
|
-
end
|
27
|
+
def get_synonyms(record)
|
28
|
+
first_terms(record, 'PRINT ENTRY') + first_terms(record, 'ENTRY')
|
29
|
+
end
|
36
30
|
|
31
|
+
def first_terms(record, field)
|
32
|
+
return [] if record[field].nil?
|
33
|
+
record[field].map { |s| s.split('|').first }
|
34
|
+
end
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -7,36 +7,36 @@ module Qa::Authorities
|
|
7
7
|
end
|
8
8
|
include WebServiceBase
|
9
9
|
|
10
|
-
def search
|
10
|
+
def search(q)
|
11
11
|
get_raw_response("prefix-query", q)
|
12
|
-
r =
|
12
|
+
r = []
|
13
13
|
raw_response.xpath('sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData', 'sru' => 'http://www.loc.gov/zing/srw/').each do |record|
|
14
|
-
r.append(
|
14
|
+
r.append("id" => record.xpath('Zthes/term/termId').first.content, "label" => record.xpath('Zthes/term/termName').first.content)
|
15
15
|
end
|
16
16
|
r
|
17
17
|
end
|
18
18
|
|
19
|
-
def find
|
19
|
+
def find(id)
|
20
20
|
get_raw_response("id-lookup", id)
|
21
21
|
parse_full_record(id)
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def parse_full_record(id)
|
27
|
+
a = {}
|
28
|
+
zthes_record = raw_response.xpath("sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/Zthes/term[termId='#{id}']", 'sru' => 'http://www.loc.gov/zing/srw/')
|
29
|
+
zthes_record.children.each do |child|
|
30
|
+
if (child.is_a? Nokogiri::XML::Element) && !child.children.nil? && (child.children.size == 1) && (child.children.first.is_a? Nokogiri::XML::Text)
|
31
|
+
a[child.name] = child.children.first.to_s
|
32
|
+
end
|
32
33
|
end
|
34
|
+
a
|
33
35
|
end
|
34
|
-
a
|
35
|
-
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def get_raw_response(query_type, id)
|
38
|
+
query_url = Oclcts.url_pattern(query_type).gsub("{query}", id).gsub("{id}", id).gsub("{authority-id}", subauthority)
|
39
|
+
@raw_response = Nokogiri::XML(open(query_url))
|
40
|
+
end
|
41
41
|
end
|
42
42
|
end
|
@@ -2,17 +2,14 @@ require 'nokogiri'
|
|
2
2
|
|
3
3
|
module Qa::Authorities
|
4
4
|
class Tgnlang < Base
|
5
|
-
|
6
5
|
def search(q)
|
7
|
-
|
6
|
+
get_tgnlang(q)
|
8
7
|
end
|
9
8
|
|
10
|
-
def
|
11
|
-
obj =
|
9
|
+
def get_tgnlang(q)
|
10
|
+
obj = []
|
12
11
|
Tgnlang.languages.each do |h|
|
13
|
-
if h["label"].downcase.start_with?(q.downcase)
|
14
|
-
obj.push(h)
|
15
|
-
end
|
12
|
+
obj.push(h) if h["label"].downcase.start_with?(q.downcase)
|
16
13
|
end
|
17
14
|
obj
|
18
15
|
end
|
@@ -27,7 +24,7 @@ module Qa::Authorities
|
|
27
24
|
lang_array = doc.css("Language").map do |lang|
|
28
25
|
id = lang.css("Language_Code").first.text
|
29
26
|
label = lang.css("Language_Name").first.text
|
30
|
-
{"id" => id, "label" => label}
|
27
|
+
{ "id" => id, "label" => label }
|
31
28
|
end
|
32
29
|
end
|
33
30
|
lang_array
|
@@ -37,11 +34,9 @@ module Qa::Authorities
|
|
37
34
|
def find(id)
|
38
35
|
id = id.downcase
|
39
36
|
Tgnlang.languages.each do |h|
|
40
|
-
if h["label"].downcase == id
|
41
|
-
return h
|
42
|
-
end
|
37
|
+
return h if h["label"].downcase == id
|
43
38
|
end
|
44
|
-
|
39
|
+
{}
|
45
40
|
end
|
46
41
|
end
|
47
42
|
end
|
data/lib/qa/version.rb
CHANGED
@@ -1,143 +1,133 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Qa::TermsController, :
|
4
|
-
|
3
|
+
describe Qa::TermsController, type: :controller do
|
5
4
|
before do
|
6
5
|
@routes = Qa::Engine.routes
|
7
6
|
end
|
8
7
|
|
9
8
|
describe "#check_vocab_param" do
|
10
|
-
it "
|
11
|
-
get :search,
|
9
|
+
it "returns 404 if the vocabulary is missing" do
|
10
|
+
get :search, q: "a query", vocab: ""
|
12
11
|
expect(response.code).to eq("404")
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
15
|
describe "#check_query_param" do
|
17
|
-
it "
|
18
|
-
get :search,
|
16
|
+
it "returns 404 if the query is missing" do
|
17
|
+
get :search, q: "", vocab: "tgnlang"
|
19
18
|
expect(response.code).to eq("404")
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
22
|
describe "#init_authority" do
|
24
23
|
context "when the authority does not exist" do
|
25
|
-
it "
|
24
|
+
it "returns 404" do
|
26
25
|
expect(Rails.logger).to receive(:warn).with("Unable to initialize authority Qa::Authorities::Non-existent-authority")
|
27
|
-
get :search,
|
26
|
+
get :search, q: "a query", vocab: "non-existent-authority"
|
28
27
|
expect(response.code).to eq("404")
|
29
28
|
end
|
30
29
|
end
|
31
30
|
context "when a sub-authority does not exist" do
|
32
|
-
it "
|
31
|
+
it "returns 404 if a sub-authority does not exist" do
|
33
32
|
expect(Rails.logger).to receive(:warn).with("Unable to initialize sub-authority non-existent-subauthority for Qa::Authorities::Loc. Valid sub-authorities are [\"subjects\", \"names\", \"classification\", \"childrensSubjects\", \"genreForms\", \"performanceMediums\", \"graphicMaterials\", \"organizations\", \"relators\", \"countries\", \"ethnographicTerms\", \"geographicAreas\", \"languages\", \"iso639-1\", \"iso639-2\", \"iso639-5\", \"preservation\", \"actionsGranted\", \"agentType\", \"edtf\", \"contentLocationType\", \"copyrightStatus\", \"cryptographicHashFunctions\", \"environmentCharacteristic\", \"environmentPurpose\", \"eventRelatedAgentRole\", \"eventRelatedObjectRole\", \"eventType\", \"formatRegistryRole\", \"hardwareType\", \"inhibitorTarget\", \"inhibitorType\", \"objectCategory\", \"preservationLevelRole\", \"relationshipSubType\", \"relationshipType\", \"rightsBasis\", \"rightsRelatedAgentRole\", \"signatureEncoding\", \"signatureMethod\", \"softwareType\", \"storageMedium\"]")
|
34
|
-
get :search,
|
33
|
+
get :search, q: "a query", vocab: "loc", subauthority: "non-existent-subauthority"
|
35
34
|
expect(response.code).to eq("404")
|
36
35
|
end
|
37
36
|
end
|
38
37
|
context "when a sub-authority is absent" do
|
39
|
-
it "
|
40
|
-
get :search,
|
38
|
+
it "returns 404 for LOC" do
|
39
|
+
get :search, q: "a query", vocab: "loc"
|
41
40
|
expect(response.code).to eq("404")
|
42
41
|
end
|
43
|
-
it "
|
44
|
-
get :search,
|
42
|
+
it "returns 404 for oclcts" do
|
43
|
+
get :search, q: "a query", vocab: "oclcts"
|
45
44
|
expect(response.code).to eq("404")
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
49
|
describe "#search" do
|
51
|
-
|
52
50
|
context "loc" do
|
53
|
-
before
|
54
|
-
stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
|
55
|
-
with(:
|
56
|
-
to_return(:
|
51
|
+
before do
|
52
|
+
stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
|
53
|
+
.with(headers: { 'Accept' => 'application/json' })
|
54
|
+
.to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
|
57
55
|
end
|
58
56
|
|
59
|
-
it "
|
60
|
-
get :search,
|
57
|
+
it "returns a set of terms for a tgnlang query" do
|
58
|
+
get :search, q: "Tibetan", vocab: "tgnlang"
|
61
59
|
expect(response).to be_success
|
62
60
|
end
|
63
61
|
|
64
|
-
it "
|
65
|
-
get :search,
|
62
|
+
it "does not return 404 if subauthority is valid" do
|
63
|
+
get :search, q: "Berry", vocab: "loc", subauthority: "names"
|
66
64
|
expect(response).to be_success
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
70
68
|
context "assign_fast" do
|
71
69
|
before do
|
72
|
-
stub_request(:get, "http://fast.oclc.org/searchfast/fastsuggest?query=word&queryIndex=suggest50&queryReturn=suggest50,idroot,auth,type&rows=20&suggest=autoSubject")
|
73
|
-
with(:
|
74
|
-
to_return(:
|
70
|
+
stub_request(:get, "http://fast.oclc.org/searchfast/fastsuggest?query=word&queryIndex=suggest50&queryReturn=suggest50,idroot,auth,type&rows=20&suggest=autoSubject")
|
71
|
+
.with(headers: { 'Accept' => 'application/json' })
|
72
|
+
.to_return(body: webmock_fixture("assign-fast-topical-result.json"), status: 200, headers: {})
|
75
73
|
end
|
76
74
|
it "succeeds if authority class is camelcase" do
|
77
|
-
get :search,
|
75
|
+
get :search, q: "word", vocab: "assign_fast", subauthority: "topical"
|
78
76
|
expect(response).to be_success
|
79
77
|
end
|
80
78
|
end
|
81
|
-
|
82
79
|
end
|
83
80
|
|
84
81
|
describe "#index" do
|
85
|
-
|
86
82
|
context "with supported authorities" do
|
87
|
-
it "
|
88
|
-
get :index,
|
83
|
+
it "returns all local authority state terms" do
|
84
|
+
get :index, vocab: "local", subauthority: "states"
|
89
85
|
expect(response).to be_success
|
90
86
|
end
|
91
|
-
it "
|
92
|
-
get :index,
|
87
|
+
it "returns all MeSH terms" do
|
88
|
+
get :index, vocab: "mesh"
|
93
89
|
expect(response).to be_success
|
94
90
|
end
|
95
91
|
end
|
96
92
|
|
97
93
|
context "when the authority does not support #all" do
|
98
|
-
it "
|
99
|
-
get :index,
|
94
|
+
it "returns null for tgnlang" do
|
95
|
+
get :index, vocab: "tgnlang"
|
100
96
|
expect(response.body).to eq("null")
|
101
97
|
end
|
102
|
-
it "
|
103
|
-
get :index,
|
98
|
+
it "returns null for oclcts" do
|
99
|
+
get :index, vocab: "oclcts", subauthority: "mesh"
|
104
100
|
expect(response.body).to eq("null")
|
105
101
|
end
|
106
|
-
it "
|
107
|
-
get :index,
|
102
|
+
it "returns null for LOC authorities" do
|
103
|
+
get :index, vocab: "loc", subauthority: "relators"
|
108
104
|
expect(response.body).to eq("null")
|
109
105
|
end
|
110
106
|
end
|
111
|
-
|
112
107
|
end
|
113
108
|
|
114
109
|
describe "#show" do
|
115
|
-
|
116
110
|
context "with supported authorities" do
|
117
|
-
|
118
111
|
before do
|
119
|
-
stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json")
|
120
|
-
with(:
|
121
|
-
to_return(:
|
112
|
+
stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json")
|
113
|
+
.with(headers: { 'Accept' => 'application/json' })
|
114
|
+
.to_return(status: 200, body: webmock_fixture("loc-names-response.txt"), headers: {})
|
122
115
|
end
|
123
116
|
|
124
|
-
it "
|
125
|
-
get :show,
|
117
|
+
it "returns an individual state term" do
|
118
|
+
get :show, vocab: "local", subauthority: "states", id: "OH"
|
126
119
|
expect(response).to be_success
|
127
120
|
end
|
128
121
|
|
129
|
-
it "
|
130
|
-
get :show,
|
122
|
+
it "returns an individual MeSH term" do
|
123
|
+
get :show, vocab: "mesh", id: "D000001"
|
131
124
|
expect(response).to be_success
|
132
125
|
end
|
133
126
|
|
134
|
-
it "
|
135
|
-
get :show,
|
127
|
+
it "returns an individual subject term" do
|
128
|
+
get :show, vocab: "loc", subauthority: "subjects", id: "sh85077565"
|
136
129
|
expect(response).to be_success
|
137
130
|
end
|
138
|
-
|
139
131
|
end
|
140
|
-
|
141
132
|
end
|
142
|
-
|
143
133
|
end
|