mongoid_geospatial 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. data/Gemfile +5 -4
  2. data/Guardfile +24 -0
  3. data/README.md +9 -3
  4. data/lib/mongoid_geospatial/{contexts → contextual}/mongo.rb +11 -6
  5. data/lib/mongoid_geospatial/criterion/complex.rb +7 -0
  6. data/lib/mongoid_geospatial/criterion/inclusion.rb +12 -12
  7. data/lib/mongoid_geospatial/extensions/rgeo_spherical_point_impl.rb +13 -0
  8. data/lib/mongoid_geospatial/fields/line_string.rb +7 -6
  9. data/lib/mongoid_geospatial/fields/point.rb +24 -11
  10. data/lib/mongoid_geospatial/fields/polygon.rb +14 -10
  11. data/lib/mongoid_geospatial/geospatial/geo_near_results.rb +1 -1
  12. data/lib/mongoid_geospatial/geospatial.rb +1 -29
  13. data/lib/mongoid_geospatial/version.rb +1 -1
  14. data/lib/mongoid_geospatial.rb +9 -5
  15. data/mongoid_geospatial.gemspec +4 -5
  16. data/spec/models/address.rb +19 -14
  17. data/spec/models/bar.rb +3 -1
  18. data/spec/models/event.rb +2 -2
  19. data/spec/models/farm.rb +3 -4
  20. data/spec/models/person.rb +18 -60
  21. data/spec/models/phone.rb +3 -1
  22. data/spec/models/river.rb +2 -2
  23. data/spec/{functional/contexts → mongoid_geospatial/contextual}/mongo_spec.rb +16 -8
  24. data/spec/mongoid_geospatial/criterion/inclusion_spec.rb +375 -0
  25. data/spec/mongoid_geospatial/fields/point_spec.rb +34 -0
  26. data/spec/mongoid_geospatial/fields/polygon_spec.rb +6 -0
  27. data/spec/{functional → mongoid_geospatial}/geospatial/geo_near_results_spec.rb +0 -0
  28. data/spec/mongoid_geospatial/geospatial_spec.rb +2 -0
  29. data/spec/mongoid_geospatial/mongoid_geospatial_spec.rb +83 -0
  30. data/spec/spec_helper.rb +36 -20
  31. data/spec/support/authentication.rb +23 -23
  32. metadata +23 -161
  33. data/spec/functional/criterion/inclusion_spec.rb +0 -360
  34. data/spec/functional/mongoid_geospatial_spec.rb +0 -54
  35. data/spec/models/account.rb +0 -19
  36. data/spec/models/acolyte.rb +0 -9
  37. data/spec/models/address_component.rb +0 -5
  38. data/spec/models/agent.rb +0 -10
  39. data/spec/models/alert.rb +0 -5
  40. data/spec/models/animal.rb +0 -21
  41. data/spec/models/answer.rb +0 -4
  42. data/spec/models/birthday.rb +0 -13
  43. data/spec/models/book.rb +0 -5
  44. data/spec/models/business.rb +0 -7
  45. data/spec/models/callbacks.rb +0 -57
  46. data/spec/models/category.rb +0 -13
  47. data/spec/models/circus.rb +0 -7
  48. data/spec/models/comment.rb +0 -13
  49. data/spec/models/country_code.rb +0 -6
  50. data/spec/models/description.rb +0 -11
  51. data/spec/models/division.rb +0 -5
  52. data/spec/models/drug.rb +0 -5
  53. data/spec/models/employer.rb +0 -5
  54. data/spec/models/entry.rb +0 -6
  55. data/spec/models/favorite.rb +0 -6
  56. data/spec/models/fruits.rb +0 -11
  57. data/spec/models/game.rb +0 -18
  58. data/spec/models/ghost.rb +0 -7
  59. data/spec/models/house.rb +0 -4
  60. data/spec/models/inheritance.rb +0 -90
  61. data/spec/models/league.rb +0 -5
  62. data/spec/models/location.rb +0 -5
  63. data/spec/models/login.rb +0 -6
  64. data/spec/models/membership.rb +0 -4
  65. data/spec/models/mixed_drink.rb +0 -4
  66. data/spec/models/name.rb +0 -13
  67. data/spec/models/namespacing.rb +0 -11
  68. data/spec/models/observed.rb +0 -41
  69. data/spec/models/override.rb +0 -16
  70. data/spec/models/owner.rb +0 -6
  71. data/spec/models/page.rb +0 -5
  72. data/spec/models/page_question.rb +0 -4
  73. data/spec/models/paranoid_post.rb +0 -18
  74. data/spec/models/parents.rb +0 -32
  75. data/spec/models/patient.rb +0 -15
  76. data/spec/models/pet.rb +0 -7
  77. data/spec/models/pet_owner.rb +0 -6
  78. data/spec/models/player.rb +0 -23
  79. data/spec/models/post.rb +0 -26
  80. data/spec/models/preference.rb +0 -9
  81. data/spec/models/question.rb +0 -8
  82. data/spec/models/quiz.rb +0 -6
  83. data/spec/models/rating.rb +0 -8
  84. data/spec/models/role.rb +0 -5
  85. data/spec/models/service.rb +0 -6
  86. data/spec/models/shelf.rb +0 -5
  87. data/spec/models/slave_address_numbers.rb +0 -14
  88. data/spec/models/survey.rb +0 -5
  89. data/spec/models/tag.rb +0 -6
  90. data/spec/models/tracking_id_validation_history.rb +0 -25
  91. data/spec/models/translation.rb +0 -5
  92. data/spec/models/tree.rb +0 -9
  93. data/spec/models/user.rb +0 -9
  94. data/spec/models/user_account.rb +0 -10
  95. data/spec/models/vet_visit.rb +0 -5
  96. data/spec/models/video.rb +0 -9
  97. data/spec/models/wiki_page.rb +0 -6
data/Gemfile CHANGED
@@ -1,11 +1,12 @@
1
1
  source 'http://rubygems.org'
2
-
3
- # Specify gem's dependencies in mongoid_geospatial.gemspec
4
- gemspec
2
+ gemspec # Specify gem's dependencies in mongoid_geospatial.gemspec
5
3
 
6
4
  gem 'rgeo'
5
+ gem 'mongoid', '~> 3.0'
7
6
 
8
7
  group :development do
9
8
  gem 'rspec'
10
- gem 'fuubar'
9
+ gem 'guard-rspec'
10
+ gem 'pry'
11
+ # gem 'fuubar'
11
12
  end
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ require 'guard'
4
+
5
+ guard 'rspec', :version => 2 do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { "spec" } # { |m| "spec spec/lib/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+
10
+ # Rails example
11
+ # watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ # watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ # watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
14
+ # watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
15
+ # watch('config/routes.rb') { "spec/routing" }
16
+ # watch('app/controllers/application_controller.rb') { "spec/controllers" }
17
+
18
+ # Capybara request specs
19
+ # watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
20
+
21
+ # Turnip features and steps
22
+ # watch(%r{^spec/acceptance/(.+)\.feature$})
23
+ # watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
24
+ end
data/README.md CHANGED
@@ -4,9 +4,16 @@ Mongoid Geospatial
4
4
  A Mongoid Extension that simplifies and adds support for MongoDB and
5
5
  RGeo Spatial Calculations.
6
6
 
7
- *WARNING* There are no plans to support MongoDB < 2.0.
7
+ ** On beta again **
8
+
9
+ Removing some trash, improving and adding support for RGeo and GeoRuby.
10
+ Version 2+ is going to be beta testing, when it's ready I'll release v3,
11
+ So the major version stays the same as mongoid.
12
+
13
+
14
+ There are no plans to support MongoDB < 2.0
15
+ There are no plans to support Mongoid <= 2.0
8
16
 
9
- *WARNING* Experimental Mongoid 3.0 support.
10
17
 
11
18
 
12
19
  Quick Start
@@ -335,4 +342,3 @@ Copyright
335
342
  -----------
336
343
  Copyright (c) 2011 Ryan Ong. See LICENSE.txt for
337
344
  further details.
338
-
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
- module Contexts #:nodoc:
3
+ module Contextual #:nodoc:
4
4
  class Mongo #:nodoc:
5
5
 
6
6
  # Fetches rows from the data base sorted by distance.
@@ -31,7 +31,7 @@ module Mongoid #:nodoc:
31
31
  #
32
32
  # @return [ Array ] Sorted Rows
33
33
  def geo_near(center, opts = {})
34
- opts = self.options.merge(opts)
34
+ opts = self.criteria.options.merge(opts)
35
35
  # convert point
36
36
  center = center.to_xy if center.respond_to?(:to_xy)
37
37
  center = [center.x, center.y] if center.respond_to?(:x)
@@ -68,7 +68,8 @@ module Mongoid #:nodoc:
68
68
 
69
69
  end
70
70
  opts[:query] = create_geo_near_query(center,opts)
71
- results = klass.db.command(opts[:query])
71
+ results = klass.mongo_session.command(opts[:query])
72
+
72
73
  Mongoid::Geospatial::GeoNearResults.new(klass,results,opts)
73
74
  end
74
75
 
@@ -76,7 +77,7 @@ module Mongoid #:nodoc:
76
77
 
77
78
  def create_geo_near_query(center,opts)
78
79
  # minimum query
79
- query = BSON::OrderedHash.new
80
+ query = {}
80
81
  query[:geoNear] = klass.collection_name
81
82
  query[:near] = center
82
83
 
@@ -92,8 +93,8 @@ module Mongoid #:nodoc:
92
93
  # allow the use of complex werieis
93
94
  if opts[:query]
94
95
  query['query'] = self.criteria.where(opts[:query]).selector
95
- elsif self.selector != {}
96
- query['query'] = self.selector
96
+ elsif self.criteria.selector != {}
97
+ query['query'] = self.criteria.selector
97
98
  end
98
99
 
99
100
  if opts[:max_distance]
@@ -101,6 +102,10 @@ module Mongoid #:nodoc:
101
102
  query['maxDistance'] = query['maxDistance']/opts[:unit].to_f if opts[:unit]
102
103
  end
103
104
 
105
+ if opts[:unique_docs]
106
+ query['uniqueDocs'] = true
107
+ end
108
+
104
109
  query['spherical'] = true if opts[:spherical]
105
110
 
106
111
  # mongodb < 1.7 returns degrees but with earth flat. in Mongodb 1.7 you can set sphere and let mongodb calculate the distance in Miles or KM
@@ -10,6 +10,13 @@ module Mongoid #:nodoc:
10
10
  # becomes:
11
11
  # <tt> { :field.lt => "value }</tt>
12
12
  class Complex
13
+
14
+ attr_accessor :key, :operator
15
+
16
+ def initialize(opts = {})
17
+ @key, @operator = opts[:key], opts[:operator]
18
+ end
19
+
13
20
 
14
21
  def to_mongo_query v
15
22
  {"$#{operator}" => v}
@@ -1,14 +1,14 @@
1
1
  # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module Criterion #:nodoc:
4
- module Inclusion
5
- def near(attributes = {})
6
- update_selector(attributes, "$near")
7
- end
2
+ # module Mongoid #:nodoc:
3
+ # module Criterion #:nodoc:
4
+ # module Inclusion
5
+ # def near(attributes = {})
6
+ # update_selector(attributes, "$near")
7
+ # end
8
8
 
9
- def near_sphere(attributes = {})
10
- update_selector(attributes, "$near")
11
- end
12
- end
13
- end
14
- end
9
+ # def near_sphere(attributes = {})
10
+ # update_selector(attributes, "$near")
11
+ # end
12
+ # end
13
+ # end
14
+ # end
@@ -0,0 +1,13 @@
1
+ module RGeo
2
+ module Geographic
3
+ class SphericalPointImpl
4
+ def to_a
5
+ [x, y, z]
6
+ end
7
+
8
+ def [] index
9
+ to_a[index]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,15 +2,16 @@ module Mongoid
2
2
  module Geospatial
3
3
  class LineString
4
4
 
5
- def mongoize(object)
6
- RGeo::Geographic.spherical_factory.line_string *object
7
- end
8
-
9
- def demongoize(object)
10
- object.to_a
5
+ def mongoize
6
+ to_a
11
7
  end
12
8
 
9
+ class << self
10
+ def demongoize(object)
11
+ RGeo::Geographic.spherical_factory.line_string object
12
+ end
13
13
 
14
+ end
14
15
  end
15
16
  end
16
17
  end
@@ -2,19 +2,32 @@ module Mongoid
2
2
  module Geospatial
3
3
  class Point
4
4
 
5
- def mongoize(object)
6
- return unless object && !object.empty?
7
- RGeo::Geographic.spherical_factory.point *object
8
- #["x"], object["y"]
5
+ def mongoize
6
+ [x, y]
9
7
  end
10
8
 
11
- def demongoize(object)
12
- object.respond_to?(:x) ? [object.x, object.y] : object
13
- # if object.respond_to? :x
14
- # { "x" => object.x, "y" => object.y }
15
- # else
16
- # { "x" => object[0], "y" => object[1] }
17
- # end
9
+ class << self
10
+
11
+ def demongoize(object)
12
+ return unless object && !object.empty?
13
+ RGeo::Geographic.spherical_factory.point *object
14
+ #["x"], object["y"]
15
+ end
16
+
17
+ def mongoize(object)
18
+ #return new.mongoize if object.respond_to?(:x)
19
+ case object
20
+ when Point then object.mongoize
21
+ when Hash then [object[:x], object[:y]]
22
+ else object
23
+ end
24
+ end
25
+
26
+ # Converts the object that was supplied to a criteria and converts it
27
+ # into a database friendly form.
28
+ def evolve(object)
29
+ object.respond_to?(:x) ? object.mongoize : object
30
+ end
18
31
  end
19
32
 
20
33
  # - self.spacial_fields ||= []
@@ -2,19 +2,23 @@ module Mongoid
2
2
  module Geospatial
3
3
  class Polygon
4
4
 
5
- def mongoize(object)
6
- points = object.map do |pair|
7
- RGeo::Geographic.spherical_factory.point *pair
8
- end
9
- ring = RGeo::Geographic.spherical_factory.linear_ring points
10
- RGeo::Geographic.spherical_factory.polygon ring
11
- end
12
-
13
- def demongoize(object)
14
- object #.flatten
5
+ def mongoize
6
+ self #.flatten
15
7
  end
16
8
 
9
+ class << self
10
+ def demongoize(object)
11
+ points = object.map do |pair|
12
+ RGeo::Geographic.spherical_factory.point *pair
13
+ end
14
+ ring = RGeo::Geographic.spherical_factory.linear_ring points
15
+ RGeo::Geographic.spherical_factory.polygon ring
16
+ end
17
17
 
18
+ # def evolve(object)
19
+ # { "$gte" => object.first, "$lte" => object.last }
20
+ # end
21
+ end
18
22
  end
19
23
  end
20
24
  end
@@ -113,7 +113,7 @@ module Mongoid
113
113
  alias_method :per_page, :limit_value
114
114
 
115
115
  def num_pages
116
- (self.total_entries && @opts[:per_page]) ? (total_entries.to_f / @opts[:per_page]).ceil : nil
116
+ (total_entries && @opts[:per_page]) ? (total_entries.to_f / @opts[:per_page]).ceil : nil
117
117
  end
118
118
  alias_method :total_pages, :num_pages
119
119
 
@@ -54,37 +54,9 @@ module Mongoid
54
54
 
55
55
  def spatial_index name, options = {}
56
56
  self.spatial_fields_indexed << name
57
- if Mongoid::VERSION =~ /3.0/
58
- index name => '2d', :options => options
59
- else
60
- index [[name, '2d']], options
61
- end
57
+ index({name => '2d'}, options)
62
58
  end
63
59
  end
64
60
 
65
- # def distance(p2, opts = {})
66
- # p1 = self.send(key)
67
- # Mongoid::Geospatial.distance(p1, p2, opts)
68
- # end
69
-
70
-
71
-
72
- # def self.distance(p1,p2,opts = {})
73
- # opts[:formula] ||= (opts[:spherical]) ? @@spherical_distance_formula : :pythagorean_theorem
74
- # p1 = p1.to_lng_lat if p1.respond_to?(:to_lng_lat)
75
- # p2 = p2.to_lng_lat if p2.respond_to?(:to_lng_lat)
76
-
77
- # rads = Formulas.send(opts[:formula], p1, p2)
78
-
79
- # if unit = earth_radius[opts[:unit]]
80
- # opts[:unit] = (rads.instance_variable_get("@radian")) ? unit : unit * RAD_PER_DEG
81
- # end
82
-
83
- # rads *= opts[:unit].to_f if opts[:unit]
84
- # rads
85
-
86
- # end
87
-
88
-
89
61
  end
90
62
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Geospatial
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -2,13 +2,17 @@ require 'rgeo'
2
2
  require 'mongoid'
3
3
  require 'active_support/core_ext/string/inflections'
4
4
  require 'active_support/concern'
5
- require 'mongoid_geospatial/contexts/mongo'
5
+ require 'mongoid_geospatial/contextual/mongo'
6
6
  require 'mongoid_geospatial/criteria'
7
7
  require 'mongoid_geospatial/extensions/symbol'
8
+ require 'mongoid_geospatial/extensions/rgeo_spherical_point_impl'
8
9
  require 'mongoid_geospatial/field_option'
9
- require 'mongoid_geospatial/fields/point'
10
- require 'mongoid_geospatial/fields/polygon'
11
- require 'mongoid_geospatial/fields/line_string'
10
+
11
+ fields_path = 'mongoid_geospatial/fields'
12
+
13
+ %w{point polygon line_string}.each do |type|
14
+ require "#{fields_path}/#{type}"
15
+ end
16
+
12
17
  require 'mongoid_geospatial/finders'
13
18
  require 'mongoid_geospatial/geospatial'
14
-
@@ -16,12 +16,11 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Mongoid::Geospatial::VERSION
17
17
 
18
18
 
19
- gem.add_dependency('rgeo', ['>= 0.3.5'])
20
- gem.add_dependency('mongoid', ['>= 2.0.0'])
21
- gem.add_dependency('activesupport', ["~> 3.0"])
19
+ gem.add_dependency('rgeo', ['>= 0.3.15'])
20
+ gem.add_dependency('mongoid', ['>= 3.0.0'])
21
+ gem.add_dependency('activesupport', ["~> 3.2"])
22
22
  gem.add_development_dependency('yard', ["~>0.6.0"])
23
- gem.add_development_dependency('rspec', ['~>2.3'])
24
- gem.add_development_dependency('rcov', ['>= 0'])
23
+ gem.add_development_dependency('rspec', ['~>2.11'])
25
24
  gem.add_development_dependency('mocha', ['>= 0'])
26
25
  gem.add_development_dependency('will_paginate', ['>= 0'])
27
26
  gem.add_development_dependency('kaminari', ['>= 0'])
@@ -1,21 +1,26 @@
1
1
  class Address
2
2
  include Mongoid::Document
3
3
 
4
+ field :_id, type: String, default: ->{ street.try(:parameterize) }
5
+
4
6
  attr_accessor :mode
5
7
 
6
8
  field :address_type
7
- field :number, :type => Integer
9
+ field :number, type: Integer
8
10
  field :street
9
11
  field :city
10
12
  field :state
11
13
  field :post_code
12
14
  field :parent_title
13
- field :services, :type => Array
14
- field :latlng, :type => Array
15
- key :street
16
- embeds_many :locations
15
+ field :services, type: Array
16
+ field :latlng, type: Array
17
+ field :map, type: Hash
18
+
19
+ embeds_many :locations, validate: false
20
+ embeds_one :code, validate: false
21
+ embeds_one :target, as: :targetable, validate: false
17
22
 
18
- embedded_in :addressable, :polymorphic => true do
23
+ embedded_in :addressable, polymorphic: true do
19
24
  def extension
20
25
  "Testing"
21
26
  end
@@ -24,19 +29,19 @@ class Address
24
29
  end
25
30
  end
26
31
 
27
- accepts_nested_attributes_for :locations
32
+ accepts_nested_attributes_for :locations, :code, :target
28
33
 
29
- referenced_in :account
34
+ belongs_to :account
30
35
 
31
- scope :without_postcode, where(:postcode => nil)
32
- named_scope :rodeo, where(:street => "Rodeo Dr") do
36
+ scope :without_postcode, where(postcode: nil)
37
+ scope :rodeo, where(street: "Rodeo Dr") do
33
38
  def mansion?
34
39
  all? { |address| address.street == "Rodeo Dr" }
35
40
  end
36
41
  end
37
42
 
38
- validates_presence_of :street, :on => :update
39
- validates_format_of :street, :with => /\D/, :allow_nil => true
43
+ validates_presence_of :street, on: :update
44
+ validates_format_of :street, with: /\D/, allow_nil: true
40
45
 
41
46
  def set_parent=(set = false)
42
47
  self.parent_title = addressable.title if set
@@ -48,11 +53,11 @@ class Address
48
53
 
49
54
  class << self
50
55
  def california
51
- where(:state => "CA")
56
+ where(state: "CA")
52
57
  end
53
58
 
54
59
  def homes
55
- where(:address_type => "Home")
60
+ where(address_type: "Home")
56
61
  end
57
62
 
58
63
  def streets
data/spec/models/bar.rb CHANGED
@@ -4,6 +4,8 @@ class Bar
4
4
 
5
5
  field :name, :type => String
6
6
  field :location, :type => Point, :spatial => true
7
- references_one :rating, :as => :ratable
7
+
8
+ has_one :rating, :as => :ratable
9
+
8
10
  spatial_index :location
9
11
  end
data/spec/models/event.rb CHANGED
@@ -3,12 +3,12 @@ class Event
3
3
 
4
4
  field :title
5
5
  field :date, :type => Date
6
- references_and_referenced_in_many \
6
+ has_and_belongs_to_many \
7
7
  :administrators,
8
8
  :class_name => 'Person',
9
9
  :inverse_of => :administrated_events,
10
10
  :dependent => :nullify
11
- referenced_in :owner
11
+ belongs_to :owner
12
12
 
13
13
  def self.each_day(start_date, end_date)
14
14
  groups = only(:date).asc(:date).where(:date.gte => start_date, :date.lte => end_date).group
data/spec/models/farm.rb CHANGED
@@ -2,9 +2,8 @@ class Farm
2
2
  include Mongoid::Document
3
3
  include Mongoid::Geospatial
4
4
 
5
- field :name, :type => String
6
- #field :location, :type => Point #, :spatial => true
7
- field :area, :type => Polygon
5
+ field :name, type: String
6
+ field :area, type: Polygon, spatial: true
8
7
 
9
- #spatial_index :location
8
+ spatial_index :area
10
9
  end
@@ -25,14 +25,14 @@ class Person
25
25
  field :owner_id, :type => Integer
26
26
  field :security_code
27
27
  field :reading, :type => Object
28
- field :bson_id, :type => BSON::ObjectId
28
+ field :bson_id, :type => bson_object_id_class
29
29
 
30
- index :age
31
- index :addresses
32
- index :dob
33
- index :name
34
- index :title
35
- index :ssn, :unique => true
30
+ index age: 1
31
+ index addresses: 1
32
+ index dob: 1
33
+ index name: 1
34
+ index title: 1
35
+ index({ssn: 1}, :unique => true)
36
36
 
37
37
  validates_format_of :ssn, :without => /\$\$\$/
38
38
 
@@ -40,9 +40,6 @@ class Person
40
40
 
41
41
  attr_protected :security_code, :owner_id
42
42
 
43
- embeds_many :favorites, :order => :title.desc, :inverse_of => :perp
44
- embeds_many :videos, :order => [[ :title, :asc ]]
45
- embeds_many :phone_numbers, :class_name => "Phone"
46
43
  embeds_many :addresses, :as => :addressable do
47
44
  def extension
48
45
  "Testing"
@@ -51,61 +48,22 @@ class Person
51
48
  @target.select { |doc| doc.street == street }
52
49
  end
53
50
  end
54
- embeds_many :address_components
55
- embeds_many :services
56
51
 
57
- embeds_one :pet, :class_name => "Animal"
58
- embeds_one :name, :as => :namable do
59
- def extension
60
- "Testing"
61
- end
62
- def dawkins?
63
- first_name == "Richard" && last_name == "Dawkins"
64
- end
65
- end
66
- embeds_one :quiz
52
+ # embeds_many :services
53
+
54
+
55
+ # has_many \
56
+ # :posts,
57
+ # :dependent => :delete,
58
+ # :order => :rating.desc do
59
+ # def extension
60
+ # "Testing"
61
+ # end
62
+ # end
67
63
 
68
64
  accepts_nested_attributes_for :addresses
69
65
  accepts_nested_attributes_for :name, :update_only => true
70
- accepts_nested_attributes_for :pet, :allow_destroy => true
71
- accepts_nested_attributes_for :game, :allow_destroy => true
72
- accepts_nested_attributes_for :favorites, :allow_destroy => true, :limit => 5
73
- accepts_nested_attributes_for :posts
74
- accepts_nested_attributes_for :preferences
75
- accepts_nested_attributes_for :quiz
76
-
77
- references_one :game, :dependent => :destroy do
78
- def extension
79
- "Testing"
80
- end
81
- end
82
66
 
83
- references_many \
84
- :posts,
85
- :dependent => :delete,
86
- :order => :rating.desc do
87
- def extension
88
- "Testing"
89
- end
90
- end
91
- references_many :paranoid_posts
92
- references_and_referenced_in_many \
93
- :preferences,
94
- :index => true,
95
- :dependent => :nullify,
96
- :autosave => true,
97
- :order => :value.desc
98
- references_and_referenced_in_many :user_accounts
99
- references_and_referenced_in_many :houses
100
-
101
- references_many :drugs, :autosave => true
102
- references_one :account, :autosave => true
103
-
104
- references_and_referenced_in_many \
105
- :administrated_events,
106
- :class_name => 'Event',
107
- :inverse_of => :administrators,
108
- :dependent => :nullify
109
67
 
110
68
  scope :minor, where(:age.lt => 18)
111
69
  scope :without_ssn, without(:ssn)
data/spec/models/phone.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  class Phone
2
2
  include Mongoid::Document
3
3
  field :number
4
- key :number
4
+ if Mongoid::VERSION < '3'
5
+ key :number
6
+ end
5
7
  embeds_one :country_code
6
8
  embedded_in :person
7
9
  end
data/spec/models/river.rb CHANGED
@@ -5,9 +5,9 @@ class River
5
5
  field :name, type: String
6
6
  field :length, type: Integer
7
7
  field :average_discharge, type: Integer
8
- field :source, type: Array, spatial: true
8
+ field :source, type: LineString, spatial: true
9
9
  # set return_array to true if you do not want a hash returned all the time
10
- field :mouth, type: Array, spatial: {lat: 'latitude', lng: 'longitude'}
10
+ field :mouth, type: Point, spatial: {lat: 'latitude', lng: 'longitude'}
11
11
  field :mouth_array, type: Array, spatial: {return_array: true}
12
12
 
13
13
  # simplified spatial indexing