Skip to content

Commit

Permalink
Force downcase in MESH authority queries
Browse files Browse the repository at this point in the history
MESH ids are in lowercase. Since query is case sensitive, we need to downcase
query terms in order to prevent false negatives based on typist idiosyncracies.

Since it's not possible to redirect authorities in `Qa` due to the `TermsController`
behavior (samvera/questioning_authority#137), we
simply monkeypatch the existing `Qa::Authorities::Mesh` class.
  • Loading branch information
Tom Johnson committed Jan 27, 2018
1 parent 8003c4a commit 5355eda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/models/qa/authorities/mesh.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'qa/authorities/mesh'

module Qa
module Authorities
##
# Monkeypatch the built in MESH authority to downcase terms.
#
# @see https://github.com/samvera/questioning_authority/issues/158
class Mesh
def search(query)
Qa::SubjectMeshTerm
.where('term_lower LIKE ?', "#{query.to_s.downcase}%")
.limit(10)
.map { |t| { id: t.term_id, label: t.term } }
end
end
end
end
2 changes: 1 addition & 1 deletion spec/features/autocomplete_mesh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
click_on 'Additional fields'

# Check that we get the correct autocompletion from QA
find('#etd_subject').send_keys 'sulfameraz'
find('#etd_subject').send_keys 'SuLFamerAZ'
expect(page).to have_content('Sulfamerazine')

# Fill out the rest of the form
Expand Down

0 comments on commit 5355eda

Please sign in to comment.