Skip to content
Snippets Groups Projects
Commit 7c344826 authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge pull request #265 from petergoldstein/feature/mongoid_3_0_x_compatibility

Update code to account for Mongoid 3.0.x changes with backwards compatibility
parents 335e79b9 cbe663a0
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,14 @@ module Geocoder ...@@ -17,8 +17,14 @@ module Geocoder
def geocoder_init(options) def geocoder_init(options)
super(options) super(options)
if options[:skip_index] == false if options[:skip_index] == false
index [[ geocoder_options[:coordinates], Mongo::GEO2D ]], # create 2d index
:min => -180, :max => 180 # create 2d index if (::Mongoid::VERSION >= "3")
index({ geocoder_options[:coordinates].to_sym => '2d' },
{:min => -180, :max => 180})
else
index [[ geocoder_options[:coordinates], '2d' ]],
:min => -180, :max => 180
end
end end
end end
end end
......
...@@ -17,7 +17,8 @@ class MongoidTest < Test::Unit::TestCase ...@@ -17,7 +17,8 @@ class MongoidTest < Test::Unit::TestCase
def test_custom_coordinate_field_near_scope def test_custom_coordinate_field_near_scope
location = [40.750354, -73.993371] location = [40.750354, -73.993371]
p = Place.near(location) p = Place.near(location)
assert_equal p.selector[:location]['$nearSphere'], location.reverse key = Mongoid::VERSION >= "3" ? "location" : :location
assert_equal p.selector[key]['$nearSphere'], location.reverse
end end
def test_model_configuration def test_model_configuration
......
...@@ -7,8 +7,12 @@ require 'geocoder/models/mongoid' ...@@ -7,8 +7,12 @@ require 'geocoder/models/mongoid'
$LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
Mongoid.configure do |config| if (::Mongoid::VERSION >= "3")
config.logger = Logger.new($stderr, :debug) Mongoid.logger = Logger.new($stderr, :debug)
else
Mongoid.configure do |config|
config.logger = Logger.new($stderr, :debug)
end
end end
## ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment