From 82e15539290d5327d8ebb6fe79374e0437924c0c Mon Sep 17 00:00:00 2001 From: Brian 'Phunk' Gadoury Date: Wed, 28 Aug 2013 21:13:09 -0400 Subject: [PATCH] Improve testability under Travis --- .travis.yml | 1 + bin/test-full-app.sh | 1 + features/metacharacter_filtering.feature | 8 ++++---- features/support/v1_hooks.rb | 9 ++++----- v1/lib/v1/searchable/query.rb | 11 ++++++----- v1/spec/items.json | 12 ++++++++++-- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index a5a0ff0..a982667 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,3 +18,4 @@ services: branches: only: - develop + - travfix diff --git a/bin/test-full-app.sh b/bin/test-full-app.sh index 78fdf11..cd5116c 100755 --- a/bin/test-full-app.sh +++ b/bin/test-full-app.sh @@ -4,4 +4,5 @@ # test suite the same way Travis CI is. (Referenced from .travis.yml) # Brian 'Phunk' Gadoury +# bundle exec rspec spec v1/spec && bundle exec rake cucumber diff --git a/features/metacharacter_filtering.feature b/features/metacharacter_filtering.feature index 5ab5935..0bd893b 100644 --- a/features/metacharacter_filtering.feature +++ b/features/metacharacter_filtering.feature @@ -20,9 +20,9 @@ Feature: Search for items by keyword with meta-characters in the query string When I item-search for "&&test{" Then I should get http status code "200" - Scenario: Basic keyword search with crazy multiple un-parseable meta-characters all over the place + Scenario: Basic keyword search with crazy multiple un-parseable meta-characters everywhere When I item-search for "}?harv[a:z](" - Then I should get http status code "200" + Then the API should return record item-meta2 Scenario: Basic keyword search with embedded double-quote When I item-search for '2 pieces, 3 3/4" x 7' @@ -36,7 +36,7 @@ Feature: Search for items by keyword with meta-characters in the query string When I item-search for '"2 pieces, 3 x 7"' Then I should get http status code "200" - Scenario: Basic keyword search with embedded double-quote wrapped in outer double-quotes, expecting a search hit + Scenario: Basic keyword search with embedded double-quote wrapped in outer double-quotes When I item-search for '"1 1/2" by 3 1/2""' - Then the API should return record item-wood + Then the API should return record item-meta1 diff --git a/features/support/v1_hooks.rb b/features/support/v1_hooks.rb index ee8c8b8..1556202 100644 --- a/features/support/v1_hooks.rb +++ b/features/support/v1_hooks.rb @@ -21,13 +21,12 @@ puts "Initializing test environment for the repository and search index..." V1::Repository.recreate_env - sleep 2 + sleep(ENV['TRAVIS'] ? 10 : 3) previous_index = V1::SearchEngine.create_and_deploy_index - V1::SearchEngine.safe_delete_index(previous_index) + V1::SearchEngine.safe_delete_index(previous_index) if previous_index - # Sleep a bit to let CouchDB finish doing its thing internally, as well as letting - # the river catch up on indexing the docs added to CouchDB. - sleep 5 + # Sleep a bit to let the river catch up on indexing the docs added to CouchDB. + sleep (ENV['TRAVIS'] ? 10 : 3) puts "Search docs : #{V1::SearchEngine.doc_count}" end diff --git a/v1/lib/v1/searchable/query.rb b/v1/lib/v1/searchable/query.rb index d170f8a..ed231ff 100644 --- a/v1/lib/v1/searchable/query.rb +++ b/v1/lib/v1/searchable/query.rb @@ -8,9 +8,9 @@ module Searchable module Query - # not escaped, but probably could be: '&&', '||' + # not escaped, but probably could be if escape code was tweaked: '&&', '||' # not escaped, because they don't seem to need it: '+', '-', - ESCAPED_METACHARACTERS = [ '"', '!', '(', ')', '{', '}', '[', ']', '^', '~', '?', ':', '\\' ] + ESCAPED_METACHARACTERS = [ '"', '!', '(', ')', '{', '}', '[', ']', '^', '~', '?', ':' ] def self.execute_empty_search(search) # We need to be explicit with an empty search @@ -23,13 +23,13 @@ def self.build_all(resource, search, params) date_range_queries = date_range_queries(params) # ids_queries = ids_query(resource, params) + # Only call search.query.boolean if we have some queries to pass it. + # Otherwise we'll get incorrect search results. if (string_queries + date_range_queries).empty? execute_empty_search(search) return false end - # Only call search.query.boolean if we have some queries to pass it. - # Otherwise we'll get incorrect search results. search.query do |query| # if ids_queries.any? # query.ids *ids_queries @@ -65,8 +65,9 @@ def self.protect_metacharacters(string) tmp = $1 quoted = true end + escaped_metacharacters.each do |mc| - tmp.gsub!(mc, '\\' + mc.split('').join('\\\\') ) + tmp.gsub!(mc, '\\' + mc) end quoted ? %Q("#{tmp}") : tmp diff --git a/v1/spec/items.json b/v1/spec/items.json index 72849df..cb4959d 100644 --- a/v1/spec/items.json +++ b/v1/spec/items.json @@ -723,13 +723,21 @@ } }, { - "_id": "item-wood", - "id": "item-wood", + "_id": "item-meta1", + "id": "item-meta1", "ingestType": "item", "sourceResource": { "title": "2 x 4 pieces of wood are actually 1 1/2\" by 3 1/2\" after milling" } }, + { + "_id": "item-meta2", + "id": "item-meta2", + "ingestType": "item", + "sourceResource": { + "title": "My cat's name is }?harv[a:z](" + } + }, { "_id": "item-canoncasesort1", "id": "item-canoncasesort1",