mongoid 1.2.8 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongoid.rb +2 -3
- data/lib/mongoid/associations.rb +5 -3
- data/lib/mongoid/associations/belongs_to_related.rb +6 -9
- data/lib/mongoid/associations/has_many.rb +2 -0
- data/lib/mongoid/associations/has_many_related.rb +10 -0
- data/lib/mongoid/attributes.rb +6 -1
- data/lib/mongoid/commands.rb +2 -10
- data/lib/mongoid/components.rb +11 -12
- data/lib/mongoid/contexts/enumerable.rb +21 -11
- data/lib/mongoid/contexts/mongo.rb +40 -1
- data/lib/mongoid/criteria.rb +3 -29
- data/lib/mongoid/criterion/inclusion.rb +2 -1
- data/lib/mongoid/document.rb +5 -6
- data/lib/mongoid/extensions.rb +10 -0
- data/lib/mongoid/extensions/big_decimal/conversions.rb +19 -0
- data/lib/mongoid/extensions/binary/conversions.rb +17 -0
- data/lib/mongoid/{caching.rb → extras.rb} +26 -3
- data/lib/mongoid/field.rb +20 -7
- data/lib/mongoid/finders.rb +10 -80
- data/mongoid.gemspec +15 -13
- data/spec/integration/mongoid/document_spec.rb +1 -1
- data/spec/models/person.rb +1 -0
- data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +4 -0
- data/spec/unit/mongoid/associations/has_many_related_spec.rb +42 -13
- data/spec/unit/mongoid/associations/has_many_spec.rb +12 -7
- data/spec/unit/mongoid/associations_spec.rb +16 -0
- data/spec/unit/mongoid/attributes_spec.rb +23 -0
- data/spec/unit/mongoid/commands/destroy_spec.rb +3 -0
- data/spec/unit/mongoid/commands_spec.rb +4 -11
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +16 -0
- data/spec/unit/mongoid/contexts/mongo_spec.rb +96 -0
- data/spec/unit/mongoid/criteria_spec.rb +11 -4
- data/spec/unit/mongoid/document_spec.rb +11 -0
- data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +22 -0
- data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +22 -0
- data/spec/unit/mongoid/{enslavement_spec.rb → extras_spec.rb} +55 -2
- data/spec/unit/mongoid/field_spec.rb +62 -0
- data/spec/unit/mongoid/finders_spec.rb +36 -0
- metadata +69 -37
- data/HISTORY +0 -342
- data/lib/mongoid/enslavement.rb +0 -38
- data/spec/unit/mongoid/caching_spec.rb +0 -63
data/lib/mongoid/extensions.rb
CHANGED
@@ -4,6 +4,8 @@ require "mongoid/extensions/array/aliasing"
|
|
4
4
|
require "mongoid/extensions/array/assimilation"
|
5
5
|
require "mongoid/extensions/array/conversions"
|
6
6
|
require "mongoid/extensions/array/parentization"
|
7
|
+
require "mongoid/extensions/big_decimal/conversions"
|
8
|
+
require "mongoid/extensions/binary/conversions"
|
7
9
|
require "mongoid/extensions/boolean/conversions"
|
8
10
|
require "mongoid/extensions/date/conversions"
|
9
11
|
require "mongoid/extensions/datetime/conversions"
|
@@ -29,6 +31,14 @@ class Array #:nodoc
|
|
29
31
|
include Mongoid::Extensions::Array::Parentization
|
30
32
|
end
|
31
33
|
|
34
|
+
class BigDecimal #:nodoc
|
35
|
+
extend Mongoid::Extensions::BigDecimal::Conversions
|
36
|
+
end
|
37
|
+
|
38
|
+
class Binary #:nodoc
|
39
|
+
extend Mongoid::Extensions::Binary::Conversions
|
40
|
+
end
|
41
|
+
|
32
42
|
class Boolean #:nodoc
|
33
43
|
extend Mongoid::Extensions::Boolean::Conversions
|
34
44
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "bigdecimal"
|
3
|
+
|
4
|
+
module Mongoid #:nodoc:
|
5
|
+
module Extensions #:nodoc:
|
6
|
+
module BigDecimal #:nodoc:
|
7
|
+
module Conversions #:nodoc:
|
8
|
+
# Get the string as a +BigDecimal+
|
9
|
+
def get(value)
|
10
|
+
::BigDecimal.new(value)
|
11
|
+
end
|
12
|
+
# Set the value in the hash as a string.
|
13
|
+
def set(value)
|
14
|
+
value.to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid #:nodoc:
|
3
|
+
module Extensions #:nodoc:
|
4
|
+
module Binary #:nodoc:
|
5
|
+
module Conversions #:nodoc:
|
6
|
+
# Get the value from the db hash.
|
7
|
+
def get(value)
|
8
|
+
value
|
9
|
+
end
|
10
|
+
# Set the value in the db hash.
|
11
|
+
def set(value)
|
12
|
+
value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
|
-
module
|
3
|
+
module Extras #:nodoc:
|
4
4
|
def self.included(base)
|
5
5
|
base.class_eval do
|
6
6
|
extend ClassMethods
|
7
|
-
class_inheritable_accessor :cached
|
7
|
+
class_inheritable_accessor :cached, :enslaved
|
8
8
|
self.cached = false
|
9
|
+
self.enslaved = false
|
9
10
|
|
10
|
-
delegate :cached?, :to => "self.class"
|
11
|
+
delegate :cached?, :enslaved?, :to => "self.class"
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -36,6 +37,28 @@ module Mongoid #:nodoc:
|
|
36
37
|
def cached?
|
37
38
|
self.cached == true
|
38
39
|
end
|
40
|
+
|
41
|
+
# Set whether or not this documents read operations should delegate to
|
42
|
+
# the slave database by default.
|
43
|
+
#
|
44
|
+
# Example:
|
45
|
+
#
|
46
|
+
# class Person
|
47
|
+
# include Mongoid::Document
|
48
|
+
# enslave
|
49
|
+
# end
|
50
|
+
def enslave
|
51
|
+
self.enslaved = true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Determines if the class is enslaved or not.
|
55
|
+
#
|
56
|
+
# Returns:
|
57
|
+
#
|
58
|
+
# True if enslaved, false if not.
|
59
|
+
def enslaved?
|
60
|
+
self.enslaved == true
|
61
|
+
end
|
39
62
|
end
|
40
63
|
end
|
41
64
|
end
|
data/lib/mongoid/field.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
3
|
class Field
|
4
|
+
attr_reader :name, :type
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# Determine if the field is able to be accessible via a mass update.
|
7
|
+
#
|
8
|
+
# Returns:
|
9
|
+
#
|
10
|
+
# true if accessible, false if not.
|
11
|
+
def accessible?
|
12
|
+
!!@accessible
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get the default value for the field.
|
16
|
+
#
|
17
|
+
# Returns:
|
18
|
+
#
|
19
|
+
# The primitive value or a copy of the default.
|
20
|
+
def default
|
21
|
+
(@default.is_a?(Array) || @default.is_a?(Hash)) ? @default.dup : @default
|
22
|
+
end
|
9
23
|
|
10
24
|
# Create the new field with a name and optional additional options. Valid
|
11
25
|
# options are :default
|
@@ -19,9 +33,9 @@ module Mongoid #:nodoc:
|
|
19
33
|
#
|
20
34
|
# <tt>Field.new(:score, :default => 0)</tt>
|
21
35
|
def initialize(name, options = {})
|
22
|
-
@name = name
|
23
|
-
@default = options[:default]
|
36
|
+
@name, @default = name, options[:default]
|
24
37
|
@type = options[:type] || String
|
38
|
+
@accessible = options.has_key?(:accessible) ? options[:accessible] : true
|
25
39
|
end
|
26
40
|
|
27
41
|
# Used for setting an object in the attributes hash. If nil is provided the
|
@@ -34,6 +48,5 @@ module Mongoid #:nodoc:
|
|
34
48
|
def get(object)
|
35
49
|
type.get(object)
|
36
50
|
end
|
37
|
-
|
38
51
|
end
|
39
52
|
end
|
data/lib/mongoid/finders.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
3
|
module Finders #:nodoc:
|
4
|
+
|
5
|
+
# Delegate to the criteria methods that are natural for creating a new
|
6
|
+
# criteria.
|
7
|
+
[ :all_in, :any_in, :excludes, :limit, :max, :min,
|
8
|
+
:not_in, :only, :order_by, :skip, :sum, :where ].each do |name|
|
9
|
+
define_method(name) do |*args|
|
10
|
+
criteria.send(name, *args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
# Find +Documents+ given the conditions.
|
5
15
|
#
|
6
16
|
# Options:
|
@@ -100,36 +110,6 @@ module Mongoid #:nodoc:
|
|
100
110
|
find(:last, *args)
|
101
111
|
end
|
102
112
|
|
103
|
-
# Convenience method for returning the max value of a field.
|
104
|
-
#
|
105
|
-
# Options:
|
106
|
-
#
|
107
|
-
# field: The field to use when calculating the max.
|
108
|
-
#
|
109
|
-
# Example:
|
110
|
-
#
|
111
|
-
# <tt>Person.max(:age)</tt>
|
112
|
-
#
|
113
|
-
# Returns: <tt>Float</tt> max value.
|
114
|
-
def max(field)
|
115
|
-
criteria.max(field)
|
116
|
-
end
|
117
|
-
|
118
|
-
# Convenience method for returning the min value of a field.
|
119
|
-
#
|
120
|
-
# Options:
|
121
|
-
#
|
122
|
-
# field: The field to use when calculating the min.
|
123
|
-
#
|
124
|
-
# Example:
|
125
|
-
#
|
126
|
-
# <tt>Person.min(:age)</tt>
|
127
|
-
#
|
128
|
-
# Returns: <tt>Float</tt> min value.
|
129
|
-
def min(field)
|
130
|
-
criteria.min(field)
|
131
|
-
end
|
132
|
-
|
133
113
|
# Find all documents in paginated fashion given the supplied arguments.
|
134
114
|
# If no parameters are passed just default to offset 0 and limit 20.
|
135
115
|
#
|
@@ -147,56 +127,6 @@ module Mongoid #:nodoc:
|
|
147
127
|
Criteria.translate(self, params).paginate
|
148
128
|
end
|
149
129
|
|
150
|
-
# Entry point for creating a new criteria from a Document. This will
|
151
|
-
# instantiate a new +Criteria+ object with the supplied select criterion
|
152
|
-
# already added to it.
|
153
|
-
#
|
154
|
-
# Options:
|
155
|
-
#
|
156
|
-
# args: A list of field names to retrict the returned fields to.
|
157
|
-
#
|
158
|
-
# Example:
|
159
|
-
#
|
160
|
-
# <tt>Person.only(:field1, :field2, :field3)</tt>
|
161
|
-
#
|
162
|
-
# Returns: <tt>Criteria</tt>
|
163
|
-
def only(*args)
|
164
|
-
criteria.only(*args)
|
165
|
-
end
|
166
|
-
|
167
|
-
# Convenience method for returning the sum of a specified field for all
|
168
|
-
# documents in the database.
|
169
|
-
#
|
170
|
-
# Options:
|
171
|
-
#
|
172
|
-
# field: The field to use when calculating the sum.
|
173
|
-
#
|
174
|
-
# Example:
|
175
|
-
#
|
176
|
-
# <tt>Person.sum(:age)</tt>
|
177
|
-
#
|
178
|
-
# Returns: <tt>Float</tt> of the sum.
|
179
|
-
def sum(field)
|
180
|
-
criteria.sum(field)
|
181
|
-
end
|
182
|
-
|
183
|
-
# Entry point for creating a new criteria from a Document. This will
|
184
|
-
# instantiate a new +Criteria+ object with the supplied select criterion
|
185
|
-
# already added to it.
|
186
|
-
#
|
187
|
-
# Options:
|
188
|
-
#
|
189
|
-
# selector: A where criteria to initialize.
|
190
|
-
#
|
191
|
-
# Example:
|
192
|
-
#
|
193
|
-
# <tt>Person.where(:field1 => "Value")</tt>
|
194
|
-
#
|
195
|
-
# Returns: <tt>Criteria</tt>
|
196
|
-
def where(selector = nil)
|
197
|
-
criteria.where(selector)
|
198
|
-
end
|
199
|
-
|
200
130
|
protected
|
201
131
|
# Find the first object or create/initialize it.
|
202
132
|
def find_or(method, attrs = {})
|
data/mongoid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Durran Jordan"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-09}
|
13
13
|
s.email = %q{durran@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.rdoc"
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.files = [
|
18
18
|
".gitignore",
|
19
19
|
".watchr",
|
20
|
-
"HISTORY",
|
21
20
|
"MIT_LICENSE",
|
22
21
|
"README.rdoc",
|
23
22
|
"Rakefile",
|
@@ -35,7 +34,6 @@ Gem::Specification.new do |s|
|
|
35
34
|
"lib/mongoid/associations/options.rb",
|
36
35
|
"lib/mongoid/associations/proxy.rb",
|
37
36
|
"lib/mongoid/attributes.rb",
|
38
|
-
"lib/mongoid/caching.rb",
|
39
37
|
"lib/mongoid/callbacks.rb",
|
40
38
|
"lib/mongoid/collection.rb",
|
41
39
|
"lib/mongoid/collections/cyclic_iterator.rb",
|
@@ -65,7 +63,6 @@ Gem::Specification.new do |s|
|
|
65
63
|
"lib/mongoid/criterion/optional.rb",
|
66
64
|
"lib/mongoid/cursor.rb",
|
67
65
|
"lib/mongoid/document.rb",
|
68
|
-
"lib/mongoid/enslavement.rb",
|
69
66
|
"lib/mongoid/errors.rb",
|
70
67
|
"lib/mongoid/extensions.rb",
|
71
68
|
"lib/mongoid/extensions/array/accessors.rb",
|
@@ -73,6 +70,8 @@ Gem::Specification.new do |s|
|
|
73
70
|
"lib/mongoid/extensions/array/assimilation.rb",
|
74
71
|
"lib/mongoid/extensions/array/conversions.rb",
|
75
72
|
"lib/mongoid/extensions/array/parentization.rb",
|
73
|
+
"lib/mongoid/extensions/big_decimal/conversions.rb",
|
74
|
+
"lib/mongoid/extensions/binary/conversions.rb",
|
76
75
|
"lib/mongoid/extensions/boolean/conversions.rb",
|
77
76
|
"lib/mongoid/extensions/date/conversions.rb",
|
78
77
|
"lib/mongoid/extensions/datetime/conversions.rb",
|
@@ -90,6 +89,7 @@ Gem::Specification.new do |s|
|
|
90
89
|
"lib/mongoid/extensions/string/inflections.rb",
|
91
90
|
"lib/mongoid/extensions/symbol/inflections.rb",
|
92
91
|
"lib/mongoid/extensions/time/conversions.rb",
|
92
|
+
"lib/mongoid/extras.rb",
|
93
93
|
"lib/mongoid/factory.rb",
|
94
94
|
"lib/mongoid/field.rb",
|
95
95
|
"lib/mongoid/fields.rb",
|
@@ -158,7 +158,6 @@ Gem::Specification.new do |s|
|
|
158
158
|
"spec/unit/mongoid/associations/options_spec.rb",
|
159
159
|
"spec/unit/mongoid/associations_spec.rb",
|
160
160
|
"spec/unit/mongoid/attributes_spec.rb",
|
161
|
-
"spec/unit/mongoid/caching_spec.rb",
|
162
161
|
"spec/unit/mongoid/callbacks_spec.rb",
|
163
162
|
"spec/unit/mongoid/collection_spec.rb",
|
164
163
|
"spec/unit/mongoid/collections/cyclic_iterator_spec.rb",
|
@@ -183,12 +182,13 @@ Gem::Specification.new do |s|
|
|
183
182
|
"spec/unit/mongoid/criterion/optional_spec.rb",
|
184
183
|
"spec/unit/mongoid/cursor_spec.rb",
|
185
184
|
"spec/unit/mongoid/document_spec.rb",
|
186
|
-
"spec/unit/mongoid/enslavement_spec.rb",
|
187
185
|
"spec/unit/mongoid/errors_spec.rb",
|
188
186
|
"spec/unit/mongoid/extensions/array/accessors_spec.rb",
|
189
187
|
"spec/unit/mongoid/extensions/array/assimilation_spec.rb",
|
190
188
|
"spec/unit/mongoid/extensions/array/conversions_spec.rb",
|
191
189
|
"spec/unit/mongoid/extensions/array/parentization_spec.rb",
|
190
|
+
"spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb",
|
191
|
+
"spec/unit/mongoid/extensions/binary/conversions_spec.rb",
|
192
192
|
"spec/unit/mongoid/extensions/boolean/conversions_spec.rb",
|
193
193
|
"spec/unit/mongoid/extensions/date/conversions_spec.rb",
|
194
194
|
"spec/unit/mongoid/extensions/datetime/conversions_spec.rb",
|
@@ -206,6 +206,7 @@ Gem::Specification.new do |s|
|
|
206
206
|
"spec/unit/mongoid/extensions/string/inflections_spec.rb",
|
207
207
|
"spec/unit/mongoid/extensions/symbol/inflections_spec.rb",
|
208
208
|
"spec/unit/mongoid/extensions/time/conversions_spec.rb",
|
209
|
+
"spec/unit/mongoid/extras_spec.rb",
|
209
210
|
"spec/unit/mongoid/factory_spec.rb",
|
210
211
|
"spec/unit/mongoid/field_spec.rb",
|
211
212
|
"spec/unit/mongoid/fields_spec.rb",
|
@@ -235,7 +236,7 @@ Gem::Specification.new do |s|
|
|
235
236
|
s.homepage = %q{http://mongoid.org}
|
236
237
|
s.rdoc_options = ["--charset=UTF-8"]
|
237
238
|
s.require_paths = ["lib"]
|
238
|
-
s.rubygems_version = %q{1.3.
|
239
|
+
s.rubygems_version = %q{1.3.6}
|
239
240
|
s.summary = %q{ODM framework for MongoDB}
|
240
241
|
s.test_files = [
|
241
242
|
"spec/integration/mongoid/associations_spec.rb",
|
@@ -278,7 +279,6 @@ Gem::Specification.new do |s|
|
|
278
279
|
"spec/unit/mongoid/associations/options_spec.rb",
|
279
280
|
"spec/unit/mongoid/associations_spec.rb",
|
280
281
|
"spec/unit/mongoid/attributes_spec.rb",
|
281
|
-
"spec/unit/mongoid/caching_spec.rb",
|
282
282
|
"spec/unit/mongoid/callbacks_spec.rb",
|
283
283
|
"spec/unit/mongoid/collection_spec.rb",
|
284
284
|
"spec/unit/mongoid/collections/cyclic_iterator_spec.rb",
|
@@ -303,12 +303,13 @@ Gem::Specification.new do |s|
|
|
303
303
|
"spec/unit/mongoid/criterion/optional_spec.rb",
|
304
304
|
"spec/unit/mongoid/cursor_spec.rb",
|
305
305
|
"spec/unit/mongoid/document_spec.rb",
|
306
|
-
"spec/unit/mongoid/enslavement_spec.rb",
|
307
306
|
"spec/unit/mongoid/errors_spec.rb",
|
308
307
|
"spec/unit/mongoid/extensions/array/accessors_spec.rb",
|
309
308
|
"spec/unit/mongoid/extensions/array/assimilation_spec.rb",
|
310
309
|
"spec/unit/mongoid/extensions/array/conversions_spec.rb",
|
311
310
|
"spec/unit/mongoid/extensions/array/parentization_spec.rb",
|
311
|
+
"spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb",
|
312
|
+
"spec/unit/mongoid/extensions/binary/conversions_spec.rb",
|
312
313
|
"spec/unit/mongoid/extensions/boolean/conversions_spec.rb",
|
313
314
|
"spec/unit/mongoid/extensions/date/conversions_spec.rb",
|
314
315
|
"spec/unit/mongoid/extensions/datetime/conversions_spec.rb",
|
@@ -326,6 +327,7 @@ Gem::Specification.new do |s|
|
|
326
327
|
"spec/unit/mongoid/extensions/string/inflections_spec.rb",
|
327
328
|
"spec/unit/mongoid/extensions/symbol/inflections_spec.rb",
|
328
329
|
"spec/unit/mongoid/extensions/time/conversions_spec.rb",
|
330
|
+
"spec/unit/mongoid/extras_spec.rb",
|
329
331
|
"spec/unit/mongoid/factory_spec.rb",
|
330
332
|
"spec/unit/mongoid/field_spec.rb",
|
331
333
|
"spec/unit/mongoid/fields_spec.rb",
|
@@ -361,14 +363,14 @@ Gem::Specification.new do |s|
|
|
361
363
|
s.add_runtime_dependency(%q<activesupport>, ["<= 2.3.5"])
|
362
364
|
s.add_runtime_dependency(%q<mongo>, [">= 0.18.3"])
|
363
365
|
s.add_runtime_dependency(%q<durran-validatable>, [">= 2.0.1"])
|
364
|
-
s.add_runtime_dependency(%q<will_paginate>, ["<
|
366
|
+
s.add_runtime_dependency(%q<will_paginate>, ["< 2.9"])
|
365
367
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
366
368
|
s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
|
367
369
|
else
|
368
370
|
s.add_dependency(%q<activesupport>, ["<= 2.3.5"])
|
369
371
|
s.add_dependency(%q<mongo>, [">= 0.18.3"])
|
370
372
|
s.add_dependency(%q<durran-validatable>, [">= 2.0.1"])
|
371
|
-
s.add_dependency(%q<will_paginate>, ["<
|
373
|
+
s.add_dependency(%q<will_paginate>, ["< 2.9"])
|
372
374
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
373
375
|
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
374
376
|
end
|
@@ -376,7 +378,7 @@ Gem::Specification.new do |s|
|
|
376
378
|
s.add_dependency(%q<activesupport>, ["<= 2.3.5"])
|
377
379
|
s.add_dependency(%q<mongo>, [">= 0.18.3"])
|
378
380
|
s.add_dependency(%q<durran-validatable>, [">= 2.0.1"])
|
379
|
-
s.add_dependency(%q<will_paginate>, ["<
|
381
|
+
s.add_dependency(%q<will_paginate>, ["< 2.9"])
|
380
382
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
381
383
|
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
382
384
|
end
|
data/spec/models/person.rb
CHANGED
@@ -134,6 +134,10 @@ describe Mongoid::Associations::BelongsToRelated do
|
|
134
134
|
Mongoid::Associations::BelongsToRelated.update(nil, @child, @options).should be_nil
|
135
135
|
end
|
136
136
|
|
137
|
+
it "removes the association" do
|
138
|
+
Mongoid::Associations::BelongsToRelated.update(nil, @child, @options)
|
139
|
+
@child.person.should be_nil
|
140
|
+
end
|
137
141
|
end
|
138
142
|
|
139
143
|
end
|
@@ -45,16 +45,36 @@ describe Mongoid::Associations::HasManyRelated do
|
|
45
45
|
|
46
46
|
context "when parent document has not been saved" do
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
context "when appending a non mongoid object" do
|
49
|
+
|
50
|
+
before do
|
51
|
+
@parent = stub(:id => "1", :new_record? => true, :class => Person)
|
52
|
+
Post.expects(:all).returns([])
|
53
|
+
@association = Mongoid::Associations::HasManyRelated.new(@parent, options)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "appends the child document" do
|
57
|
+
@child.expects(:person_id=).with(@parent.id)
|
58
|
+
@association << @child
|
59
|
+
@association.size.should == 1
|
60
|
+
end
|
52
61
|
end
|
53
62
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
63
|
+
context "when appending a mongoid document" do
|
64
|
+
|
65
|
+
before do
|
66
|
+
@criteria = mock
|
67
|
+
@parent = stub(:id => "1", :new_record? => true, :class => Person)
|
68
|
+
Post.expects(:all).returns(@criteria)
|
69
|
+
@association = Mongoid::Associations::HasManyRelated.new(@parent, options)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "appends the child document" do
|
73
|
+
@criteria.expects(:entries).returns([])
|
74
|
+
@child.expects(:person_id=).with(@parent.id)
|
75
|
+
@association << @child
|
76
|
+
@association.size.should == 1
|
77
|
+
end
|
58
78
|
end
|
59
79
|
|
60
80
|
end
|
@@ -81,8 +101,10 @@ describe Mongoid::Associations::HasManyRelated do
|
|
81
101
|
describe "#build" do
|
82
102
|
|
83
103
|
before do
|
84
|
-
@
|
85
|
-
|
104
|
+
@criteria = mock
|
105
|
+
@criteria.expects(:entries).returns([])
|
106
|
+
@parent = stub(:id => "5", :class => Person, :new_record? => true)
|
107
|
+
Post.expects(:all).returns(@criteria)
|
86
108
|
@association = Mongoid::Associations::HasManyRelated.new(@parent, options)
|
87
109
|
end
|
88
110
|
|
@@ -169,18 +191,25 @@ describe Mongoid::Associations::HasManyRelated do
|
|
169
191
|
describe "#create" do
|
170
192
|
|
171
193
|
before do
|
172
|
-
@
|
194
|
+
@post = mock
|
195
|
+
@parent = stub(:id => "5", :class => Person, :new_record? => true)
|
173
196
|
Post.expects(:all).returns([])
|
174
|
-
Mongoid::Commands::Save.expects(:execute)
|
175
197
|
@association = Mongoid::Associations::HasManyRelated.new(@parent, options)
|
198
|
+
Post.expects(:instantiate).returns(@post)
|
176
199
|
end
|
177
200
|
|
178
201
|
it "builds and saves the new object" do
|
202
|
+
@post.expects(:run_callbacks).with(:before_create)
|
203
|
+
@post.expects(:save).returns(true)
|
204
|
+
@post.expects(:run_callbacks).with(:after_create)
|
179
205
|
@association.create(:title => "Sassy")
|
180
206
|
end
|
181
207
|
|
182
208
|
it "returns the new object" do
|
183
|
-
@
|
209
|
+
@post.expects(:run_callbacks).with(:before_create)
|
210
|
+
@post.expects(:save).returns(true)
|
211
|
+
@post.expects(:run_callbacks).with(:after_create)
|
212
|
+
@association.create(:title => "Sassy").should == @post
|
184
213
|
end
|
185
214
|
|
186
215
|
end
|