qa 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -21
  3. data/Rakefile +1 -1
  4. data/app/controllers/qa/terms_controller.rb +22 -53
  5. data/config/routes.rb +4 -7
  6. data/lib/qa/authorities.rb +3 -1
  7. data/lib/qa/authorities/base.rb +27 -8
  8. data/lib/qa/authorities/getty.rb +56 -0
  9. data/lib/qa/authorities/loc.rb +27 -131
  10. data/lib/qa/authorities/loc_subauthority.rb +90 -0
  11. data/lib/qa/authorities/local.rb +38 -21
  12. data/lib/qa/authorities/local_subauthority.rb +18 -0
  13. data/lib/qa/authorities/mesh.rb +16 -23
  14. data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +0 -25
  15. data/lib/qa/authorities/mesh_tools/mesh_importer.rb +0 -2
  16. data/lib/qa/authorities/oclcts.rb +17 -24
  17. data/lib/qa/authorities/tgnlang.rb +4 -18
  18. data/lib/qa/authorities/web_service_base.rb +3 -10
  19. data/lib/qa/version.rb +1 -1
  20. data/spec/controllers/terms_controller_spec.rb +93 -44
  21. data/spec/fixtures/aat-response.txt +108 -0
  22. data/spec/fixtures/getty-aat-find-response.json +2494 -0
  23. data/spec/fixtures/loc-response.txt +1521 -17
  24. data/spec/fixtures/loc-subject-find-response.txt +24 -0
  25. data/spec/internal/Gemfile +16 -13
  26. data/spec/internal/Gemfile.lock +121 -86
  27. data/spec/internal/app/assets/javascripts/application.js +1 -1
  28. data/spec/internal/app/assets/stylesheets/application.css +1 -1
  29. data/spec/internal/bin/rails +1 -5
  30. data/spec/internal/bin/rake +0 -4
  31. data/spec/internal/bin/setup +29 -0
  32. data/spec/internal/config.ru +1 -1
  33. data/spec/internal/config/application.rb +3 -0
  34. data/spec/internal/config/boot.rb +1 -2
  35. data/spec/internal/config/environments/development.rb +4 -0
  36. data/spec/internal/config/environments/production.rb +14 -18
  37. data/spec/internal/config/environments/test.rb +5 -2
  38. data/spec/internal/config/initializers/assets.rb +11 -0
  39. data/spec/internal/config/initializers/cookies_serializer.rb +1 -1
  40. data/spec/internal/config/secrets.yml +2 -2
  41. data/spec/internal/db/development.sqlite3 +0 -0
  42. data/spec/internal/db/migrate/{20140620210534_create_qa_subject_mesh_terms.qa.rb → 20150311214117_create_qa_subject_mesh_terms.qa.rb} +0 -0
  43. data/spec/internal/db/migrate/{20140620210535_create_qa_mesh_tree.qa.rb → 20150311214118_create_qa_mesh_tree.qa.rb} +0 -0
  44. 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
  45. data/spec/internal/db/schema.rb +3 -3
  46. data/spec/internal/db/test.sqlite3 +0 -0
  47. data/spec/internal/lib/generators/test_app_generator.rb +0 -1
  48. data/spec/internal/log/development.log +498 -207
  49. data/spec/internal/test/test_helper.rb +0 -3
  50. data/spec/lib/authorities_getty_spec.rb +71 -0
  51. data/spec/lib/authorities_loc_spec.rb +98 -65
  52. data/spec/lib/authorities_loc_subauthorities.rb +81 -0
  53. data/spec/lib/authorities_local_spec.rb +53 -79
  54. data/spec/lib/authorities_local_subauthorities_spec.rb +43 -0
  55. data/spec/lib/authorities_mesh_spec.rb +16 -12
  56. data/spec/lib/authorities_oclcts_spec.rb +17 -17
  57. data/spec/lib/authorities_tgnlang_spec.rb +4 -7
  58. data/spec/lib/mesh_data_parser_spec.rb +13 -13
  59. data/spec/lib/tasks/mesh.rake_spec.rb +4 -4
  60. data/spec/models/subject_mesh_term_spec.rb +5 -5
  61. data/spec/routing/route_spec.rb +34 -0
  62. data/spec/spec_helper.rb +5 -22
  63. data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -1
  64. metadata +44 -12
  65. data/lib/qa/authorities/local/subauthority.rb +0 -65
  66. data/spec/internal/bin/spring +0 -18
@@ -0,0 +1,90 @@
1
+ module Qa::Authorities::LocSubauthority
2
+
3
+ def get_url_for_authority authority
4
+ case
5
+ when authorities.include?(authority) then authority_base_url
6
+ when vocabularies.include?(authority) then vocab_base_url
7
+ when datatypes.include?(authority) then datatype_base_url
8
+ when preservation.include?(authority) then vocab_preservation_base_url
9
+ end
10
+ end
11
+
12
+ def authorities
13
+ [
14
+ "subjects",
15
+ "names",
16
+ "classification",
17
+ "childrensSubjects",
18
+ "genreForms",
19
+ "performanceMediums"
20
+ ]
21
+ end
22
+
23
+ def vocabularies
24
+ [
25
+ "graphicMaterials",
26
+ "organizations",
27
+ "relators",
28
+ "countries",
29
+ "ethnographicTerms",
30
+ "geographicAreas",
31
+ "languages",
32
+ "iso639-1",
33
+ "iso639-2",
34
+ "iso639-5",
35
+ "preservation",
36
+ "actionsGranted",
37
+ "agentType"
38
+ ]
39
+ end
40
+
41
+ def datatypes
42
+ ["edtf"]
43
+ end
44
+
45
+ def preservation
46
+ [
47
+ "contentLocationType",
48
+ "copyrightStatus",
49
+ "cryptographicHashFunctions",
50
+ "environmentCharacteristic",
51
+ "environmentPurpose",
52
+ "eventRelatedAgentRole",
53
+ "eventRelatedObjectRole",
54
+ "eventType",
55
+ "formatRegistryRole",
56
+ "hardwareType",
57
+ "inhibitorTarget",
58
+ "inhibitorType",
59
+ "objectCategory",
60
+ "preservationLevelRole",
61
+ "relationshipSubType",
62
+ "relationshipType",
63
+ "rightsBasis",
64
+ "rightsRelatedAgentRole",
65
+ "signatureEncoding",
66
+ "signatureMethod",
67
+ "softwareType",
68
+ "storageMedium"
69
+ ]
70
+ end
71
+
72
+ private
73
+
74
+ def vocab_base_url
75
+ "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F"
76
+ end
77
+
78
+ def authority_base_url
79
+ "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F"
80
+ end
81
+
82
+ def datatype_base_url
83
+ "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F"
84
+ end
85
+
86
+ def vocab_preservation_base_url
87
+ "cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F"
88
+ end
89
+
90
+ end
@@ -1,39 +1,56 @@
1
1
  module Qa::Authorities
2
+ class Local < Base
2
3
 
3
- class Local < Qa::Authorities::Base
4
- extend Deprecation
4
+ include Qa::Authorities::LocalSubauthority
5
5
 
6
- attr_accessor :results
6
+ def initialize *args
7
+ super
8
+ @sub_authority ||= args.first
9
+ raise "No sub-authority provided" if sub_authority.nil?
10
+ end
7
11
 
8
- class << self
9
- def sub_authority(name)
10
- @sub_authorities ||= {}
11
- raise ArgumentError, "Invalid sub-authority '#{name}'" unless Subauthority.names.include?(name)
12
- @sub_authorities[name] ||= Subauthority.new(name)
13
- end
12
+ def sub_authorities
13
+ names
14
+ end
14
15
 
15
- def sub_authorities
16
- Subauthority.names
16
+ def search(q)
17
+ r = q.blank? ? [] : terms.select { |term| /\b#{q.downcase}/.match(term[:term].downcase) }
18
+ r.map do |res|
19
+ { :id => res[:id], :label => res[:term] }.with_indifferent_access
17
20
  end
21
+ end
18
22
 
19
- def terms(sub_authority)
20
- sub_authority(sub_authority).terms
23
+ def all
24
+ terms.map do |res|
25
+ { :id => res[:id], :label => res[:term] }.with_indifferent_access
21
26
  end
22
27
  end
23
28
 
24
- delegate :sub_authority, to: self
29
+ def find(id)
30
+ terms.find { |term| term[:id] == id } || {}
31
+ end
32
+
33
+ private
25
34
 
26
- def search(q, sub_authority)
27
- @results = sub_authority(sub_authority).search(q)
35
+ def terms
36
+ sub_authority_hash = YAML.load(File.read(sub_authority_filename))
37
+ terms = sub_authority_hash.with_indifferent_access.fetch(:terms, [])
38
+ normalize_terms(terms)
28
39
  end
29
40
 
30
- def full_record(id, sub_authority)
31
- sub_authority(sub_authority).full_record(id)
41
+ def sub_authority_filename
42
+ File.join(sub_authorities_path, "#{sub_authority}.yml")
32
43
  end
33
44
 
34
- def get_full_record(id, sub_authority)
35
- Deprecation.warn(Local, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller)
36
- full_record(id, sub_authority)
45
+ def normalize_terms(terms)
46
+ terms.map do |term|
47
+ if term.is_a? String
48
+ { :id => term, :term => term }.with_indifferent_access
49
+ else
50
+ term[:id] ||= term[:term]
51
+ term
52
+ end
53
+ end
37
54
  end
38
55
 
39
56
  end
@@ -0,0 +1,18 @@
1
+ module Qa::Authorities::LocalSubauthority
2
+
3
+ # Path to sub-authority files is either the full path to a directory or
4
+ # the path to a directory relative to the Rails application
5
+ def sub_authorities_path
6
+ if AUTHORITIES_CONFIG[:local_path].starts_with?(File::Separator)
7
+ AUTHORITIES_CONFIG[:local_path]
8
+ else
9
+ File.join(Rails.root, AUTHORITIES_CONFIG[:local_path])
10
+ end
11
+ end
12
+
13
+ # Local sub-authorities are any YAML files in the sub_authorities_path
14
+ def names
15
+ Dir.entries(sub_authorities_path).map { |f| File.basename(f, ".yml") if f.match(/yml$/) }.compact
16
+ end
17
+
18
+ end
@@ -1,32 +1,25 @@
1
1
  module Qa::Authorities
2
- class Mesh
3
- extend Deprecation
2
+ class Mesh < Base
4
3
 
5
- def results
6
- @results ||= begin
7
- r = Qa::SubjectMeshTerm.where('term_lower LIKE ?', "#{@q}%").limit(10)
8
- r.map { |t| {id: t.term_id, label: t.term} }
9
- end
4
+ def search q
5
+ begin
6
+ r = Qa::SubjectMeshTerm.where('term_lower LIKE ?', "#{@q}%").limit(10)
7
+ r.map { |t| {id: t.term_id, label: t.term} }
8
+ end
10
9
  end
11
10
 
12
- def search(q, sub_authority=nil)
13
- @q = q
11
+ def find id
12
+ begin
13
+ r = Qa::SubjectMeshTerm.where(term_id: id).limit(1).first
14
+ r.nil? ? nil : {id: r.term_id, label: r.term, synonyms: r.synonyms}
15
+ end
14
16
  end
15
17
 
16
- def full_record(id)
17
- @results ||= begin
18
- r = Qa::SubjectMeshTerm.where(term_id: id).limit(1).first
19
- r.nil? ? nil : {id: r.term_id, label: r.term, synonyms: r.synonyms}
20
- end
21
- end
22
-
23
- def get_full_record(id)
24
- Deprecation.warn(Mesh, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller)
25
- full_record(id)
26
- end
27
-
28
- # satisfy TermsController
29
- def parse_authority_response
18
+ def all
19
+ begin
20
+ r = Qa::SubjectMeshTerm.all
21
+ r.map { |t| {id: t.term_id, label: t.term} }
22
+ end
30
23
  end
31
24
 
32
25
  end
@@ -35,31 +35,6 @@ module Qa::Authorities
35
35
  return result
36
36
  end
37
37
 
38
- ### XXX: delete everything below?
39
-
40
- def self.get_synonyms(record)
41
- return [] if record['ENTRY'].blank?
42
- record['ENTRY'].map { |synonym| synonym.split('|').first }
43
- end
44
-
45
- def self.get_print_synonyms(record)
46
- return [] if record['PRINT ENTRY'].blank?
47
- record['PRINT ENTRY'].map { |synonym| synonym.split('|').first }
48
- end
49
-
50
- def self.get_description(record)
51
- return [] if record['MS'].blank?
52
- record['MS']
53
- end
54
-
55
- def self.get_tree(record)
56
- return [] if record['MN'].blank?
57
- record['MN']
58
- end
59
-
60
- def self.get_term(record)
61
- record['MH'].first
62
- end
63
38
  end
64
39
  end
65
40
  end
@@ -34,8 +34,6 @@ module Qa::Authorities
34
34
  record[field].map { |s| s.split('|').first }
35
35
  end
36
36
 
37
- def tree_number_to_term_list
38
- end
39
37
  end
40
38
  end
41
39
  end
@@ -2,26 +2,22 @@ require 'open-uri'
2
2
  require 'nokogiri'
3
3
 
4
4
  module Qa::Authorities
5
- class Oclcts < Qa::Authorities::Base
6
- extend Deprecation
5
+ class Oclcts < WebServiceBase
7
6
 
8
7
  SRU_SERVER_CONFIG = YAML.load_file(Rails.root.join("config", "oclcts-authorities.yml"))
9
-
10
- attr_accessor :sub_authority
11
8
 
12
- def initialize
9
+ def initialize *args
10
+ super
11
+ @sub_authority ||= args.first
12
+ raise "No sub-authority provided" if sub_authority.nil?
13
13
  end
14
14
 
15
- def self.authority_valid?(sub_authority)
16
- self.sub_authorities.include?(sub_authority)
15
+ def sub_authorities
16
+ SRU_SERVER_CONFIG["authorities"].map { |sub_authority| sub_authority[0] }
17
17
  end
18
18
 
19
- def self.sub_authorities
20
- @sub_authorities ||= SRU_SERVER_CONFIG["authorities"].map { |sub_authority| sub_authority[0] }
21
- end
22
-
23
- def search(q, sub_authority=nil)
24
- raw_response = get_raw_response("prefix-query", q, sub_authority)
19
+ def search q
20
+ get_raw_response("prefix-query", q)
25
21
  r = Array.new
26
22
  raw_response.xpath('sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData', 'sru' => 'http://www.loc.gov/zing/srw/').each do |record|
27
23
  r.append({"id" => record.xpath('Zthes/term/termId').first.content, "label" => record.xpath('Zthes/term/termName').first.content})
@@ -29,19 +25,16 @@ module Qa::Authorities
29
25
  r
30
26
  end
31
27
 
32
- def full_record(id, sub_authority)
33
- raw_response = get_raw_response("id-lookup", id, sub_authority)
34
- parse_full_record(raw_response, id)
28
+ def find id
29
+ get_raw_response("id-lookup", id)
30
+ parse_full_record(id)
35
31
  end
36
32
 
37
- def get_full_record(id, sub_authority)
38
- Deprecation.warn(Oclcts, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller)
39
- full_record(id, sub_authority)
40
- end
33
+ private
41
34
 
42
- def parse_full_record(raw_xml, id)
35
+ def parse_full_record id
43
36
  a = {}
44
- zthes_record = raw_xml.xpath("sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/Zthes/term[termId='#{id}']", 'sru' => 'http://www.loc.gov/zing/srw/')
37
+ zthes_record = raw_response.xpath("sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/Zthes/term[termId='#{id}']", 'sru' => 'http://www.loc.gov/zing/srw/')
45
38
  zthes_record.children.each do |child|
46
39
  if (child.is_a? Nokogiri::XML::Element) && (!child.children.nil?) && (child.children.size == 1) && (child.children.first.is_a? Nokogiri::XML::Text)
47
40
  a[child.name] = child.children.first.to_s
@@ -50,9 +43,9 @@ module Qa::Authorities
50
43
  a
51
44
  end
52
45
 
53
- def get_raw_response(query_type, id, sub_authority)
46
+ def get_raw_response query_type, id
54
47
  query_url = SRU_SERVER_CONFIG["url-pattern"][query_type].gsub("{query}", id).gsub("{id}", id).gsub("{authority-id}", sub_authority)
55
- Nokogiri::XML(open(query_url))
48
+ @raw_response = Nokogiri::XML(open(query_url))
56
49
  end
57
50
  end
58
51
  end
@@ -1,15 +1,10 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  module Qa::Authorities
4
- class Tgnlang
5
- attr_accessor :response
6
- extend Deprecation
4
+ class Tgnlang < Base
7
5
 
8
- def initialize
9
- end
10
-
11
- def search(q, sub_authority='')
12
- self.response = getTgnLang(q)
6
+ def search(q)
7
+ getTgnLang(q)
13
8
  end
14
9
 
15
10
  def getTgnLang(q)
@@ -39,16 +34,7 @@ module Qa::Authorities
39
34
  end
40
35
  end
41
36
 
42
- def results
43
- self.response
44
- end
45
-
46
- def get_full_record(id, sub_authority)
47
- Deprecation.warn(Tgnlang, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller)
48
- full_record(id, sub_authority)
49
- end
50
-
51
- def full_record(id, sub_authority)
37
+ def find(id)
52
38
  id = id.downcase
53
39
  Tgnlang.languages.each do |h|
54
40
  if h["label"].downcase == id
@@ -1,20 +1,13 @@
1
1
  require 'rest_client'
2
- require 'deprecation'
3
2
 
4
3
  module Qa::Authorities
5
- class WebServiceBase
6
- attr_accessor :response, :raw_response
4
+ class WebServiceBase < Base
5
+ attr_accessor :raw_response
7
6
 
8
7
  # mix-in to retreive and parse JSON content from the web
9
8
  def get_json(url)
10
9
  r = RestClient.get url, {accept: :json}
11
- self.response = JSON.parse(r)
12
- end
13
-
14
- # This method should be removed
15
- # use #response instead
16
- def results
17
- self.response
10
+ JSON.parse(r)
18
11
  end
19
12
  end
20
13
  end
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,78 +1,127 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Qa::TermsController do
3
+ describe Qa::TermsController, :type => :controller do
4
4
 
5
5
  before do
6
6
  @routes = Qa::Engine.routes
7
7
  end
8
8
 
9
- describe "#index" do
9
+ describe "#check_vocab_param" do
10
+ it "should return 404 if the vocabulary is missing" do
11
+ get :search, { :q => "a query", :vocab => "" }
12
+ expect(response.code).to eq("404")
13
+ end
14
+ end
10
15
 
11
- context "with errors" do
16
+ describe "#check_query_param" do
17
+ it "should return 404 if the query is missing" do
18
+ get :search, { :q => "", :vocab => "tgnlang" }
19
+ expect(response.code).to eq("404")
20
+ end
21
+ end
12
22
 
13
- it "should return 400 if no vocabulary is specified" do
14
- get :index, { :vocab => nil}
15
- expect(response.code).to eq("400")
23
+ describe "#init_authority" do
24
+ context "when the authority does not exist" do
25
+ it "should return 404" do
26
+ get :search, { :q => "a query", :vocab => "non-existent-authority" }
27
+ expect(response.code).to eq("404")
16
28
  end
17
-
18
- it "should return 400 if no query is specified" do
19
- get :index, { :q => nil}
20
- expect(response.code).to eq("400")
29
+ end
30
+ context "when a sub-authority does not exist" do
31
+ it "should return 404 if a sub-authority does not exist" do
32
+ get :search, { :q => "a query", :vocab => "loc", :sub_authority => "non-existent-subauthority" }
33
+ expect(response.code).to eq("404")
21
34
  end
22
-
23
- it "should return 400 if vocabulary is not valid" do
24
- get :index, { :q => "foo", :vocab => "bar" }
25
- expect(response.code).to eq("400")
35
+ end
36
+ context "when a sub-authority is absent" do
37
+ it "should return 404 for LOC" do
38
+ get :search, { :q => "a query", :vocab => "loc" }
39
+ expect(response.code).to eq("404")
26
40
  end
27
-
28
- it "should return 400 if sub_authority is not valid" do
29
- get :index, { :q => "foo", :vocab => "loc", :sub_authority => "foo" }
30
- expect(response.code).to eq("400")
41
+ it "should return 404 for oclcts" do
42
+ get :search, { :q => "a query", :vocab => "oclcts" }
43
+ expect(response.code).to eq("404")
31
44
  end
45
+ end
46
+ end
47
+
48
+ describe "#search" do
32
49
 
50
+ before :each do
51
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names").
52
+ with(:headers => {'Accept'=>'application/json'}).
53
+ to_return(:body => webmock_fixture("loc-names-response.txt"), :status => 200)
33
54
  end
34
55
 
35
- context "with a successful query" do
56
+ it "should return a set of terms for a tgnlang query" do
57
+ get :search, {:q => "Tibetan", :vocab => "tgnlang" }
58
+ expect(response).to be_success
59
+ end
36
60
 
37
- before :each do
38
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=").
39
- with(:headers => {'Accept'=>'application/json'}).
40
- to_return(:body => webmock_fixture("loc-response.txt"), :status => 200)
41
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/vocabulary/relators").
42
- with(:headers => {'Accept'=>'application/json'}).
43
- to_return(:body => webmock_fixture("loc-response.txt"), :status => 200)
44
- end
61
+ it "should not return 404 if sub_authority is valid" do
62
+ get :search, { :q => "Berry", :vocab => "loc", :sub_authority => "names" }
63
+ expect(response).to be_success
64
+ end
45
65
 
46
- it "should return a set of terms for a tgnlang query" do
47
- get :index, {:q => "Tibetan", :vocab => "tgnlang" }
66
+ end
67
+
68
+ describe "#index" do
69
+
70
+ context "with supported authorities" do
71
+ it "should return all local authority state terms" do
72
+ get :index, { :vocab => "local", :sub_authority => "states" }
48
73
  expect(response).to be_success
49
74
  end
75
+ it "should return all MeSH terms" do
76
+ get :index, { :vocab => "mesh" }
77
+ expect(response).to be_success
78
+ end
79
+ end
50
80
 
51
- it "should not return 400 if vocabulary is valid" do
52
- get :index, { :q => "foo", :vocab => "loc" }
53
- expect(response.code).to_not eq("400")
81
+ context "when the authority does not support #all" do
82
+ it "should return null for tgnlang" do
83
+ get :index, { :vocab => "tgnlang" }
84
+ expect(response.body).to eq("null")
54
85
  end
86
+ it "should return null for oclcts" do
87
+ get :index, { :vocab => "oclcts", :sub_authority => "mesh" }
88
+ expect(response.body).to eq("null")
89
+ end
90
+ it "should return null for LOC authorities" do
91
+ get :index, { :vocab => "loc", :sub_authority => "relators" }
92
+ expect(response.body).to eq("null")
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ describe "#show" do
99
+
100
+ context "with supported authorities" do
55
101
 
56
- it "should not return 400 if sub_authority is valid" do
57
- get :index, { :q => "foo", :vocab => "loc", :sub_authority => "relators" }
58
- expect(response.code).to_not eq("400")
102
+ before do
103
+ stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json").
104
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
105
+ to_return(:status => 200, :body => webmock_fixture("loc-names-response.txt"), :headers => {})
59
106
  end
60
107
 
61
- end
108
+ it "should return an individual state term" do
109
+ get :show, { :vocab => "local", :sub_authority => "states", id: "OH" }
110
+ expect(response).to be_success
111
+ end
62
112
 
63
- context "when returning all terms" do
113
+ it "should return an individual MeSH term" do
114
+ get :show, { vocab: "mesh", id: "D000001" }
115
+ expect(response).to be_success
116
+ end
64
117
 
65
- it "should return all local authority state terms" do
66
- get :index, { :vocab => "local", :sub_authority => "states" }
67
- response.should be_success
118
+ it "should return an individual subject term" do
119
+ get :show, { vocab: "loc", sub_authority: "subjects", id: "sh85077565" }
120
+ expect(response).to be_success
68
121
  end
69
122
 
70
123
  end
71
124
 
72
125
  end
73
126
 
74
- describe "#show" do
75
- it "the path resolves"
76
- end
77
-
78
127
  end