Commit e1c350ba6c424767e12c8c1481bd7710da673ea2

Authored by Andrew Kane
1 parent d474a69a

Fixes for Mongoid 4

.travis.yml
... ... @@ -15,3 +15,4 @@ notifications:
15 15 gemfile:
16 16 - Gemfile
17 17 - gemfiles/mongoid3.gemfile
  18 + - gemfiles/mongoid4.gemfile
... ...
Gemfile
... ... @@ -3,7 +3,5 @@ source 'https://rubygems.org'
3 3 # Specify your gem's dependencies in searchkick.gemspec
4 4 gemspec
5 5  
6   -# gem "mongoid", github: "mongoid/mongoid"
7   -# gem "mongoid", "~> 3.1.0"
8 6 # gem "activerecord", "~> 3.2.0"
9 7 # gem "activerecord", "~> 3.1.0"
... ...
gemfiles/mongoid4.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", github: "mongoid/mongoid"
... ...
lib/searchkick/model.rb
... ... @@ -43,6 +43,9 @@ module Searchkick
43 43 # stringify fields
44 44 source = source.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
45 45  
  46 + # Mongoid 4 hack
  47 + source["_id"] = source["_id"].to_s if source["_id"]
  48 +
46 49 options = self.class.searchkick_options
47 50  
48 51 # conversions
... ...
searchkick.gemspec
... ... @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23 23  
24 24 spec.add_development_dependency "bundler", "~> 1.3"
25 25 spec.add_development_dependency "rake"
26   - spec.add_development_dependency "minitest"
  26 + spec.add_development_dependency "minitest", "~> 4.7"
27 27 spec.add_development_dependency "activerecord"
28 28 spec.add_development_dependency "pg"
29 29 end
... ...
test/autocomplete_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestAutocomplete < Minitest::Test
  3 +class TestAutocomplete < Minitest::Unit::TestCase
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::Test
  3 +class TestBoost < Minitest::Unit::TestCase
4 4  
5 5 # conversions
6 6  
... ...
test/facets_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestFacets < Minitest::Test
  3 +class TestFacets < Minitest::Unit::TestCase
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::Test
  3 +class TestHighlight < Minitest::Unit::TestCase
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::Test
  3 +class TestIndex < Minitest::Unit::TestCase
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::Test
  3 +class TestInheritance < Minitest::Unit::TestCase
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::Test
  5 +class TestMatch < Minitest::Unit::TestCase
6 6  
7 7 # exact
8 8  
... ...
test/similar_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestSimilar < Minitest::Test
  3 +class TestSimilar < Minitest::Unit::TestCase
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::Test
  3 +class TestSql < Minitest::Unit::TestCase
4 4  
5 5 def test_limit
6 6 store_names ["Product A", "Product B", "Product C", "Product D"]
... ... @@ -87,7 +87,7 @@ class TestSql &lt; Minitest::Test
87 87 def test_where_id
88 88 store_names ["Product A"]
89 89 product = Product.last
90   - assert_search "product", ["Product A"], where: {id: product.id}
  90 + assert_search "product", ["Product A"], where: {id: product.id.to_s}
91 91 end
92 92  
93 93 def test_near
... ...
test/suggest_test.rb
1 1 require_relative "test_helper"
2 2  
3   -class TestSuggest < Minitest::Test
  3 +class TestSuggest < Minitest::Unit::TestCase
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::Test
  3 +class TestSynonyms < Minitest::Unit::TestCase
4 4  
5 5 def test_bleach
6 6 store_names ["Clorox Bleach", "Kroger Bleach"]
... ...
test/test_helper.rb
... ... @@ -18,8 +18,15 @@ if defined?(Mongoid)
18 18  
19 19 class Product
20 20 include Mongoid::Document
21   - # include Mongoid::Attributes::Dynamic
22   -
  21 + include Mongoid::Timestamps
  22 +
  23 + field :name
  24 + field :store_id, type: Integer
  25 + field :in_stock, type: Boolean
  26 + field :backordered, type: Boolean
  27 + field :orders_count, type: Integer
  28 + field :price, type: Integer
  29 + field :color
23 30 field :latitude, type: BigDecimal
24 31 field :longitude, type: BigDecimal
25 32 end
... ... @@ -30,6 +37,8 @@ if defined?(Mongoid)
30 37  
31 38 class Animal
32 39 include Mongoid::Document
  40 +
  41 + field :name
33 42 end
34 43  
35 44 class Dog < Animal
... ... @@ -122,7 +131,7 @@ Product.reindex # run twice for both index paths
122 131  
123 132 Animal.reindex
124 133  
125   -class Minitest::Test
  134 +class Minitest::Unit::TestCase
126 135  
127 136 def setup
128 137 Product.destroy_all
... ...