qa 2.0.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +54 -6
  3. data/app/controllers/qa/application_controller.rb +24 -0
  4. data/app/controllers/qa/linked_data_terms_controller.rb +116 -51
  5. data/app/controllers/qa/terms_controller.rb +7 -2
  6. data/app/models/qa/mesh_tree.rb +5 -9
  7. data/app/models/qa/subject_mesh_term.rb +2 -7
  8. data/config/authorities/linked_data/agrovoc.json +8 -1
  9. data/config/initializers/linked_data_authorities.rb +1 -17
  10. data/config/routes.rb +11 -0
  11. data/lib/generators/qa/apidoc/USAGE +11 -0
  12. data/lib/generators/qa/apidoc/apidoc_generator.rb +22 -0
  13. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/apidoc.json +1322 -0
  14. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-16x16.png +0 -0
  15. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/favicon-32x32.png +0 -0
  16. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/index.html +61 -0
  17. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/oauth2-redirect.html +67 -0
  18. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js +93 -0
  19. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-bundle.js.map +1 -0
  20. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js +14 -0
  21. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui-standalone-preset.js.map +1 -0
  22. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css +3 -0
  23. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.css.map +1 -0
  24. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js +9 -0
  25. data/lib/generators/qa/apidoc/templates/public/qa/apidoc/swagger-ui.js.map +1 -0
  26. data/lib/generators/qa/install/install_generator.rb +11 -0
  27. data/lib/generators/qa/install/templates/config/initializers/qa.rb +13 -0
  28. data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +1 -1
  29. data/lib/generators/qa/local/tables/tables_generator.rb +1 -1
  30. data/lib/qa.rb +16 -0
  31. data/lib/qa/authorities/assign_fast_subauthority.rb +3 -3
  32. data/lib/qa/authorities/getty/aat.rb +13 -6
  33. data/lib/qa/authorities/getty/tgn.rb +11 -22
  34. data/lib/qa/authorities/getty/ulan.rb +13 -16
  35. data/lib/qa/authorities/linked_data.rb +1 -0
  36. data/lib/qa/authorities/linked_data/authority_service.rb +47 -0
  37. data/lib/qa/authorities/linked_data/config.rb +9 -3
  38. data/lib/qa/authorities/linked_data/config/search_config.rb +16 -2
  39. data/lib/qa/authorities/linked_data/config/term_config.rb +17 -3
  40. data/lib/qa/authorities/linked_data/find_term.rb +4 -3
  41. data/lib/qa/authorities/linked_data/generic_authority.rb +8 -1
  42. data/lib/qa/authorities/linked_data/rdf_helper.rb +15 -0
  43. data/lib/qa/authorities/linked_data/search_query.rb +19 -3
  44. data/lib/qa/authorities/loc/generic_authority.rb +2 -2
  45. data/lib/qa/authorities/loc_subauthority.rb +2 -2
  46. data/lib/qa/authorities/local.rb +2 -4
  47. data/lib/qa/authorities/local/file_based_authority.rb +1 -1
  48. data/lib/qa/authorities/local/mysql_table_based_authority.rb +11 -2
  49. data/lib/qa/authorities/local/table_based_authority.rb +2 -1
  50. data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +1 -1
  51. data/lib/qa/authorities/mesh_tools/mesh_importer.rb +1 -1
  52. data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +1 -3
  53. data/lib/qa/configuration.rb +34 -0
  54. data/lib/qa/version.rb +1 -1
  55. data/lib/tasks/mesh.rake +3 -3
  56. data/spec/controllers/linked_data_terms_controller_spec.rb +247 -18
  57. data/spec/controllers/terms_controller_spec.rb +87 -12
  58. data/spec/fixtures/authorities/linked_data/lod_encoding_config.json +91 -0
  59. data/spec/fixtures/authorities/linked_data/lod_term_id_param_config.json +27 -0
  60. data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +27 -0
  61. data/spec/fixtures/{lexvo_snippet.rdf → lexvo_snippet.rdf.xml} +1 -0
  62. data/spec/lib/authorities/assign_fast_spec.rb +3 -1
  63. data/spec/lib/authorities/file_based_authority_spec.rb +19 -11
  64. data/spec/lib/authorities/geonames_spec.rb +3 -3
  65. data/spec/lib/authorities/getty/aat_spec.rb +14 -8
  66. data/spec/lib/authorities/getty/tgn_spec.rb +8 -15
  67. data/spec/lib/authorities/getty/ulan_spec.rb +8 -6
  68. data/spec/lib/authorities/getty_spec.rb +2 -1
  69. data/spec/lib/authorities/linked_data/authority_service_spec.rb +47 -0
  70. data/spec/lib/authorities/linked_data/generic_authority_spec.rb +56 -14
  71. data/spec/lib/authorities/linked_data/search_config_spec.rb +33 -19
  72. data/spec/lib/authorities/linked_data/search_query_spec.rb +67 -15
  73. data/spec/lib/authorities/linked_data/term_config_spec.rb +34 -20
  74. data/spec/lib/authorities/loc_spec.rb +9 -9
  75. data/spec/lib/authorities/local_spec.rb +7 -8
  76. data/spec/lib/authorities/oclcts_spec.rb +27 -20
  77. data/spec/lib/authorities/table_based_authority_spec.rb +5 -3
  78. data/spec/lib/authorities_loc_subauthorities.rb +2 -2
  79. data/spec/lib/configuration_spec.rb +58 -0
  80. data/spec/lib/mesh_data_parser_spec.rb +2 -0
  81. data/spec/lib/services/rdf_authority_parser_spec.rb +1 -1
  82. data/spec/lib/tasks/mesh.rake_spec.rb +13 -12
  83. data/spec/models/subject_mesh_term_spec.rb +2 -0
  84. data/spec/requests/cors_headers_spec.rb +118 -0
  85. data/spec/spec_helper.rb +2 -2
  86. metadata +167 -137
@@ -28,14 +28,14 @@ describe Qa::Authorities::Loc do
28
28
  end
29
29
 
30
30
  context "for searching" do
31
- let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
31
+ let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
32
32
  it "returns a url" do
33
33
  expect(authority.build_query_url("foo")).to eq(url)
34
34
  end
35
35
  end
36
36
 
37
37
  context "for returning single terms" do
38
- let(:url) { "http://id.loc.gov/authorities/subjects/sh2002003586.json" }
38
+ let(:url) { "https://id.loc.gov/authorities/subjects/sh2002003586.json" }
39
39
  it "returns a url with an authority and id" do
40
40
  expect(authority.find_url("sh2002003586")).to eq(url)
41
41
  end
@@ -49,15 +49,15 @@ describe Qa::Authorities::Loc do
49
49
  end
50
50
 
51
51
  before do
52
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
52
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
53
53
  .with(headers: { 'Accept' => 'application/json' })
54
54
  .to_return(status: 200, body: "")
55
55
  end
56
56
 
57
57
  context "with flat params encoded" do
58
- let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
58
+ let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
59
59
  it "returns a response" do
60
- flat_params_url = "http://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
60
+ flat_params_url = "https://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
61
61
  expect(subject.env.url.to_s).to eq(flat_params_url)
62
62
  end
63
63
  end
@@ -66,7 +66,7 @@ describe Qa::Authorities::Loc do
66
66
  describe "#search" do
67
67
  context "any LOC authorities" do
68
68
  let :authority do
69
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
69
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
70
70
  .with(headers: { 'Accept' => 'application/json' })
71
71
  .to_return(body: webmock_fixture("loc-response.txt"), status: 200)
72
72
  described_class.subauthority_for("geographicAreas")
@@ -95,7 +95,7 @@ describe Qa::Authorities::Loc do
95
95
 
96
96
  context "subject terms" do
97
97
  let :results do
98
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
98
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
99
99
  .with(headers: { 'Accept' => 'application/json' })
100
100
  .to_return(body: webmock_fixture("loc-subjects-response.txt"), status: 200)
101
101
  described_class.subauthority_for("subjects").search("History--")
@@ -111,7 +111,7 @@ describe Qa::Authorities::Loc do
111
111
 
112
112
  context "name terms" do
113
113
  let :results do
114
- stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
114
+ stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
115
115
  .with(headers: { 'Accept' => 'application/json' })
116
116
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
117
117
  described_class.subauthority_for("names").search("Berry")
@@ -125,7 +125,7 @@ describe Qa::Authorities::Loc do
125
125
  describe "#find" do
126
126
  context "using a subject id" do
127
127
  let :results do
128
- stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json")
128
+ stub_request(:get, "https://id.loc.gov/authorities/subjects/sh2002003586.json")
129
129
  .with(headers: { 'Accept' => 'application/json' })
130
130
  .to_return(status: 200, body: webmock_fixture("loc-subject-find-response.txt"), headers: {})
131
131
  described_class.subauthority_for("subjects").find("sh2002003586")
@@ -8,11 +8,11 @@ describe Qa::Authorities::Local do
8
8
  end
9
9
 
10
10
  describe "#subauthorities_path" do
11
+ let!(:original_path) { described_class.config[:local_path] }
11
12
  before do
12
- @original_path = described_class.config[:local_path]
13
13
  described_class.config[:local_path] = path
14
14
  end
15
- after { described_class.config[:local_path] = @original_path }
15
+ after { described_class.config[:local_path] = original_path }
16
16
 
17
17
  context "configured with a full path" do
18
18
  let(:path) { "/full/path" }
@@ -25,8 +25,8 @@ describe Qa::Authorities::Local do
25
25
  context "configured with a relative path" do
26
26
  let(:path) { "relative/path" }
27
27
 
28
- it "returns a path relative to the Rails applicaition" do
29
- expect(described_class.subauthorities_path).to eq(File.join(Rails.root, path))
28
+ it "returns a path relative to the Rails application" do
29
+ expect(described_class.subauthorities_path).to eq(Rails.root.join(path).to_s)
30
30
  end
31
31
  end
32
32
  end
@@ -37,11 +37,11 @@ describe Qa::Authorities::Local do
37
37
  end
38
38
 
39
39
  context "when the path doesn't exist" do
40
+ let!(:original_path) { described_class.config[:local_path] }
40
41
  before do
41
- @original_path = described_class.config[:local_path]
42
42
  described_class.config[:local_path] = '/foo/bar'
43
43
  end
44
- after { described_class.config[:local_path] = @original_path }
44
+ after { described_class.config[:local_path] = original_path }
45
45
 
46
46
  it "raises an error" do
47
47
  expect { described_class.names }.to raise_error Qa::ConfigDirectoryNotFound
@@ -70,8 +70,7 @@ describe Qa::Authorities::Local do
70
70
  describe ".register" do
71
71
  before do
72
72
  class SolrAuthority
73
- def initialize(one)
74
- end
73
+ def initialize(one); end
75
74
  end
76
75
  described_class.register_subauthority('new_sub', 'SolrAuthority')
77
76
  end
@@ -1,46 +1,53 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Qa::Authorities::Oclcts do
4
+ let(:first_query) { described_class.subauthority_for("mesh") }
5
+ let(:terms) { first_query.search("ball") }
6
+ let(:term_record) { first_query.find(terms.first["id"]) }
7
+ let(:second_query) { described_class.subauthority_for("mesh") }
8
+
4
9
  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")
10
+ stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts" \
11
+ ".rootHeading%20exact%20%22ball*%22&recordPacking=xml&recordSchema=" \
12
+ "http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1")
6
13
  .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")
14
+ stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts" \
15
+ ".rootHeading%20exact%20%22alph*%22&recordPacking=xml&recordSchema=" \
16
+ "http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1")
8
17
  .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")
18
+ stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=dc" \
19
+ ".identifier%20exact%20%22D031329Q000821%22&recordPacking=xml&recordSchema=" \
20
+ "http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1")
10
21
  .to_return(body: webmock_fixture("oclcts-response-mesh-3.txt"), status: 200)
11
22
 
12
- @first_query = described_class.subauthority_for("mesh")
13
- @terms = @first_query.search("ball")
14
- @term_record = @first_query.find(@terms.first["id"])
15
- @second_query = described_class.subauthority_for("mesh")
16
- @second_query.search("alph")
23
+ second_query.search("alph")
17
24
  end
18
25
 
19
26
  describe "a query for terms" do
20
27
  it "has an array of hashes that match the query" do
21
- expect(@terms).to be_kind_of Array
22
- expect(@terms.first).to be_kind_of Hash
23
- expect(@terms.first["label"]).to be_kind_of String
24
- expect(@terms.first["label"]).to include "Ballota"
28
+ expect(terms).to be_kind_of Array
29
+ expect(terms.first).to be_kind_of Hash
30
+ expect(terms.first["label"]).to be_kind_of String
31
+ expect(terms.first["label"]).to include "Ballota"
25
32
  end
26
33
 
27
34
  it "has an array of hashes containing unique id and label" do
28
- expect(@terms.first).to have_key("id")
29
- expect(@terms.first).to have_key("label")
35
+ expect(terms.first).to have_key("id")
36
+ expect(terms.first).to have_key("label")
30
37
  end
31
38
  end
32
39
 
33
40
  describe "a query for a single item" do
34
41
  it "has a hash of values that represent the item requested" do
35
- expect(@term_record).to be_kind_of Hash
36
- expect(@term_record.values).to include @terms.first["id"]
37
- expect(@term_record.values).to include @terms.first["label"]
42
+ expect(term_record).to be_kind_of Hash
43
+ expect(term_record.values).to include terms.first["id"]
44
+ expect(term_record.values).to include terms.first["label"]
38
45
  end
39
46
 
40
47
  it "succeeds for valid ids, even if the id is not in the initial list of responses" do
41
- record = @second_query.find(@terms.first["id"])
42
- expect(record.values).to include @terms.first["id"]
43
- expect(record.values).to include @terms.first["label"]
48
+ record = second_query.find(terms.first["id"])
49
+ expect(record.values).to include terms.first["id"]
50
+ expect(record.values).to include terms.first["label"]
44
51
  end
45
52
  end
46
53
  end
@@ -25,9 +25,11 @@ describe Qa::Authorities::Local::TableBasedAuthority do
25
25
  end
26
26
 
27
27
  describe "#all" do
28
- let(:expected) { [{ 'id' => "A1", 'label' => "Abc Term A1" },
29
- { 'id' => "A2", 'label' => "Term A2" },
30
- { 'id' => "A3", 'label' => "Abc Term A3" }] }
28
+ let(:expected) do
29
+ [{ 'id' => "A1", 'label' => "Abc Term A1" },
30
+ { 'id' => "A2", 'label' => "Term A2" },
31
+ { 'id' => "A3", 'label' => "Abc Term A3" }]
32
+ end
31
33
  it "returns all the entries" do
32
34
  expect(language.all).to eq [
33
35
  { "id" => "http://id.loc.gov/vocabulary/languages/fre", "label" => "French" },
@@ -10,7 +10,7 @@ describe Qa::Authorities::LocSubauthority do
10
10
 
11
11
  context "with a valid subauthority" do
12
12
  it "returns a url" do
13
- subauthority_table.keys.each do |authority|
13
+ subauthority_table.each_key do |authority|
14
14
  expect(subject.get_url_for_authority(authority)).to eq(subauthority_table[authority])
15
15
  end
16
16
  end
@@ -24,7 +24,7 @@ describe Qa::Authorities::LocSubauthority do
24
24
 
25
25
  # This is the original data structure that was used to define subauthority urls
26
26
  # It is retained here to ensure our refactor succeeded
27
- def subauthority_table
27
+ def subauthority_table # rubocop:disable Metrics/MethodLength
28
28
  vocab_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F'
29
29
  authority_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F'
30
30
  datatype_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F'
@@ -0,0 +1,58 @@
1
+ RSpec.describe Qa::Configuration do
2
+ subject { described_class.new }
3
+
4
+ it { is_expected.to respond_to(:cors_headers?) }
5
+ it { is_expected.to respond_to(:enable_cors_headers) }
6
+ it { is_expected.to respond_to(:disable_cors_headers) }
7
+ it { is_expected.to respond_to(:authorized_reload_token=) }
8
+ it { is_expected.to respond_to(:authorized_reload_token) }
9
+ it { is_expected.to respond_to(:valid_authority_reload_token?) }
10
+
11
+ describe '#enable_cors_headers' do
12
+ it 'turns on cors headers support' do
13
+ subject.enable_cors_headers
14
+ expect(subject.cors_headers?).to be true
15
+ end
16
+ end
17
+
18
+ describe '#disable_cors_headers' do
19
+ it 'turns off cors headers support' do
20
+ subject.disable_cors_headers
21
+ expect(subject.cors_headers?).to be false
22
+ end
23
+ end
24
+
25
+ describe '#valid_authority_reload_token?' do
26
+ it 'defaults to invalid' do
27
+ expect(subject.valid_authority_reload_token?('any value')).to be false
28
+ end
29
+
30
+ context 'when token is set to blank' do
31
+ before do
32
+ subject.authorized_reload_token = ''
33
+ end
34
+
35
+ it 'returns false if token matches' do
36
+ expect(subject.valid_authority_reload_token?('')).to be false
37
+ end
38
+
39
+ it "returns false if token doesn't match" do
40
+ expect(subject.valid_authority_reload_token?('any value')).to be false
41
+ end
42
+ end
43
+
44
+ context 'when token has a value' do
45
+ before do
46
+ subject.authorized_reload_token = 'A_TOKEN'
47
+ end
48
+
49
+ it 'returns true if the passed in token matches' do
50
+ expect(subject.valid_authority_reload_token?('A_TOKEN')).to be true
51
+ end
52
+
53
+ it 'returns false if the passed in token does not match' do
54
+ expect(subject.valid_authority_reload_token?('BAD TOKEN')).to be false
55
+ end
56
+ end
57
+ end
58
+ end
@@ -47,6 +47,7 @@ EOS
47
47
  expect(records[1]).to eq({})
48
48
  end
49
49
 
50
+ # rubocop:disable Metrics/LineLength
50
51
  it 'parses a sample mesh file' do
51
52
  mesh = described_class.new(webmock_fixture('mesh.txt'))
52
53
  records = mesh.all_records
@@ -116,4 +117,5 @@ EOS
116
117
  "DX" => ["19840101"],
117
118
  "UI" => ["D000001"])
118
119
  end
120
+ # rubocop:enable Metrics/LineLength
119
121
  end
@@ -2,7 +2,7 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Qa::Services::RDFAuthorityParser do
5
- let(:source) { [File.join(fixture_path, 'lexvo_snippet.rdf')] }
5
+ let(:source) { [File.join(fixture_path, 'lexvo_snippet.rdf.xml')] }
6
6
  let(:format) { 'rdfxml' }
7
7
  let(:predicate) { RDF::URI("http://www.w3.org/2008/05/skos#prefLabel") }
8
8
  let(:name) { 'language' }
@@ -2,33 +2,34 @@ require 'spec_helper'
2
2
  require 'rake'
3
3
  require 'stringio'
4
4
 
5
- describe "mesh rake tasks" do
5
+ describe "mesh rake tasks" do # rubocop:disable RSpec/DescribeClass
6
+ let(:rake) { Rake::Application.new }
6
7
  before do
7
- @rake = Rake::Application.new
8
- Rake.application = @rake
9
- Rake.application.rake_require "mesh", ["#{Rails.root}/lib/tasks", "#{Rails.root}/../lib/tasks"], []
8
+ Rake.application = rake
9
+ Rake.application.rake_require "mesh", [Rails.root.join('lib', 'tasks'), Rails.root.join('..', 'lib', 'tasks')], []
10
10
  Rake::Task.define_task(:environment) # rspec has loaded rails
11
11
  end
12
12
 
13
13
  describe "mesh:import" do
14
+ let(:task_name) { "mesh:import" }
15
+ let(:output) { StringIO.new }
14
16
  before do
15
- @task_name = "mesh:import"
16
- @output = StringIO.new
17
- $stdout = @output
17
+ $stdout = output # rubocop:disable RSpec/ExpectOutput # TODO: Explore how to remove this disable
18
18
  end
19
19
  after :all do
20
20
  $stdout = STDOUT
21
21
  end
22
22
  it "has 'environment' as a prereq" do
23
- expect(@rake[@task_name].prerequisites).to include("environment")
23
+ expect(rake[task_name].prerequisites).to include("environment")
24
24
  end
25
25
  it "requires $MESH_FILE to be set" do
26
26
  old_mesh_file = ENV.delete('MESH_FILE')
27
- @rake[@task_name].invoke
28
- @output.seek(0)
29
- expect(@output.read).to match(/Need to set \$MESH_FILE with path to file to ingest/)
27
+ rake[task_name].invoke
28
+ output.seek(0)
29
+ expect(output.read).to match(/Need to set \$MESH_FILE with path to file to ingest/)
30
30
  ENV['MESH_FILE'] = old_mesh_file
31
31
  end
32
+
32
33
  describe "create or update" do
33
34
  let(:input) { StringIO.new("*NEWRECORD\nUI = 5\nMH = test\n") }
34
35
  let(:term) { Qa::SubjectMeshTerm.find_by_term_id(5) }
@@ -36,7 +37,7 @@ describe "mesh rake tasks" do
36
37
  before do
37
38
  ENV['MESH_FILE'] = "dummy"
38
39
  allow(File).to receive(:open).with("dummy").and_yield(input)
39
- @rake[@task_name].invoke
40
+ rake[task_name].invoke
40
41
  end
41
42
  it "creates or update all records in the config file" do
42
43
  expect(term).not_to be_nil
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # rubocop:disable RSpec/InstanceVariable # TODO: Explore if there is a way to remove this disable
3
4
  describe Qa::SubjectMeshTerm, type: :model do
4
5
  before(:all) do
5
6
  @term = Qa::SubjectMeshTerm.new
@@ -47,3 +48,4 @@ describe Qa::SubjectMeshTerm, type: :model do
47
48
  # @term.parents.map { |p| p.term_id }.should == ["1", "2", "3"]
48
49
  # end
49
50
  end
51
+ # rubocop:enable RSpec/InstanceVariable
@@ -0,0 +1,118 @@
1
+ # spec/requests/cors_headers_spec.rb
2
+ require 'spec_helper'
3
+
4
+ describe "CORS OPTIONS requests" do # rubocop:disable RSpec/DescribeClass
5
+ context 'when cors headers are enabled' do
6
+ before do
7
+ Qa.config.enable_cors_headers
8
+ end
9
+
10
+ it 'return CORS header info for index' do
11
+ reset!
12
+ integration_session.__send__ :process, 'OPTIONS', "/qa/terms/loc"
13
+ correct_cors_response?
14
+ end
15
+
16
+ it 'return CORS header info for index with subauthority' do
17
+ reset!
18
+ integration_session.__send__ :process, 'OPTIONS', "/qa/terms/local/states"
19
+ correct_cors_response?
20
+ end
21
+
22
+ it 'return CORS header info for search' do
23
+ reset!
24
+ integration_session.__send__ :process, 'OPTIONS', "/qa/search/loc"
25
+ correct_cors_response?
26
+ end
27
+
28
+ it 'return CORS header info for search with subauthority' do
29
+ reset!
30
+ integration_session.__send__ :process, 'OPTIONS', "/qa/search/local/two_args?q=a query"
31
+ correct_cors_response?
32
+ end
33
+
34
+ it 'return CORS header info for show' do
35
+ reset!
36
+ integration_session.__send__ :process, 'OPTIONS', "/qa/show/mesh/D000001"
37
+ correct_cors_response?
38
+ end
39
+
40
+ it 'return CORS header info for show with subauthority' do
41
+ reset!
42
+ integration_session.__send__ :process, 'OPTIONS', "/qa/show/local/states/OH"
43
+ correct_cors_response?
44
+ end
45
+
46
+ it 'return CORS header info for linked_data/search' do
47
+ reset!
48
+ integration_session.__send__ :process, 'OPTIONS', "/qa/search/linked_data/OCLC_FAST?q=my_query&maximumRecords=3"
49
+ correct_cors_response?
50
+ end
51
+
52
+ it 'return CORS header info for linked_data/show' do
53
+ reset!
54
+ integration_session.__send__ :process, 'OPTIONS', "/qa/show/linked_data/OCLC_FAST/n24"
55
+ correct_cors_response?
56
+ end
57
+ end
58
+
59
+ def correct_cors_response?
60
+ expect(response.code).to eq('204')
61
+ expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
62
+ expect(response.headers['Access-Control-Allow-Methods']).to eq 'GET, OPTIONS'
63
+ end
64
+
65
+ context 'when cors headers are disabled' do
66
+ before do
67
+ Qa.config.disable_cors_headers
68
+ end
69
+
70
+ it 'report method not supported for index' do
71
+ reset!
72
+ integration_session.__send__ :process, 'OPTIONS', "/qa/terms/loc"
73
+ expect(response.code).to eq('501')
74
+ end
75
+
76
+ it 'report method not supported for index with subauthority' do
77
+ reset!
78
+ integration_session.__send__ :process, 'OPTIONS', "/qa/terms/local/states"
79
+ expect(response.code).to eq('501')
80
+ end
81
+
82
+ it 'report method not supported for search' do
83
+ reset!
84
+ integration_session.__send__ :process, 'OPTIONS', "/qa/search/loc"
85
+ expect(response.code).to eq('501')
86
+ end
87
+
88
+ it 'report method not supported for search with subauthority' do
89
+ reset!
90
+ integration_session.__send__ :process, 'OPTIONS', "/qa/search/local/two_args?q=a query"
91
+ expect(response.code).to eq('501')
92
+ end
93
+
94
+ it 'report method not supported for show' do
95
+ reset!
96
+ integration_session.__send__ :process, 'OPTIONS', "/qa/show/mesh/D000001"
97
+ expect(response.code).to eq('501')
98
+ end
99
+
100
+ it 'report method not supported for show with subauthority' do
101
+ reset!
102
+ integration_session.__send__ :process, 'OPTIONS', "/qa/show/local/states/OH"
103
+ expect(response.code).to eq('501')
104
+ end
105
+
106
+ it 'report method not supported for linked_data/search' do
107
+ reset!
108
+ integration_session.__send__ :process, 'OPTIONS', "/qa/search/linked_data/OCLC_FAST?q=my_query&maximumRecords=3"
109
+ expect(response.code).to eq('501')
110
+ end
111
+
112
+ it 'report method not supported for linked_data/show' do
113
+ reset!
114
+ integration_session.__send__ :process, 'OPTIONS', "/qa/show/linked_data/OCLC_FAST/n24"
115
+ expect(response.code).to eq('501')
116
+ end
117
+ end
118
+ end