test/test_helper.rb in searchkick-0.9.1 vs test/test_helper.rb in searchkick-1.0.0

- old
+ new

@@ -1,10 +1,11 @@ require "bundler/setup" Bundler.require(:default) require "minitest/autorun" require "minitest/pride" require "logger" +require "active_support/core_ext" if defined?(NoBrainer) ENV["RACK_ENV"] = "test" Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test) @@ -15,16 +16,30 @@ I18n.config.enforce_available_locales = true ActiveJob::Base.logger = nil if defined?(ActiveJob) -if defined?(Mongoid) +def elasticsearch2? + Searchkick.server_version.starts_with?("2.") +end - def mongoid2? - Mongoid::VERSION.starts_with?("2.") - end +def mongoid2? + defined?(Mongoid) && Mongoid::VERSION.starts_with?("2.") +end +def nobrainer? + defined?(NoBrainer) +end + +def activerecord_below41? + defined?(ActiveRecord) && Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("4.1.0") +end + +if defined?(Mongoid) + Mongoid.logger.level = Logger::INFO + Mongo::Logger.logger.level = Logger::INFO if defined?(Mongo::Logger) + if mongoid2? # enable comparison of BSON::ObjectIds module BSON class ObjectId def <=>(other) @@ -94,11 +109,11 @@ field :found_rate field :price, type: Integer field :color, type: String field :latitude field :longitude - field :description, type: String + field :description, type: String belongs_to :store, validates: false end class Store @@ -218,19 +233,19 @@ end end class Store searchkick \ - routing: :name, + routing: elasticsearch2? ? false : "name", merge_mappings: true, mappings: { store: { properties: { - name: {type: "string", analyzer: "keyword"}, + name: {type: "string", analyzer: "keyword"} } } - } + } end class Animal searchkick \ autocomplete: [:name], @@ -245,11 +260,10 @@ Store.reindex Animal.reindex class Minitest::Test - def setup Product.destroy_all Store.destroy_all Animal.destroy_all end @@ -277,7 +291,6 @@ end def assert_first(term, expected, options = {}, klass = Product) assert_equal expected, klass.search(term, options).map(&:name).first end - end