Skip to content

Commit

Permalink
Merge pull request #2 from trln/github-actions-2
Browse files Browse the repository at this point in the history
Setup github actions. Bumping version due to some rubocop appeasmennt & housekeeping.
  • Loading branch information
kazymovae authored Feb 11, 2021
2 parents 4cbcf23 + bca1284 commit d5c5443
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 57 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions argon_call_number_search.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['[email protected]']

Expand Down Expand Up @@ -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'
Expand Down
31 changes: 17 additions & 14 deletions lib/argon_call_number_search/search_builder_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/argon_call_number_search/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ArgonCallNumberSearch
VERSION = '0.1.2'
VERSION = '0.1.3'
end
66 changes: 33 additions & 33 deletions spec/argon_call_number_search/search_builder_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d5c5443

Please sign in to comment.