Skip to content
This repository has been archived by the owner on Oct 4, 2018. It is now read-only.

Commit

Permalink
Improve testability under Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
bgadoury committed Aug 29, 2013
1 parent 8390ad4 commit 82e1553
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -18,3 +18,4 @@ services:
branches:
only:
- develop
- travfix
1 change: 1 addition & 0 deletions bin/test-full-app.sh
Expand Up @@ -4,4 +4,5 @@
# test suite the same way Travis CI is. (Referenced from .travis.yml)
# Brian 'Phunk' Gadoury <bgadoury@endpoint.com>

#
bundle exec rspec spec v1/spec && bundle exec rake cucumber
8 changes: 4 additions & 4 deletions features/metacharacter_filtering.feature
Expand Up @@ -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'
Expand All @@ -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

9 changes: 4 additions & 5 deletions features/support/v1_hooks.rb
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions v1/lib/v1/searchable/query.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions v1/spec/items.json
Expand Up @@ -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",
Expand Down

0 comments on commit 82e1553

Please sign in to comment.