Commit 278ea36fe2d6eb874fbe3c152a47a7a80a874108

Authored by Andrew Kane
1 parent 2f4a89ec

Added different Elasticsearch versions to Travis

.travis.yml
... ... @@ -22,10 +22,22 @@ gemfile:
22 22 - test/gemfiles/mongoid3.gemfile
23 23 - test/gemfiles/mongoid4.gemfile
24 24 - test/gemfiles/mongoid5.gemfile
  25 +env:
  26 + - ELASTICSEARCH_VERSION=2.3.0
25 27 matrix:
26 28 include:
  29 + - gemfile: Gemfile
  30 + env: ELASTICSEARCH_VERSION=1.0.0
  31 + - gemfile: Gemfile
  32 + env: ELASTICSEARCH_VERSION=1.7.0
  33 + - gemfile: Gemfile
  34 + env: ELASTICSEARCH_VERSION=2.0.0
  35 + - gemfile: Gemfile
  36 + env: ELASTICSEARCH_VERSION=5.0.0-alpha2
27 37 # - gemfile: test/gemfiles/nobrainer.gemfile
28 38 # env: NOBRAINER=true
29 39 allow_failures:
  40 + - gemfile: Gemfile
  41 + env: ELASTICSEARCH_VERSION=5.0.0-alpha2
30 42 # - gemfile: test/gemfiles/nobrainer.gemfile
31 43 # env: NOBRAINER=true
... ...
lib/searchkick.rb
... ... @@ -58,6 +58,10 @@ module Searchkick
58 58 @server_version ||= client.info["version"]["number"]
59 59 end
60 60  
  61 + def self.below_version?(version)
  62 + Gem::Version.new(server_version) < Gem::Version.new(version)
  63 + end
  64 +
61 65 def self.enable_callbacks
62 66 self.callbacks_value = nil
63 67 end
... ...
lib/searchkick/query.rb
... ... @@ -781,19 +781,15 @@ module Searchkick
781 781 end
782 782  
783 783 def below12?
784   - below_version?("1.2.0")
  784 + Searchkick.below_version?("1.2.0")
785 785 end
786 786  
787 787 def below14?
788   - below_version?("1.4.0")
  788 + Searchkick.below_version?("1.4.0")
789 789 end
790 790  
791 791 def below20?
792   - below_version?("2.0.0")
793   - end
794   -
795   - def below_version?(version)
796   - Gem::Version.new(Searchkick.server_version) < Gem::Version.new(version)
  792 + Searchkick.below_version?("2.0.0")
797 793 end
798 794 end
799 795 end
... ...
test/ci/before_install.sh
... ... @@ -3,8 +3,12 @@
3 3 gem install bundler
4 4  
5 5 sudo apt-get purge elasticsearch
6   -wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.3.deb
7   -sudo dpkg -i elasticsearch-1.7.3.deb
  6 +if [[ $ELASTICSEARCH_VERSION == 1* ]]; then
  7 + wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.deb
  8 +else
  9 + wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.deb
  10 +fi
  11 +sudo dpkg -i elasticsearch-$ELASTICSEARCH_VERSION.deb
8 12 sudo service elasticsearch start
9 13  
10 14 if [ -n "$NOBRAINER" ]; then
... ...
test/facets_test.rb
... ... @@ -2,7 +2,7 @@ require_relative &quot;test_helper&quot;
2 2  
3 3 class FacetsTest < Minitest::Test
4 4 def setup
5   - skip if elasticsearch2?
  5 + skip unless elasticsearch_below20?
6 6 super
7 7 store [
8 8 {name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago},
... ...
test/match_test.rb
... ... @@ -110,12 +110,14 @@ class MatchTest &lt; Minitest::Test
110 110 end
111 111  
112 112 def test_misspelling_zucchini_transposition
  113 + skip unless elasticsearch_below14?
113 114 store_names ["zucchini"]
114 115 assert_search "zuccihni", ["zucchini"]
115 116 assert_search "zuccihni", [], misspellings: {transpositions: false}
116 117 end
117 118  
118 119 def test_misspelling_lasagna
  120 + skip unless elasticsearch_below14?
119 121 store_names ["lasagna"]
120 122 assert_search "lasanga", ["lasagna"], misspellings: {transpositions: true}
121 123 assert_search "lasgana", ["lasagna"], misspellings: {transpositions: true}
... ... @@ -124,6 +126,7 @@ class MatchTest &lt; Minitest::Test
124 126 end
125 127  
126 128 def test_misspelling_lasagna_pasta
  129 + skip unless elasticsearch_below14?
127 130 store_names ["lasagna pasta"]
128 131 assert_search "lasanga", ["lasagna pasta"], misspellings: {transpositions: true}
129 132 assert_search "lasanga pasta", ["lasagna pasta"], misspellings: {transpositions: true}
... ...
test/test_helper.rb
... ... @@ -21,8 +21,12 @@ I18n.config.enforce_available_locales = true
21 21 ActiveJob::Base.logger = nil if defined?(ActiveJob)
22 22 ActiveSupport::LogSubscriber.logger = Logger.new(STDOUT) if ENV["NOTIFICATIONS"]
23 23  
24   -def elasticsearch2?
25   - Searchkick.server_version.starts_with?("2.")
  24 +def elasticsearch_below20?
  25 + Searchkick.below_version?("2.0.0")
  26 +end
  27 +
  28 +def elasticsearch_below14?
  29 + Searchkick.server_version.starts_with?("1.4.0")
26 30 end
27 31  
28 32 def mongoid2?
... ...