Commit d4c1f2bc6522f84e70a6b05310c667438de0883d

Authored by Andrew Kane
1 parent a92c6987

Fixed Mongoid 3 tests

.gitignore
... ... @@ -3,7 +3,7 @@
3 3 .bundle
4 4 .config
5 5 .yardoc
6   -Gemfile.lock
  6 +*.lock
7 7 InstalledFiles
8 8 _yardoc
9 9 coverage
... ...
.travis.yml
... ... @@ -11,3 +11,6 @@ notifications:
11 11 email:
12 12 on_success: never
13 13 on_failure: change
  14 +gemfile:
  15 + - Gemfile
  16 + - gemfiles/mongoid3.gemfile
... ...
gemfiles/mongoid3.gemfile 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +source 'https://rubygems.org'
  2 +
  3 +# Specify your gem's dependencies in searchkick.gemspec
  4 +gemspec path: "../"
  5 +
  6 +gem "mongoid", "~> 3.1.0"
... ...
lib/searchkick/model.rb
... ... @@ -90,6 +90,8 @@ module Searchkick
90 90  
91 91 cast_big_decimal.call(source)
92 92  
  93 + # p search_data
  94 +
93 95 source.to_json
94 96 end
95 97  
... ...
lib/searchkick/search.rb
... ... @@ -161,6 +161,8 @@ module Searchkick
161 161 proc do |where|
162 162 filters = []
163 163 (where || {}).each do |field, value|
  164 + field = :_id if field.to_s == "id"
  165 +
164 166 if field == :or
165 167 value.each do |or_clause|
166 168 filters << {or: or_clause.map{|or_statement| {and: where_filters.call(or_statement)} }}
... ...
test/autocomplete_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestAutocomplete < Minitest::Unit::TestCase
  3 +class TestAutocomplete < Minitest::Test
4 4  
5 5 def test_autocomplete
6 6 store_names ["Hummus"]
... ...
test/boost_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestBoost < Minitest::Unit::TestCase
  3 +class TestBoost < Minitest::Test
4 4  
5 5 # conversions
6 6  
... ...
test/facets_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestFacets < Minitest::Unit::TestCase
  3 +class TestFacets < Minitest::Test
4 4  
5 5 def setup
6 6 super
... ...
test/highlight_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestHighlight < Minitest::Unit::TestCase
  3 +class TestHighlight < Minitest::Test
4 4  
5 5 def test_basic
6 6 store_names ["Two Door Cinema Club"]
... ...
test/index_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestIndex < Minitest::Unit::TestCase
  3 +class TestIndex < Minitest::Test
4 4  
5 5 def test_clean_indices
6 6 old_index = Tire::Index.new("products_test_20130801000000000")
... ...
test/inheritance_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestInheritance < Minitest::Unit::TestCase
  3 +class TestInheritance < Minitest::Test
4 4  
5 5 def setup
6 6 super
... ...
test/match_test.rb
... ... @@ -2,7 +2,7 @@
2 2  
3 3 require_relative "test_helper"
4 4  
5   -class TestMatch < Minitest::Unit::TestCase
  5 +class TestMatch < Minitest::Test
6 6  
7 7 # exact
8 8  
... ...
test/similar_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestSimilar < Minitest::Unit::TestCase
  3 +class TestSimilar < Minitest::Test
4 4  
5 5 def test_similar
6 6 store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"]
... ...
test/sql_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestSql < Minitest::Unit::TestCase
  3 +class TestSql < Minitest::Test
4 4  
5 5 def test_limit
6 6 store_names ["Product A", "Product B", "Product C", "Product D"]
... ... @@ -194,9 +194,12 @@ class TestSql &lt; Minitest::Unit::TestCase
194 194 assert_kind_of Tire::Results::Item, Product.search("product", load: false, include: [:store]).first
195 195 end
196 196  
197   - def test_include
198   - store_names ["Product A"]
199   - assert Product.search("product", include: [:store]).first.association(:store).loaded?
  197 + # TODO see if Mongoid is loaded
  198 + if !defined?(Mongoid)
  199 + def test_include
  200 + store_names ["Product A"]
  201 + assert Product.search("product", include: [:store]).first.association(:store).loaded?
  202 + end
200 203 end
201 204  
202 205 end
... ...
test/suggest_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestSuggest < Minitest::Unit::TestCase
  3 +class TestSuggest < Minitest::Test
4 4  
5 5 def test_basic
6 6 store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"]
... ...
test/synonyms_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestSynonyms < Minitest::Unit::TestCase
  3 +class TestSynonyms < Minitest::Test
4 4  
5 5 def test_bleach
6 6 store_names ["Clorox Bleach", "Kroger Bleach"]
... ...
test/test_helper.rb
... ... @@ -11,7 +11,7 @@ Tire.configure do
11 11 pretty true
12 12 end
13 13  
14   -if ENV["MONGOID"]
  14 +if defined?(Mongoid)
15 15 Mongoid.configure do |config|
16 16 config.connect_to "searchkick_test"
17 17 end
... ... @@ -19,6 +19,9 @@ if ENV[&quot;MONGOID&quot;]
19 19 class Product
20 20 include Mongoid::Document
21 21 # include Mongoid::Attributes::Dynamic
  22 +
  23 + field :latitude, type: BigDecimal
  24 + field :longitude, type: BigDecimal
22 25 end
23 26  
24 27 class Store
... ... @@ -105,7 +108,7 @@ class Product
105 108 attr_accessor :conversions, :user_ids
106 109  
107 110 def search_data
108   - attributes.merge conversions: conversions, user_ids: user_ids, location: [latitude, longitude], multiple_locations: [[latitude, longitude], [0, 0]]
  111 + serializable_hash.merge conversions: conversions, user_ids: user_ids, location: [latitude, longitude], multiple_locations: [[latitude, longitude], [0, 0]]
109 112 end
110 113 end
111 114  
... ... @@ -119,7 +122,7 @@ Product.reindex # run twice for both index paths
119 122  
120 123 Animal.reindex
121 124  
122   -class MiniTest::Unit::TestCase
  125 +class Minitest::Test
123 126  
124 127 def setup
125 128 Product.destroy_all
... ...