test/test_helper.rb in searchkick-0.4.1 vs test/test_helper.rb in searchkick-0.4.2
- old
+ new
@@ -31,10 +31,12 @@
field :longitude, type: BigDecimal
end
class Store
include Mongoid::Document
+
+ field :name
end
class Animal
include Mongoid::Document
@@ -71,10 +73,11 @@
t.decimal :longitude, precision: 10, scale: 7
t.timestamps
end
ActiveRecord::Migration.create_table :stores, :force => true do |t|
+ t.string :name
end
ActiveRecord::Migration.create_table :animals, :force => true do |t|
t.string :name
t.string :type
@@ -117,26 +120,42 @@
attr_accessor :conversions, :user_ids
def search_data
serializable_hash.merge conversions: conversions, user_ids: user_ids, location: [latitude, longitude], multiple_locations: [[latitude, longitude], [0, 0]]
end
+
+ def should_index?
+ name != "DO NOT INDEX"
+ end
end
+class Store
+ searchkick mappings: {
+ store: {
+ properties: {
+ name: {type: "string", analyzer: "keyword"}
+ }
+ }
+ }
+end
+
class Animal
searchkick autocomplete: [:name], suggest: [:name]
end
Product.searchkick_index.delete if Product.searchkick_index.exists?
Product.reindex
Product.reindex # run twice for both index paths
+Store.reindex
Animal.reindex
class Minitest::Unit::TestCase
def setup
Product.destroy_all
+ Animal.destroy_all
end
protected
def store(documents, klass = Product)
@@ -149,18 +168,18 @@
def store_names(names, klass = Product)
store names.map{|name| {name: name} }, klass
end
# no order
- def assert_search(term, expected, options = {})
- assert_equal expected.sort, Product.search(term, options).map(&:name).sort
+ def assert_search(term, expected, options = {}, klass = Product)
+ assert_equal expected.sort, klass.search(term, options).map(&:name).sort
end
- def assert_order(term, expected, options = {})
- assert_equal expected, Product.search(term, options).map(&:name)
+ def assert_order(term, expected, options = {}, klass = Product)
+ assert_equal expected, klass.search(term, options).map(&:name)
end
- def assert_first(term, expected, options = {})
- assert_equal expected, Product.search(term, options).map(&:name).first
+ def assert_first(term, expected, options = {}, klass = Product)
+ assert_equal expected, klass.search(term, options).map(&:name).first
end
end