From bca1284656f4ff0e59f61901637fc06e60664c4f Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Thu, 11 Feb 2021 09:14:55 -0500 Subject: [PATCH] Setup github actions. Bumping version due to some rubocop appeasment & housekeeping. --- .github/workflows/ruby.yml | 31 +++++++++ .travis.yml | 7 -- argon_call_number_search.gemspec | 4 +- .../search_builder_behavior.rb | 31 +++++---- lib/argon_call_number_search/version.rb | 2 +- .../search_builder_behavior_spec.rb | 66 +++++++++---------- 6 files changed, 84 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/ruby.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 0000000..1ad7b71 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + pull_request: + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['2.4.6', '2.5.5', '2.6.3'] + name: Ruby ${{ matrix.ruby }} + + steps: + - uses: actions/checkout@v2 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + - name: Install dependencies + run: bundle install + + - name: Run rubocop + run: rubocop + + - name: Run tests + run: rspec diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2103175..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -sudo: false -language: ruby -cache: bundler -rvm: - - 2.5.3 -before_install: gem install bundler -v 2.0.2 diff --git a/argon_call_number_search.gemspec b/argon_call_number_search.gemspec index 49937d1..80ff846 100644 --- a/argon_call_number_search.gemspec +++ b/argon_call_number_search.gemspec @@ -7,6 +7,7 @@ require 'argon_call_number_search/version' Gem::Specification.new do |spec| spec.name = 'argon_call_number_search' spec.version = ArgonCallNumberSearch::VERSION + spec.required_ruby_version = '~> 2.4' spec.authors = ['Cory Lown'] spec.email = ['cory.lown@duke.edu'] @@ -34,10 +35,9 @@ Gem::Specification.new do |spec| spec.add_dependency 'activesupport' spec.add_dependency 'lcsort' - spec.add_dependency 'trln_argon', '~> 1.0' spec.add_development_dependency 'bundler', '~> 2.0' - spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'rake', '>= 12.3.3' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rubocop' spec.add_development_dependency 'rubocop-rspec' diff --git a/lib/argon_call_number_search/search_builder_behavior.rb b/lib/argon_call_number_search/search_builder_behavior.rb index ba73931..873dd3d 100644 --- a/lib/argon_call_number_search/search_builder_behavior.rb +++ b/lib/argon_call_number_search/search_builder_behavior.rb @@ -6,31 +6,34 @@ def add_call_number_query_to_solr(solr_parameters) return unless call_number_query_present? solr_parameters[:defType] = 'lucene' - if blacklight_params[:search_field] == 'advanced' && solr_parameters[:q] - # Replace default call number query from Blacklight advanced search handling - solr_parameters[:q] = solr_parameters[:q].gsub("_query_:\"{!edismax}#{call_number_query_str}\"", + solr_parameters[:q] = if blacklight_params[:search_field] == 'advanced' && solr_parameters[:q] + # Replace default call number query from Blacklight advanced search handling + solr_parameters[:q].gsub("_query_:\"{!edismax}#{call_number_query_str}\"", "(#{call_number_queries})") - else - solr_parameters[:q] = call_number_queries - end + else + call_number_queries + end end private + # rubocop:disable Metrics/AbcSize def call_number_query_present? blacklight_params.key?(:search_field) && - (blacklight_params[:search_field] == 'call_number' && - blacklight_params[:q].present? && - blacklight_params[:q].respond_to?(:to_str)) || - (blacklight_params[:search_field] == 'advanced' && - blacklight_params[:call_number].present? && - blacklight_params[:call_number].respond_to?(:to_str)) + (blacklight_params[:search_field] == 'call_number' && + blacklight_params[:q].present? && + blacklight_params[:q].respond_to?(:to_str)) || + (blacklight_params[:search_field] == 'advanced' && + blacklight_params[:call_number].present? && + blacklight_params[:call_number].respond_to?(:to_str)) end + # rubocop:enable Metrics/AbcSize def call_number_query_str - if blacklight_params[:search_field] == 'call_number' + case blacklight_params[:search_field] + when 'call_number' blacklight_params[:q].to_s - elsif blacklight_params[:search_field] == 'advanced' + when 'advanced' blacklight_params[:call_number].to_s end end diff --git a/lib/argon_call_number_search/version.rb b/lib/argon_call_number_search/version.rb index 818b492..e6ebeab 100644 --- a/lib/argon_call_number_search/version.rb +++ b/lib/argon_call_number_search/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ArgonCallNumberSearch - VERSION = '0.1.2' + VERSION = '0.1.3' end diff --git a/spec/argon_call_number_search/search_builder_behavior_spec.rb b/spec/argon_call_number_search/search_builder_behavior_spec.rb index 5487f09..5f2c0ab 100644 --- a/spec/argon_call_number_search/search_builder_behavior_spec.rb +++ b/spec/argon_call_number_search/search_builder_behavior_spec.rb @@ -28,51 +28,51 @@ class SearchBuilderTestClass end describe 'lc call number search' do - context 'call number search' do + context 'when call number search' do let(:blacklight_parameters) do - { :search_field => 'call_number', - :q => 'PS3623.I556497 P433' } + { search_field: 'call_number', + q: 'PS3623.I556497 P433' } end it 'generates a solr query' do expect(SearchBuilder.add_call_number_query_to_solr(solr_parameters)).to( - eq('lc_call_nos_normed_a:/PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ - 'shelfkey:/lc:PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ - '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}' \ - '(PS3623.I556497 P433)"') + eq('lc_call_nos_normed_a:/PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ + 'shelfkey:/lc:PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ + '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}' \ + '(PS3623.I556497 P433)"') ) end end - context 'advanced search' do + context 'when advanced search' do let(:blacklight_parameters) do - { :search_field => 'advanced', - :title => 'meditations', - :call_number => 'PS3623.I556497 P433', - :op => 'AND' } + { search_field: 'advanced', + title: 'meditations', + call_number: 'PS3623.I556497 P433', + op: 'AND' } end let(:solr_parameters) do # solr_parameters from advanced search - { :q => "_query_:\"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}" \ + { q: '_query_:"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}' \ "#{blacklight_parameters[:title]}\" AND _query_:\"{!edismax}#{blacklight_parameters[:call_number]}\"" } end it 'generates a solr query' do expect(SearchBuilder.add_call_number_query_to_solr(solr_parameters)).to( - eq('_query_:"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}meditations" AND ' \ - '(lc_call_nos_normed_a:/PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ - 'shelfkey:/lc:PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ - '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}' \ - '(PS3623.I556497 P433)")') + eq('_query_:"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}meditations" AND ' \ + '(lc_call_nos_normed_a:/PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ + 'shelfkey:/lc:PS.3623.I556497.P433(\\..*|-.*)*/ OR ' \ + '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}' \ + '(PS3623.I556497 P433)")') ) end end end describe 'accession number search' do - context 'call number search' do + context 'when call number search' do let(:blacklight_parameters) do - { :search_field => 'call_number', - :q => 'cd 12345' } + { search_field: 'call_number', + q: 'cd 12345' } end it 'generates a solr query' do @@ -86,26 +86,26 @@ class SearchBuilderTestClass end end - context 'advanced search' do + context 'when advanced search' do let(:blacklight_parameters) do - { :search_field => 'advanced', - :title => 'ballad', - :call_number => 'cd 12345', - :op => 'OR' } + { search_field: 'advanced', + title: 'ballad', + call_number: 'cd 12345', + op: 'OR' } end let(:solr_parameters) do # solr_parameters from advanced search - { :q => "_query_:\"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}" \ + { q: '_query_:"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}' \ "#{blacklight_parameters[:title]}\" OR _query_:\"{!edismax}#{blacklight_parameters[:call_number]}\"" } end it 'generates a solr query' do expect(SearchBuilder.add_call_number_query_to_solr(solr_parameters)).to( - eq('_query_:"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}ballad" OR ' \ - '(lc_call_nos_normed_a:/cd 12345(\\..*|-.*)*/ OR '\ - 'shelfkey:/lc:cd 12345(\\..*|-.*)*/ OR '\ - '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}'\ - '(cd 12345)" OR '\ - '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}(cd12345)")') + eq('_query_:"{!edismax qf=$title_qf pf=$title_pf pf3=$title_pf3 pf2=$title_pf2}ballad" OR ' \ + '(lc_call_nos_normed_a:/cd 12345(\\..*|-.*)*/ OR '\ + 'shelfkey:/lc:cd 12345(\\..*|-.*)*/ OR '\ + '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}'\ + '(cd 12345)" OR '\ + '_query_:"{!edismax qf=shelf_numbers_tp pf= pf3= pf2=}(cd12345)")') ) end end