mongoid_geospatial 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -4
- data/Guardfile +24 -0
- data/README.md +9 -3
- data/lib/mongoid_geospatial/{contexts → contextual}/mongo.rb +11 -6
- data/lib/mongoid_geospatial/criterion/complex.rb +7 -0
- data/lib/mongoid_geospatial/criterion/inclusion.rb +12 -12
- data/lib/mongoid_geospatial/extensions/rgeo_spherical_point_impl.rb +13 -0
- data/lib/mongoid_geospatial/fields/line_string.rb +7 -6
- data/lib/mongoid_geospatial/fields/point.rb +24 -11
- data/lib/mongoid_geospatial/fields/polygon.rb +14 -10
- data/lib/mongoid_geospatial/geospatial/geo_near_results.rb +1 -1
- data/lib/mongoid_geospatial/geospatial.rb +1 -29
- data/lib/mongoid_geospatial/version.rb +1 -1
- data/lib/mongoid_geospatial.rb +9 -5
- data/mongoid_geospatial.gemspec +4 -5
- data/spec/models/address.rb +19 -14
- data/spec/models/bar.rb +3 -1
- data/spec/models/event.rb +2 -2
- data/spec/models/farm.rb +3 -4
- data/spec/models/person.rb +18 -60
- data/spec/models/phone.rb +3 -1
- data/spec/models/river.rb +2 -2
- data/spec/{functional/contexts → mongoid_geospatial/contextual}/mongo_spec.rb +16 -8
- data/spec/mongoid_geospatial/criterion/inclusion_spec.rb +375 -0
- data/spec/mongoid_geospatial/fields/point_spec.rb +34 -0
- data/spec/mongoid_geospatial/fields/polygon_spec.rb +6 -0
- data/spec/{functional → mongoid_geospatial}/geospatial/geo_near_results_spec.rb +0 -0
- data/spec/mongoid_geospatial/geospatial_spec.rb +2 -0
- data/spec/mongoid_geospatial/mongoid_geospatial_spec.rb +83 -0
- data/spec/spec_helper.rb +36 -20
- data/spec/support/authentication.rb +23 -23
- metadata +23 -161
- data/spec/functional/criterion/inclusion_spec.rb +0 -360
- data/spec/functional/mongoid_geospatial_spec.rb +0 -54
- data/spec/models/account.rb +0 -19
- data/spec/models/acolyte.rb +0 -9
- data/spec/models/address_component.rb +0 -5
- data/spec/models/agent.rb +0 -10
- data/spec/models/alert.rb +0 -5
- data/spec/models/animal.rb +0 -21
- data/spec/models/answer.rb +0 -4
- data/spec/models/birthday.rb +0 -13
- data/spec/models/book.rb +0 -5
- data/spec/models/business.rb +0 -7
- data/spec/models/callbacks.rb +0 -57
- data/spec/models/category.rb +0 -13
- data/spec/models/circus.rb +0 -7
- data/spec/models/comment.rb +0 -13
- data/spec/models/country_code.rb +0 -6
- data/spec/models/description.rb +0 -11
- data/spec/models/division.rb +0 -5
- data/spec/models/drug.rb +0 -5
- data/spec/models/employer.rb +0 -5
- data/spec/models/entry.rb +0 -6
- data/spec/models/favorite.rb +0 -6
- data/spec/models/fruits.rb +0 -11
- data/spec/models/game.rb +0 -18
- data/spec/models/ghost.rb +0 -7
- data/spec/models/house.rb +0 -4
- data/spec/models/inheritance.rb +0 -90
- data/spec/models/league.rb +0 -5
- data/spec/models/location.rb +0 -5
- data/spec/models/login.rb +0 -6
- data/spec/models/membership.rb +0 -4
- data/spec/models/mixed_drink.rb +0 -4
- data/spec/models/name.rb +0 -13
- data/spec/models/namespacing.rb +0 -11
- data/spec/models/observed.rb +0 -41
- data/spec/models/override.rb +0 -16
- data/spec/models/owner.rb +0 -6
- data/spec/models/page.rb +0 -5
- data/spec/models/page_question.rb +0 -4
- data/spec/models/paranoid_post.rb +0 -18
- data/spec/models/parents.rb +0 -32
- data/spec/models/patient.rb +0 -15
- data/spec/models/pet.rb +0 -7
- data/spec/models/pet_owner.rb +0 -6
- data/spec/models/player.rb +0 -23
- data/spec/models/post.rb +0 -26
- data/spec/models/preference.rb +0 -9
- data/spec/models/question.rb +0 -8
- data/spec/models/quiz.rb +0 -6
- data/spec/models/rating.rb +0 -8
- data/spec/models/role.rb +0 -5
- data/spec/models/service.rb +0 -6
- data/spec/models/shelf.rb +0 -5
- data/spec/models/slave_address_numbers.rb +0 -14
- data/spec/models/survey.rb +0 -5
- data/spec/models/tag.rb +0 -6
- data/spec/models/tracking_id_validation_history.rb +0 -25
- data/spec/models/translation.rb +0 -5
- data/spec/models/tree.rb +0 -9
- data/spec/models/user.rb +0 -9
- data/spec/models/user_account.rb +0 -10
- data/spec/models/vet_visit.rb +0 -5
- data/spec/models/video.rb +0 -9
- data/spec/models/wiki_page.rb +0 -6
@@ -1,54 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial do
|
4
|
-
|
5
|
-
it "should instantiate with no problems" do
|
6
|
-
Bar.create!(name: "Moe's")
|
7
|
-
Bar.count.should eql(1)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should have a field mapped as point" do
|
11
|
-
bar = Bar.create!(location: [5,5])
|
12
|
-
bar.location.should be_a RGeo::Geographic::SphericalPointImpl
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should accept an RGeo object" do
|
16
|
-
point = RGeo::Geographic.spherical_factory.point 1, 2
|
17
|
-
bar = Bar.create!(location: point)
|
18
|
-
bar.location.x.should be_within(0.1).of(1)
|
19
|
-
bar.location.y.should be_within(0.1).of(2)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should calculate distance between points" do
|
23
|
-
bar = Bar.create!(location: [5,5])
|
24
|
-
bar2 = Bar.create!(location: [15,15])
|
25
|
-
bar.location.distance(bar2.location).should be_within(1).of(1561283.8)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should calculate distance between points miles" do
|
29
|
-
pending
|
30
|
-
bar = Bar.create!(location: [5,5])
|
31
|
-
bar2 = Bar.create!(location: [15,15])
|
32
|
-
bar.location.distance(bar2.location).should be_within(1).of(1561283.8)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should calculate 3d distances by default" do
|
36
|
-
bar = Bar.create! location: [-73.77694444, 40.63861111 ]
|
37
|
-
bar2 = Bar.create! location: [-118.40, 33.94] #,:unit=>:mi, :spherical => true)
|
38
|
-
bar.location.distance(bar2.location).to_i.should be_within(1).of(2469)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should have a nice simple way to ovewrite geo factory" do
|
42
|
-
pending
|
43
|
-
bar = Bar.create!(location: [5,5])
|
44
|
-
bar2 = Bar.create!(location: [15,15])
|
45
|
-
bar.location.distance(bar2.location).should be_within(1).of(1561283.8)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should have a field mapped as polygon" do
|
49
|
-
farm = Farm.create!(area: [[5,5],[6,5],[6,6],[5,6]])
|
50
|
-
farm.area.should be_a RGeo::Geographic::SphericalPolygonImpl
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
end
|
data/spec/models/account.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class Account
|
2
|
-
include Mongoid::Document
|
3
|
-
field :number, :type => String
|
4
|
-
field :balance, :type => String
|
5
|
-
field :nickname, :type => String
|
6
|
-
field :name, :type => String
|
7
|
-
key :name
|
8
|
-
|
9
|
-
embeds_many :memberships
|
10
|
-
referenced_in :creator, :class_name => "User", :foreign_key => :creator_id
|
11
|
-
referenced_in :person
|
12
|
-
references_many :alerts
|
13
|
-
references_and_referenced_in_many :agents
|
14
|
-
|
15
|
-
attr_accessible :nickname, :name
|
16
|
-
|
17
|
-
validates_presence_of :name
|
18
|
-
validates_length_of :name, :maximum => 10, :on => :create
|
19
|
-
end
|
data/spec/models/acolyte.rb
DELETED
data/spec/models/agent.rb
DELETED
data/spec/models/alert.rb
DELETED
data/spec/models/animal.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Animal
|
2
|
-
include Mongoid::Document
|
3
|
-
field :name
|
4
|
-
field :tags, :type => Array
|
5
|
-
key :name
|
6
|
-
|
7
|
-
embedded_in :person
|
8
|
-
embedded_in :circus
|
9
|
-
|
10
|
-
validates_format_of :name, :without => /\$\$\$/
|
11
|
-
|
12
|
-
accepts_nested_attributes_for :person
|
13
|
-
|
14
|
-
def tag_list
|
15
|
-
tags.join(", ")
|
16
|
-
end
|
17
|
-
|
18
|
-
def tag_list=(_tag_list)
|
19
|
-
self.tags = _tag_list.split(",").map(&:strip)
|
20
|
-
end
|
21
|
-
end
|
data/spec/models/answer.rb
DELETED
data/spec/models/birthday.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Birthday
|
2
|
-
include Mongoid::Document
|
3
|
-
field :title
|
4
|
-
field :date, :type => Date
|
5
|
-
embedded_in :owner, :inverse_of => :birthdays
|
6
|
-
|
7
|
-
def self.each_day(start_date, end_date)
|
8
|
-
groups = only(:date).asc(:date).where(:date.gte => start_date, :date.lte => end_date).group
|
9
|
-
groups.each do |date, group|
|
10
|
-
yield(date, group)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/spec/models/book.rb
DELETED
data/spec/models/business.rb
DELETED
data/spec/models/callbacks.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
class Artist
|
2
|
-
include Mongoid::Document
|
3
|
-
field :name
|
4
|
-
embeds_many :songs
|
5
|
-
embeds_many :labels
|
6
|
-
|
7
|
-
before_create :before_create_stub
|
8
|
-
after_create :create_songs
|
9
|
-
before_save :before_save_stub
|
10
|
-
before_destroy :before_destroy_stub
|
11
|
-
|
12
|
-
protected
|
13
|
-
def before_create_stub
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
def before_save_stub
|
18
|
-
true
|
19
|
-
end
|
20
|
-
|
21
|
-
def before_destroy_stub
|
22
|
-
true
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_songs
|
26
|
-
2.times { |n| songs.create!(:title => "#{n}") }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Song
|
31
|
-
include Mongoid::Document
|
32
|
-
field :title
|
33
|
-
embedded_in :artist
|
34
|
-
end
|
35
|
-
|
36
|
-
class Label
|
37
|
-
include Mongoid::Document
|
38
|
-
field :name
|
39
|
-
embedded_in :artist
|
40
|
-
before_validation :cleanup
|
41
|
-
|
42
|
-
private
|
43
|
-
def cleanup
|
44
|
-
self.name = self.name.downcase.capitalize
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class ValidationCallback
|
49
|
-
include Mongoid::Document
|
50
|
-
field :history, :type => Array, :default => []
|
51
|
-
validate do
|
52
|
-
self.history << :validate
|
53
|
-
end
|
54
|
-
|
55
|
-
before_validation { self.history << :before_validation }
|
56
|
-
after_validation { self.history << :after_validation }
|
57
|
-
end
|
data/spec/models/category.rb
DELETED
data/spec/models/circus.rb
DELETED
data/spec/models/comment.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Comment
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Versioning
|
4
|
-
include Mongoid::Timestamps
|
5
|
-
field :title, :type => String
|
6
|
-
field :text, :type => String
|
7
|
-
key :text, :type => String
|
8
|
-
|
9
|
-
referenced_in :movie
|
10
|
-
referenced_in :rating
|
11
|
-
validates :title, :presence => true
|
12
|
-
validates :movie, :rating, :associated => true
|
13
|
-
end
|
data/spec/models/country_code.rb
DELETED
data/spec/models/description.rb
DELETED
data/spec/models/division.rb
DELETED
data/spec/models/drug.rb
DELETED
data/spec/models/employer.rb
DELETED
data/spec/models/entry.rb
DELETED
data/spec/models/favorite.rb
DELETED
data/spec/models/fruits.rb
DELETED
data/spec/models/game.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class Game
|
2
|
-
include Mongoid::Document
|
3
|
-
field :high_score, :type => Integer, :default => 500
|
4
|
-
field :score, :type => Integer, :default => 0
|
5
|
-
field :name
|
6
|
-
referenced_in :person, :index => true
|
7
|
-
references_one :video, :validate => false
|
8
|
-
accepts_nested_attributes_for :person
|
9
|
-
cache
|
10
|
-
|
11
|
-
validates_format_of :name, :without => /\$\$\$/
|
12
|
-
|
13
|
-
attr_protected :_id
|
14
|
-
|
15
|
-
set_callback(:initialize, :after) do |document|
|
16
|
-
write_attribute("name", "Testing") unless name
|
17
|
-
end
|
18
|
-
end
|
data/spec/models/ghost.rb
DELETED
data/spec/models/house.rb
DELETED
data/spec/models/inheritance.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
class Canvas
|
2
|
-
include Mongoid::Document
|
3
|
-
field :name
|
4
|
-
embeds_many :shapes
|
5
|
-
embeds_one :writer
|
6
|
-
embeds_one :palette
|
7
|
-
|
8
|
-
def render
|
9
|
-
shapes.each { |shape| render }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Browser < Canvas
|
14
|
-
field :version, :type => Integer
|
15
|
-
def render; end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Firefox < Browser
|
19
|
-
field :user_agent
|
20
|
-
def render; end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Shape
|
24
|
-
include Mongoid::Document
|
25
|
-
field :x, :type => Integer, :default => 0
|
26
|
-
field :y, :type => Integer, :default => 0
|
27
|
-
|
28
|
-
embedded_in :canvas
|
29
|
-
|
30
|
-
def render; end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Square < Shape
|
34
|
-
field :width, :type => Integer, :default => 0
|
35
|
-
field :height, :type => Integer, :default => 0
|
36
|
-
end
|
37
|
-
|
38
|
-
class Circle < Shape
|
39
|
-
field :radius, :type => Integer, :default => 0
|
40
|
-
end
|
41
|
-
|
42
|
-
class Writer
|
43
|
-
include Mongoid::Document
|
44
|
-
field :speed, :type => Integer, :default => 0
|
45
|
-
|
46
|
-
embedded_in :canvas
|
47
|
-
|
48
|
-
def write; end
|
49
|
-
end
|
50
|
-
|
51
|
-
class HtmlWriter < Writer
|
52
|
-
def write; end
|
53
|
-
end
|
54
|
-
|
55
|
-
class PdfWriter < Writer
|
56
|
-
def write; end
|
57
|
-
end
|
58
|
-
|
59
|
-
class Palette
|
60
|
-
include Mongoid::Document
|
61
|
-
embedded_in :canvas
|
62
|
-
embeds_many :tools
|
63
|
-
end
|
64
|
-
|
65
|
-
class Tool
|
66
|
-
include Mongoid::Document
|
67
|
-
embedded_in :palette
|
68
|
-
end
|
69
|
-
|
70
|
-
class Pencil < Tool; end
|
71
|
-
|
72
|
-
class Eraser < Tool; end
|
73
|
-
|
74
|
-
########################################
|
75
|
-
# These are for references relationships
|
76
|
-
########################################
|
77
|
-
class ShippingContainer
|
78
|
-
include Mongoid::Document
|
79
|
-
references_many :vehicles
|
80
|
-
end
|
81
|
-
class Vehicle
|
82
|
-
include Mongoid::Document
|
83
|
-
referenced_in :shipping_container
|
84
|
-
end
|
85
|
-
class Bed; end
|
86
|
-
class Car < Vehicle; end
|
87
|
-
class Truck < Vehicle
|
88
|
-
embeds_one :bed
|
89
|
-
end
|
90
|
-
|
data/spec/models/league.rb
DELETED
data/spec/models/location.rb
DELETED
data/spec/models/login.rb
DELETED
data/spec/models/membership.rb
DELETED
data/spec/models/mixed_drink.rb
DELETED
data/spec/models/name.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Name
|
2
|
-
include Mongoid::Document
|
3
|
-
field :first_name
|
4
|
-
field :last_name
|
5
|
-
field :parent_title
|
6
|
-
key :first_name, :last_name
|
7
|
-
embeds_many :translations
|
8
|
-
embedded_in :namable, :polymorphic => true
|
9
|
-
|
10
|
-
def set_parent=(set = false)
|
11
|
-
self.parent_title = namable.title if set
|
12
|
-
end
|
13
|
-
end
|
data/spec/models/namespacing.rb
DELETED
data/spec/models/observed.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
class Actor
|
2
|
-
include Mongoid::Document
|
3
|
-
field :name
|
4
|
-
end
|
5
|
-
|
6
|
-
class Actress < Actor
|
7
|
-
end
|
8
|
-
|
9
|
-
class ActorObserver < Mongoid::Observer
|
10
|
-
attr_reader :last_after_create_record
|
11
|
-
|
12
|
-
def after_create(record)
|
13
|
-
@last_after_create_record = record
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class CallbackRecorder < Mongoid::Observer
|
18
|
-
observe :actor
|
19
|
-
|
20
|
-
attr_reader :last_callback, :call_count, :last_record
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
reset
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
def reset
|
28
|
-
@last_callback = nil
|
29
|
-
@call_count = Hash.new(0)
|
30
|
-
@last_record = {}
|
31
|
-
end
|
32
|
-
|
33
|
-
Mongoid::Callbacks::CALLBACKS.each do |callback|
|
34
|
-
define_method(callback) do |record, &block|
|
35
|
-
@last_callback = callback
|
36
|
-
@call_count[callback] += 1
|
37
|
-
@last_record[callback] = record
|
38
|
-
block ? block.call : true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/spec/models/override.rb
DELETED
data/spec/models/owner.rb
DELETED
data/spec/models/page.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class ParanoidPost
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Versioning
|
4
|
-
include Mongoid::Timestamps
|
5
|
-
include Mongoid::Paranoia
|
6
|
-
field :title
|
7
|
-
referenced_in :person
|
8
|
-
|
9
|
-
references_and_referenced_in_many :tags
|
10
|
-
|
11
|
-
named_scope :recent, where(:created_at => { "$lt" => Time.now, "$gt" => 30.days.ago })
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def old
|
15
|
-
where(:created_at => { "$lt" => 30.days.ago })
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/models/parents.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
class ParentDoc
|
2
|
-
include Mongoid::Document
|
3
|
-
|
4
|
-
embeds_many :child_docs
|
5
|
-
|
6
|
-
field :statistic
|
7
|
-
field :children_order, :type => Array, :default => [] # hold all the children's id
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
class ChildDoc
|
12
|
-
include Mongoid::Document
|
13
|
-
|
14
|
-
embedded_in :parent_doc
|
15
|
-
|
16
|
-
attr_writer :position
|
17
|
-
|
18
|
-
after_save :update_position
|
19
|
-
|
20
|
-
def position
|
21
|
-
exsited_position = parent_doc.children_order.index(id)
|
22
|
-
exsited_position ? exsited_position + 1 : parent_doc.aspects.size
|
23
|
-
end
|
24
|
-
|
25
|
-
def update_position
|
26
|
-
if @position && (@position.to_i > 0)
|
27
|
-
parent_doc.children_order.delete(id)
|
28
|
-
parent_doc.children_order.insert(@position.to_i - 1, id)
|
29
|
-
parent_doc.save
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/spec/models/patient.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
class Email
|
2
|
-
include Mongoid::Document
|
3
|
-
field :address
|
4
|
-
validates_uniqueness_of :address
|
5
|
-
embedded_in :patient
|
6
|
-
end
|
7
|
-
|
8
|
-
class Patient
|
9
|
-
include Mongoid::Document
|
10
|
-
field :title
|
11
|
-
store_in :inpatient
|
12
|
-
embeds_many :addresses, :as => :addressable
|
13
|
-
embeds_one :email
|
14
|
-
validates_presence_of :title, :on => :create
|
15
|
-
end
|