test/test_helper.rb in searchkick-0.3.1 vs test/test_helper.rb in searchkick-0.3.2

- old
+ new

@@ -22,10 +22,20 @@ end class Store include Mongoid::Document end + + class Animal + include Mongoid::Document + end + + class Dog < Animal + end + + class Cat < Animal + end else require "active_record" # for debugging # ActiveRecord::Base.logger = Logger.new(STDOUT) @@ -47,18 +57,32 @@ t.decimal :latitude, precision: 10, scale: 7 t.decimal :longitude, precision: 10, scale: 7 t.timestamps end - ActiveRecord::Migration.create_table :store, :force => true do |t| + ActiveRecord::Migration.create_table :stores, :force => true do |t| end + ActiveRecord::Migration.create_table :animals, :force => true do |t| + t.string :name + t.string :type + end + class Product < ActiveRecord::Base end class Store < ActiveRecord::Base end + + class Animal < ActiveRecord::Base + end + + class Dog < Animal + end + + class Cat < Animal + end end class Product belongs_to :store @@ -78,34 +102,40 @@ locations: ["location"] attr_accessor :conversions, :user_ids def search_data - to_hash.merge conversions: conversions, user_ids: user_ids, location: [latitude.to_f, longitude.to_f] + attributes.merge conversions: conversions, user_ids: user_ids, location: [latitude, longitude] end end -Product.tire.index.delete if Product.tire.index.exists? +class Animal + searchkick +end + +Product.searchkick_index.delete if Product.searchkick_index.exists? Product.reindex Product.reindex # run twice for both index paths +Animal.reindex + class MiniTest::Unit::TestCase def setup Product.destroy_all end protected - def store(documents) + def store(documents, klass = Product) documents.shuffle.each do |document| - Product.create!(document) + klass.create!(document) end - Product.tire.index.refresh + klass.searchkick_index.refresh end - def store_names(names) - store names.map{|name| {name: name} } + 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