Skip to content

Commit

Permalink
Merge branch 'master' into cors_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Aug 31, 2018
2 parents 7dbf2cb + 8bb7a62 commit 33f7249
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
13 changes: 11 additions & 2 deletions lib/qa/authorities/local/mysql_table_based_authority.rb
Expand Up @@ -5,8 +5,7 @@ class MysqlTableBasedAuthority < Local::TableBasedAuthority
self.table_index = "index_qa_local_authority_entries_on_lower_label_and_authority"

def self.check_for_index
conn = ActiveRecord::Base.connection
if table_or_view_exists? && conn.index_name_exists?(table_name.to_sym, table_index, :default).blank? # rubocop:disable Style/GuardClause
if table_or_view_exists? && index_name_exists? # rubocop:disable Style/GuardClause
Rails.logger.error "You've installed mysql local authority tables, but you haven't indexed the lower label. "
"Rails doesn't support functional indexes in migrations, so we tried to execute it for you but something went wrong...\n" \
"Make sure your table has a lower_label column, which is virtually created, and that the column is indexed." \
Expand All @@ -19,6 +18,16 @@ def search(q)
return [] if q.blank?
output_set(base_relation.where('lower_label like ?', "#{q.downcase}%").limit(25))
end

def self.index_name_exists?
conn = ActiveRecord::Base.connection
if ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1
conn.index_name_exists?(table_name, table_index).blank?
else
conn.index_name_exists?(table_name, table_index, :default).blank?
end
end
private_class_method :index_name_exists?
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/linked_data_terms_controller_spec.rb
Expand Up @@ -132,7 +132,7 @@
end
it 'succeeds' do
get :search, params: { q: 'supercalifragilisticexpialidocious', vocab: 'OCLC_FAST', maximumRecords: '3' }
expect(response).to be_success
expect(response).to be_successful
end
end

Expand All @@ -143,7 +143,7 @@
end
it 'succeeds' do
get :search, params: { q: 'cornell', vocab: 'OCLC_FAST', maximumRecords: '3' }
expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand All @@ -156,7 +156,7 @@
end
it 'succeeds' do
get :search, params: { q: 'supercalifragilisticexpialidocious', vocab: 'OCLC_FAST', subauthority: 'personal_name', maximumRecords: '3' }
expect(response).to be_success
expect(response).to be_successful
end
end

Expand All @@ -167,7 +167,7 @@
end
it 'succeeds' do
get :search, params: { q: 'cornell', vocab: 'OCLC_FAST', subauthority: 'personal_name', maximumRecords: '3' }
expect(response).to be_success
expect(response).to be_successful
end
end

Expand Down Expand Up @@ -204,7 +204,7 @@
end
it 'succeeds' do
get :search, params: { q: 'supercalifragilisticexpialidocious', vocab: 'AGROVOC' }
expect(response).to be_success
expect(response).to be_successful
end
end

Expand All @@ -215,7 +215,7 @@
end
it 'succeeds' do
get :search, params: { q: 'milk', vocab: 'AGROVOC' }
expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand Down Expand Up @@ -289,7 +289,7 @@
end
it 'succeeds' do
get :show, params: { id: '530369', vocab: 'OCLC_FAST' }
expect(response).to be_success
expect(response).to be_successful
end
end

Expand Down Expand Up @@ -326,7 +326,7 @@
end
it 'succeeds' do
get :show, params: { id: 'c_9513', vocab: 'AGROVOC' }
expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand All @@ -339,7 +339,7 @@
end
it 'succeeds' do
get :show, params: { id: 'sh85118553', vocab: 'LOC', subauthority: 'subjects' }
expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/terms_controller_spec.rb
Expand Up @@ -72,7 +72,7 @@ def search(_arg1, _arg2)
end
it "succeeds" do
get :search, params: { q: "a query", vocab: "local", subauthority: "two_args" }
expect(response).to be_success
expect(response).to be_successful
end
end

Expand All @@ -85,12 +85,12 @@ def search(_arg1, _arg2)

it "returns a set of terms for a tgnlang query" do
get :search, params: { q: "Tibetan", vocab: "tgnlang" }
expect(response).to be_success
expect(response).to be_successful
end

it "does not return 404 if subauthority is valid" do
get :search, params: { q: "Berry", vocab: "loc", subauthority: "names" }
expect(response).to be_success
expect(response).to be_successful
end

context 'when cors headers are enabled' do
Expand Down Expand Up @@ -128,7 +128,7 @@ def search(_arg1, _arg2)
end
it "succeeds if authority class is camelcase" do
get :search, params: { q: "word", vocab: "assign_fast", subauthority: "topical" }
expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand All @@ -137,11 +137,11 @@ def search(_arg1, _arg2)
context "with supported authorities" do
it "returns all local authority state terms" do
get :index, params: { vocab: "local", subauthority: "states" }
expect(response).to be_success
expect(response).to be_successful
end
it "returns all MeSH terms" do
get :index, params: { vocab: "mesh" }
expect(response).to be_success
expect(response).to be_successful
end

context 'when cors headers are enabled' do
Expand Down Expand Up @@ -191,17 +191,17 @@ def search(_arg1, _arg2)

it "returns an individual state term" do
get :show, params: { vocab: "local", subauthority: "states", id: "OH" }
expect(response).to be_success
expect(response).to be_successful
end

it "returns an individual MeSH term" do
get :show, params: { vocab: "mesh", id: "D000001" }
expect(response).to be_success
expect(response).to be_successful
end

it "returns an individual subject term" do
get :show, params: { vocab: "loc", subauthority: "subjects", id: "sh85077565" }
expect(response).to be_success
expect(response).to be_successful
end

context 'when cors headers are enabled' do
Expand Down

0 comments on commit 33f7249

Please sign in to comment.