mongoid-pre 2.0.0.beta1 → 2.0.0.pre
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.
- data/.watchr +15 -10
- data/HISTORY +342 -0
- data/README.rdoc +8 -1
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/mongoid/associations/{embedded_in.rb → belongs_to.rb} +4 -4
- data/lib/mongoid/associations/belongs_to_related.rb +9 -6
- data/lib/mongoid/associations/{embeds_many.rb → has_many.rb} +20 -33
- data/lib/mongoid/associations/has_many_related.rb +4 -28
- data/lib/mongoid/associations/{embeds_one.rb → has_one.rb} +6 -6
- data/lib/mongoid/associations/options.rb +6 -1
- data/lib/mongoid/associations.rb +32 -41
- data/lib/mongoid/attributes.rb +6 -13
- data/lib/mongoid/collection.rb +1 -2
- data/lib/mongoid/commands/delete.rb +1 -1
- data/lib/mongoid/commands/delete_all.rb +1 -4
- data/lib/mongoid/commands/destroy.rb +1 -1
- data/lib/mongoid/commands/destroy_all.rb +1 -3
- data/lib/mongoid/commands/save.rb +0 -1
- data/lib/mongoid/commands.rb +13 -2
- data/lib/mongoid/components.rb +1 -6
- data/lib/mongoid/config.rb +1 -5
- data/lib/mongoid/contexts/enumerable.rb +17 -54
- data/lib/mongoid/contexts/mongo.rb +38 -101
- data/lib/mongoid/contexts/paging.rb +2 -2
- data/lib/mongoid/contexts.rb +0 -21
- data/lib/mongoid/criteria.rb +73 -15
- data/lib/mongoid/criterion/inclusion.rb +0 -2
- data/lib/mongoid/criterion/optional.rb +2 -10
- data/lib/mongoid/document.rb +30 -41
- data/lib/mongoid/extensions.rb +0 -15
- data/lib/mongoid/field.rb +7 -20
- data/lib/mongoid/fields.rb +10 -15
- data/lib/mongoid/finders.rb +98 -10
- data/lib/mongoid/identity.rb +2 -8
- data/lib/mongoid/named_scope.rb +0 -2
- data/lib/mongoid/validations/associated.rb +8 -3
- data/lib/mongoid/validations/uniqueness.rb +7 -2
- data/lib/mongoid/validations.rb +2 -2
- data/lib/mongoid/versioning.rb +1 -1
- data/lib/mongoid.rb +5 -21
- data/mongoid.gemspec +19 -59
- data/spec/integration/mongoid/associations_spec.rb +3 -42
- data/spec/integration/mongoid/attributes_spec.rb +2 -2
- data/spec/integration/mongoid/commands_spec.rb +13 -27
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +0 -13
- data/spec/integration/mongoid/criteria_spec.rb +3 -50
- data/spec/integration/mongoid/document_spec.rb +5 -72
- data/spec/integration/mongoid/finders_spec.rb +28 -85
- data/spec/models/address.rb +3 -3
- data/spec/models/animal.rb +2 -2
- data/spec/models/country_code.rb +2 -2
- data/spec/models/game.rb +1 -2
- data/spec/models/inheritance.rb +5 -5
- data/spec/models/location.rb +2 -2
- data/spec/models/name.rb +3 -3
- data/spec/models/namespacing.rb +2 -2
- data/spec/models/patient.rb +0 -2
- data/spec/models/person.rb +4 -6
- data/spec/models/pet.rb +3 -3
- data/spec/models/pet_owner.rb +3 -3
- data/spec/models/phone.rb +3 -3
- data/spec/models/post.rb +1 -1
- data/spec/models/translation.rb +2 -2
- data/spec/models/vet_visit.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +0 -4
- data/spec/unit/mongoid/associations/{embedded_in_spec.rb → belongs_to_spec.rb} +11 -11
- data/spec/unit/mongoid/associations/has_many_related_spec.rb +14 -45
- data/spec/unit/mongoid/associations/{embeds_many_spec.rb → has_many_spec.rb} +34 -79
- data/spec/unit/mongoid/associations/{embeds_one_spec.rb → has_one_spec.rb} +18 -18
- data/spec/unit/mongoid/associations/options_spec.rb +19 -20
- data/spec/unit/mongoid/associations_spec.rb +12 -74
- data/spec/unit/mongoid/attributes_spec.rb +51 -83
- data/spec/unit/mongoid/collection_spec.rb +0 -46
- data/spec/unit/mongoid/commands/delete_all_spec.rb +8 -9
- data/spec/unit/mongoid/commands/delete_spec.rb +3 -6
- data/spec/unit/mongoid/commands/destroy_all_spec.rb +2 -0
- data/spec/unit/mongoid/commands/destroy_spec.rb +3 -10
- data/spec/unit/mongoid/commands_spec.rb +11 -20
- data/spec/unit/mongoid/config_spec.rb +0 -18
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +11 -198
- data/spec/unit/mongoid/contexts/mongo_spec.rb +54 -357
- data/spec/unit/mongoid/criteria_spec.rb +78 -107
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +13 -3
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +19 -25
- data/spec/unit/mongoid/criterion/optional_spec.rb +18 -25
- data/spec/unit/mongoid/document_spec.rb +34 -71
- data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
- data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +3 -0
- data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -16
- data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
- data/spec/unit/mongoid/field_spec.rb +0 -62
- data/spec/unit/mongoid/fields_spec.rb +0 -33
- data/spec/unit/mongoid/finders_spec.rb +1 -37
- data/spec/unit/mongoid/identity_spec.rb +6 -47
- data/spec/unit/mongoid/named_scope_spec.rb +2 -15
- data/spec/unit/mongoid/scope_spec.rb +1 -1
- data/spec/unit/mongoid/validations/uniqueness_spec.rb +3 -3
- data/spec/unit/mongoid_spec.rb +2 -11
- metadata +14 -64
- data/lib/mongoid/associations/meta_data.rb +0 -28
- data/lib/mongoid/contexts/ids.rb +0 -25
- data/lib/mongoid/deprecation.rb +0 -22
- data/lib/mongoid/dirty.rb +0 -203
- data/lib/mongoid/extensions/big_decimal/conversions.rb +0 -19
- data/lib/mongoid/extensions/binary/conversions.rb +0 -17
- data/lib/mongoid/extensions/objectid/conversions.rb +0 -15
- data/lib/mongoid/extras.rb +0 -61
- data/lib/mongoid/javascript/functions.yml +0 -37
- data/lib/mongoid/javascript.rb +0 -21
- data/lib/mongoid/observable.rb +0 -30
- data/lib/mongoid/paths.rb +0 -54
- data/lib/mongoid/persistence/command.rb +0 -20
- data/lib/mongoid/persistence/insert.rb +0 -71
- data/lib/mongoid/persistence/update.rb +0 -78
- data/lib/mongoid/persistence.rb +0 -27
- data/lib/mongoid/state.rb +0 -32
- data/spec/integration/mongoid/dirty_spec.rb +0 -70
- data/spec/integration/mongoid/persistence/update_spec.rb +0 -46
- data/spec/models/callbacks.rb +0 -18
- data/spec/unit/mongoid/associations/meta_data_spec.rb +0 -88
- data/spec/unit/mongoid/contexts_spec.rb +0 -25
- data/spec/unit/mongoid/deprecation_spec.rb +0 -24
- data/spec/unit/mongoid/dirty_spec.rb +0 -286
- data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extras_spec.rb +0 -102
- data/spec/unit/mongoid/javascript_spec.rb +0 -48
- data/spec/unit/mongoid/observable_spec.rb +0 -46
- data/spec/unit/mongoid/paths_spec.rb +0 -124
- data/spec/unit/mongoid/persistence/insert_spec.rb +0 -175
- data/spec/unit/mongoid/persistence/update_spec.rb +0 -148
- data/spec/unit/mongoid/persistence_spec.rb +0 -40
- data/spec/unit/mongoid/state_spec.rb +0 -83
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Dirty do
|
|
4
|
-
|
|
5
|
-
describe "#attribute_change" do
|
|
6
|
-
|
|
7
|
-
context "when the attribute has changed" do
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
11
|
-
@person.title = "Captain Obvious"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "returns an array of the old value and new value" do
|
|
15
|
-
@person.attribute_change("title").should ==
|
|
16
|
-
[ "Grand Poobah", "Captain Obvious" ]
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "allows access via (attribute)_change" do
|
|
20
|
-
@person.title_change.should ==
|
|
21
|
-
[ "Grand Poobah", "Captain Obvious" ]
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "when the attribute has not changed" do
|
|
26
|
-
|
|
27
|
-
before do
|
|
28
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "returns an empty array" do
|
|
32
|
-
@person.attribute_change("title").should be_nil
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe "#attribute_changed?" do
|
|
38
|
-
|
|
39
|
-
context "when the attribute has changed" do
|
|
40
|
-
|
|
41
|
-
before do
|
|
42
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
43
|
-
@person.title = "Captain Obvious"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "returns true" do
|
|
47
|
-
@person.attribute_changed?("title").should == true
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "allows access via (attribute)_changed?" do
|
|
51
|
-
@person.title_changed?.should == true
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context "when the attribute has not changed" do
|
|
56
|
-
|
|
57
|
-
before do
|
|
58
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "returns false" do
|
|
62
|
-
@person.attribute_changed?("title").should == false
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe "#attribute_was" do
|
|
68
|
-
|
|
69
|
-
context "when the attribute has changed" do
|
|
70
|
-
|
|
71
|
-
before do
|
|
72
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
73
|
-
@person.title = "Captain Obvious"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "returns the old value" do
|
|
77
|
-
@person.attribute_was("title").should == "Grand Poobah"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "allows access via (attribute)_was" do
|
|
81
|
-
@person.title_was.should == "Grand Poobah"
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
context "when the attribute has not changed" do
|
|
86
|
-
|
|
87
|
-
before do
|
|
88
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "returns nil" do
|
|
92
|
-
@person.attribute_was("title").should be_nil
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
describe "#changed" do
|
|
98
|
-
|
|
99
|
-
context "when the document has changed" do
|
|
100
|
-
|
|
101
|
-
before do
|
|
102
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
103
|
-
@person.title = "Captain Obvious"
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "returns an array of changed field names" do
|
|
107
|
-
@person.changed.should == [ "title" ]
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
context "when the document has not changed" do
|
|
112
|
-
|
|
113
|
-
before do
|
|
114
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "returns an empty array" do
|
|
118
|
-
@person.changed.should == []
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe "#changed?" do
|
|
124
|
-
|
|
125
|
-
context "when the document has changed" do
|
|
126
|
-
|
|
127
|
-
before do
|
|
128
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
129
|
-
@person.title = "Captain Obvious"
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "returns true" do
|
|
133
|
-
@person.should be_changed
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context "when the document has not changed" do
|
|
138
|
-
|
|
139
|
-
before do
|
|
140
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "returns false" do
|
|
144
|
-
@person.should_not be_changed
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
describe "#changes" do
|
|
150
|
-
|
|
151
|
-
context "when the document has changed" do
|
|
152
|
-
|
|
153
|
-
before do
|
|
154
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
155
|
-
@person.title = "Captain Obvious"
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
it "returns a hash of changes" do
|
|
159
|
-
@person.changes.should ==
|
|
160
|
-
{ "title" => [ "Grand Poobah", "Captain Obvious" ] }
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
context "when the document has not changed" do
|
|
165
|
-
|
|
166
|
-
before do
|
|
167
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it "returns an empty hash" do
|
|
171
|
-
@person.changes.should == {}
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
describe "#setters" do
|
|
177
|
-
|
|
178
|
-
context "when the document has changed" do
|
|
179
|
-
|
|
180
|
-
context "when the document is a root document" do
|
|
181
|
-
|
|
182
|
-
before do
|
|
183
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
184
|
-
@person.title = "Captain Obvious"
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it "returns a hash of field names and new values" do
|
|
188
|
-
@person.setters.should ==
|
|
189
|
-
{ "title" => "Captain Obvious" }
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
context "when the document is embedded" do
|
|
194
|
-
|
|
195
|
-
before do
|
|
196
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
197
|
-
@address = Address.new(:street => "Oxford St")
|
|
198
|
-
@person.addresses << @address
|
|
199
|
-
@address.street = "Bond St"
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it "returns a hash of field names and new values" do
|
|
203
|
-
@address.setters.should ==
|
|
204
|
-
{ "addresses.$.street" => "Bond St" }
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
context "when the document has not changed" do
|
|
210
|
-
|
|
211
|
-
before do
|
|
212
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
it "returns an empty hash" do
|
|
216
|
-
@person.setters.should == {}
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
describe "#previous_changes" do
|
|
222
|
-
|
|
223
|
-
before do
|
|
224
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
225
|
-
@person.title = "Captain Obvious"
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
context "when the document has been saved" do
|
|
229
|
-
|
|
230
|
-
before do
|
|
231
|
-
@person.collection.expects(:save).returns(true)
|
|
232
|
-
@person.save!
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
it "returns the changes before the save" do
|
|
236
|
-
@person.previous_changes["title"].should ==
|
|
237
|
-
[ "Grand Poobah", "Captain Obvious" ]
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
context "when the document has not been saved" do
|
|
242
|
-
|
|
243
|
-
it "returns an empty hash" do
|
|
244
|
-
@person.previous_changes.should == {}
|
|
245
|
-
end
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
describe "#reset_attribute!" do
|
|
250
|
-
|
|
251
|
-
context "when the attribute has changed" do
|
|
252
|
-
|
|
253
|
-
before do
|
|
254
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
255
|
-
@person.title = "Captain Obvious"
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
it "resets the value to the original" do
|
|
259
|
-
@person.reset_attribute!("title")
|
|
260
|
-
@person.title.should == "Grand Poobah"
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
it "allows access via reset_(attribute)!" do
|
|
264
|
-
@person.reset_title!
|
|
265
|
-
@person.title.should == "Grand Poobah"
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
it "removes the field from the changes" do
|
|
269
|
-
@person.reset_title!
|
|
270
|
-
@person.changed.should == []
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
context "when the attribute has not changed" do
|
|
275
|
-
|
|
276
|
-
before do
|
|
277
|
-
@person = Person.new(:title => "Grand Poobah")
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
it "does nothing" do
|
|
281
|
-
@person.reset_attribute!("title")
|
|
282
|
-
@person.title.should == "Grand Poobah"
|
|
283
|
-
end
|
|
284
|
-
end
|
|
285
|
-
end
|
|
286
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Extensions::BigDecimal::Conversions do
|
|
4
|
-
|
|
5
|
-
let(:number) do
|
|
6
|
-
BigDecimal.new("123456.789")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe "#get" do
|
|
10
|
-
|
|
11
|
-
it "converts the string to a big decimal" do
|
|
12
|
-
BigDecimal.get("123456.789").should == number
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "#set" do
|
|
17
|
-
|
|
18
|
-
it "converts the big decimal to a string" do
|
|
19
|
-
BigDecimal.set(number).should == "123456.789"
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Extensions::Binary::Conversions do
|
|
4
|
-
|
|
5
|
-
let(:bin) do
|
|
6
|
-
Binary.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe "#get" do
|
|
10
|
-
|
|
11
|
-
it "returns self" do
|
|
12
|
-
Binary.get(bin).should == bin
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "#set" do
|
|
17
|
-
|
|
18
|
-
it "returns self" do
|
|
19
|
-
Binary.set(bin).should == bin
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Extras do
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
@klass = Class.new do
|
|
7
|
-
include Mongoid::Extras
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe ".cache" do
|
|
12
|
-
|
|
13
|
-
before do
|
|
14
|
-
@klass.cache
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "sets the cached boolean on the class" do
|
|
18
|
-
@klass.cached.should be_true
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe ".cached?" do
|
|
24
|
-
|
|
25
|
-
context "when the class is cached" do
|
|
26
|
-
|
|
27
|
-
before do
|
|
28
|
-
@klass.cache
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "returns true" do
|
|
32
|
-
@klass.should be_cached
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "when the class is not cached" do
|
|
37
|
-
|
|
38
|
-
it "returns false" do
|
|
39
|
-
@klass.should_not be_cached
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe "#cached?" do
|
|
46
|
-
|
|
47
|
-
before do
|
|
48
|
-
@klass.cache
|
|
49
|
-
@doc = @klass.new
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "returns the class cached? value" do
|
|
53
|
-
@doc.should be_cached
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe ".enslave" do
|
|
58
|
-
|
|
59
|
-
before do
|
|
60
|
-
@klass.enslave
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "sets the enslaved boolean on the class" do
|
|
64
|
-
@klass.enslaved.should be_true
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
describe ".enslaved?" do
|
|
70
|
-
|
|
71
|
-
context "when the class is enslaved" do
|
|
72
|
-
|
|
73
|
-
before do
|
|
74
|
-
@klass.enslave
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "returns true" do
|
|
78
|
-
@klass.should be_enslaved
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context "when the class is not enslaved" do
|
|
83
|
-
|
|
84
|
-
it "returns false" do
|
|
85
|
-
@klass.should_not be_enslaved
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
describe "#enslaved?" do
|
|
92
|
-
|
|
93
|
-
before do
|
|
94
|
-
@klass.enslave
|
|
95
|
-
@doc = @klass.new
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "returns the class enslaved? value" do
|
|
99
|
-
@doc.should be_enslaved
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Javascript do
|
|
4
|
-
|
|
5
|
-
let(:js) do
|
|
6
|
-
Mongoid::Javascript
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe ".aggregate" do
|
|
10
|
-
|
|
11
|
-
it "returns the aggregate function" do
|
|
12
|
-
js.aggregate.should == "function(obj, prev) { prev.count++; }"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe ".group" do
|
|
17
|
-
|
|
18
|
-
it "returns the group function" do
|
|
19
|
-
js.group.should == "function(obj, prev) { prev.group.push(obj); }"
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe ".max" do
|
|
24
|
-
|
|
25
|
-
it "returns the max function" do
|
|
26
|
-
js.max.should == "function(obj, prev) { if (prev.max == 'start') { " +
|
|
27
|
-
"prev.max = obj.[field]; } if (prev.max < obj.[field]) { prev.max = obj.[field];" +
|
|
28
|
-
" } }"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe ".min" do
|
|
33
|
-
|
|
34
|
-
it "returns the min function" do
|
|
35
|
-
js.min.should == "function(obj, prev) { if (prev.min == 'start') { " +
|
|
36
|
-
"prev.min = obj.[field]; } if (prev.min > obj.[field]) { prev.min = obj.[field];" +
|
|
37
|
-
" } }"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe ".sum" do
|
|
42
|
-
|
|
43
|
-
it "returns the sum function" do
|
|
44
|
-
js.sum.should == "function(obj, prev) { if (prev.sum == 'start') { prev.sum = 0; " +
|
|
45
|
-
"} prev.sum += obj.[field]; }"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Observable do
|
|
4
|
-
|
|
5
|
-
let(:person) do
|
|
6
|
-
Person.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
let(:address) do
|
|
10
|
-
Address.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "#add_observer" do
|
|
14
|
-
|
|
15
|
-
it "adds an observer to the observer array" do
|
|
16
|
-
address.add_observer(person)
|
|
17
|
-
address.observers.first.should == person
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "#notify_observers" do
|
|
22
|
-
|
|
23
|
-
before do
|
|
24
|
-
address.add_observer(person)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "when observers exist" do
|
|
28
|
-
|
|
29
|
-
it "calls update on each observer with the args" do
|
|
30
|
-
person.expects(:observe).with("Testing")
|
|
31
|
-
address.notify_observers("Testing")
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context "when no observers are set up" do
|
|
36
|
-
|
|
37
|
-
before do
|
|
38
|
-
@name = Name.new
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "does notthing" do
|
|
42
|
-
@name.notify_observers("Testing")
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Paths do
|
|
4
|
-
|
|
5
|
-
let(:person) do
|
|
6
|
-
Person.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
let(:address) do
|
|
10
|
-
Address.new(:street => "testing")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
let(:location) do
|
|
14
|
-
Location.new
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#path" do
|
|
18
|
-
|
|
19
|
-
context "when the document is a parent" do
|
|
20
|
-
|
|
21
|
-
it "returns an empty string" do
|
|
22
|
-
person.path.should == ""
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "when the document is embedded" do
|
|
27
|
-
|
|
28
|
-
before do
|
|
29
|
-
person.addresses << address
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "returns the inverse_of value of the association" do
|
|
33
|
-
address.path.should == "addresses"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "when document embedded multiple levels" do
|
|
38
|
-
|
|
39
|
-
before do
|
|
40
|
-
address.locations << location
|
|
41
|
-
person.addresses << address
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "returns the JSON notation to the document" do
|
|
45
|
-
location.path.should == "addresses.locations"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "sets the route class instance var" do
|
|
49
|
-
Location._path.should == "addresses.locations"
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "#selector" do
|
|
55
|
-
|
|
56
|
-
context "when the document is a parent" do
|
|
57
|
-
|
|
58
|
-
it "returns an id selector" do
|
|
59
|
-
person.selector.should == { "_id" => person.id }
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context "when the document is embedded" do
|
|
64
|
-
|
|
65
|
-
before do
|
|
66
|
-
person.addresses << address
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "returns the association with id selector" do
|
|
70
|
-
address.selector.should == { "_id" => person.id, "addresses._id" => address.id }
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
context "when document embedded multiple levels" do
|
|
75
|
-
|
|
76
|
-
before do
|
|
77
|
-
address.locations << location
|
|
78
|
-
person.addresses << address
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "returns the JSON notation to the document with ids" do
|
|
82
|
-
location.selector.should ==
|
|
83
|
-
{ "_id" => person.id, "addresses._id" => address.id, "addresses.locations._id" => location.id }
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe "#position" do
|
|
89
|
-
|
|
90
|
-
context "when the document is a parent" do
|
|
91
|
-
|
|
92
|
-
it "returns an empty string" do
|
|
93
|
-
person.position.should == ""
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context "when the document is embedded" do
|
|
98
|
-
|
|
99
|
-
before do
|
|
100
|
-
person.addresses << address
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "returns the path plus $" do
|
|
104
|
-
address.position.should == "addresses.$"
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
context "when document embedded multiple levels" do
|
|
109
|
-
|
|
110
|
-
before do
|
|
111
|
-
address.locations << location
|
|
112
|
-
person.addresses << address
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "returns the path plus $" do
|
|
116
|
-
location.position.should == "addresses.locations.$"
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "sets the matcher class instance var" do
|
|
120
|
-
Location._position.should == "addresses.locations.$"
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|