From 278ea36fe2d6eb874fbe3c152a47a7a80a874108 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 4 May 2016 01:43:33 -0700 Subject: [PATCH] Added different Elasticsearch versions to Travis --- .travis.yml | 12 ++++++++++++ lib/searchkick.rb | 4 ++++ lib/searchkick/query.rb | 10 +++------- test/ci/before_install.sh | 8 ++++++-- test/facets_test.rb | 2 +- test/match_test.rb | 3 +++ test/test_helper.rb | 8 ++++++-- 7 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 90a8a6a..d3266bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,22 @@ gemfile: - test/gemfiles/mongoid3.gemfile - test/gemfiles/mongoid4.gemfile - test/gemfiles/mongoid5.gemfile +env: + - ELASTICSEARCH_VERSION=2.3.0 matrix: include: + - gemfile: Gemfile + env: ELASTICSEARCH_VERSION=1.0.0 + - gemfile: Gemfile + env: ELASTICSEARCH_VERSION=1.7.0 + - gemfile: Gemfile + env: ELASTICSEARCH_VERSION=2.0.0 + - gemfile: Gemfile + env: ELASTICSEARCH_VERSION=5.0.0-alpha2 # - gemfile: test/gemfiles/nobrainer.gemfile # env: NOBRAINER=true allow_failures: + - gemfile: Gemfile + env: ELASTICSEARCH_VERSION=5.0.0-alpha2 # - gemfile: test/gemfiles/nobrainer.gemfile # env: NOBRAINER=true diff --git a/lib/searchkick.rb b/lib/searchkick.rb index 719d729..5f70647 100644 --- a/lib/searchkick.rb +++ b/lib/searchkick.rb @@ -58,6 +58,10 @@ module Searchkick @server_version ||= client.info["version"]["number"] end + def self.below_version?(version) + Gem::Version.new(server_version) < Gem::Version.new(version) + end + def self.enable_callbacks self.callbacks_value = nil end diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 69922ce..6556cc1 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -781,19 +781,15 @@ module Searchkick end def below12? - below_version?("1.2.0") + Searchkick.below_version?("1.2.0") end def below14? - below_version?("1.4.0") + Searchkick.below_version?("1.4.0") end def below20? - below_version?("2.0.0") - end - - def below_version?(version) - Gem::Version.new(Searchkick.server_version) < Gem::Version.new(version) + Searchkick.below_version?("2.0.0") end end end diff --git a/test/ci/before_install.sh b/test/ci/before_install.sh index b891d08..df42974 100755 --- a/test/ci/before_install.sh +++ b/test/ci/before_install.sh @@ -3,8 +3,12 @@ gem install bundler sudo apt-get purge elasticsearch -wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.3.deb -sudo dpkg -i elasticsearch-1.7.3.deb +if [[ $ELASTICSEARCH_VERSION == 1* ]]; then + wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.deb +else + wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.deb +fi +sudo dpkg -i elasticsearch-$ELASTICSEARCH_VERSION.deb sudo service elasticsearch start if [ -n "$NOBRAINER" ]; then diff --git a/test/facets_test.rb b/test/facets_test.rb index c15edce..b1305ac 100644 --- a/test/facets_test.rb +++ b/test/facets_test.rb @@ -2,7 +2,7 @@ require_relative "test_helper" class FacetsTest < Minitest::Test def setup - skip if elasticsearch2? + skip unless elasticsearch_below20? super store [ {name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago}, diff --git a/test/match_test.rb b/test/match_test.rb index 3463439..e52861d 100644 --- a/test/match_test.rb +++ b/test/match_test.rb @@ -110,12 +110,14 @@ class MatchTest < Minitest::Test end def test_misspelling_zucchini_transposition + skip unless elasticsearch_below14? store_names ["zucchini"] assert_search "zuccihni", ["zucchini"] assert_search "zuccihni", [], misspellings: {transpositions: false} end def test_misspelling_lasagna + skip unless elasticsearch_below14? store_names ["lasagna"] assert_search "lasanga", ["lasagna"], misspellings: {transpositions: true} assert_search "lasgana", ["lasagna"], misspellings: {transpositions: true} @@ -124,6 +126,7 @@ class MatchTest < Minitest::Test end def test_misspelling_lasagna_pasta + skip unless elasticsearch_below14? store_names ["lasagna pasta"] assert_search "lasanga", ["lasagna pasta"], misspellings: {transpositions: true} assert_search "lasanga pasta", ["lasagna pasta"], misspellings: {transpositions: true} diff --git a/test/test_helper.rb b/test/test_helper.rb index 1c84850..0662177 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,8 +21,12 @@ I18n.config.enforce_available_locales = true ActiveJob::Base.logger = nil if defined?(ActiveJob) ActiveSupport::LogSubscriber.logger = Logger.new(STDOUT) if ENV["NOTIFICATIONS"] -def elasticsearch2? - Searchkick.server_version.starts_with?("2.") +def elasticsearch_below20? + Searchkick.below_version?("2.0.0") +end + +def elasticsearch_below14? + Searchkick.server_version.starts_with?("1.4.0") end def mongoid2? -- libgit2 0.21.0