mongo_doc 0.6.26 → 0.6.27
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/README.textile +14 -203
- data/Rakefile +0 -134
- data/lib/mongo_doc/collection.rb +4 -0
- data/lib/mongo_doc/finders.rb +1 -0
- data/lib/mongo_doc/timestamps.rb +4 -3
- data/lib/mongo_doc/version.rb +3 -0
- data/lib/mongo_doc.rb +0 -5
- metadata +25 -212
- data/.document +0 -5
- data/.gitignore +0 -8
- data/.rspec +0 -2
- data/.rvmrc +0 -1
- data/.watchr +0 -32
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -72
- data/HISTORY.md +0 -11
- data/VERSION +0 -1
- data/examples/simple_document.rb +0 -46
- data/examples/simple_object.rb +0 -34
- data/features/collections.feature +0 -9
- data/features/connection.feature +0 -13
- data/features/db_references.feature +0 -21
- data/features/embed_hash.feature +0 -16
- data/features/finders.feature +0 -76
- data/features/indexes.feature +0 -28
- data/features/mongodb.yml +0 -7
- data/features/mongodoc_base.feature +0 -128
- data/features/new_record.feature +0 -36
- data/features/partial_updates.feature +0 -95
- data/features/polymorphic_collections.feature +0 -16
- data/features/references.feature +0 -28
- data/features/removing_documents.feature +0 -68
- data/features/saving_an_object.feature +0 -15
- data/features/scopes.feature +0 -66
- data/features/step_definitions/collection_steps.rb +0 -17
- data/features/step_definitions/connection_steps.rb +0 -13
- data/features/step_definitions/document_steps.rb +0 -155
- data/features/step_definitions/documents.rb +0 -61
- data/features/step_definitions/embed_hash_steps.rb +0 -6
- data/features/step_definitions/field_steps.rb +0 -28
- data/features/step_definitions/finder_steps.rb +0 -15
- data/features/step_definitions/index_steps.rb +0 -10
- data/features/step_definitions/json_steps.rb +0 -9
- data/features/step_definitions/object_steps.rb +0 -50
- data/features/step_definitions/objects.rb +0 -24
- data/features/step_definitions/partial_update_steps.rb +0 -31
- data/features/step_definitions/query_steps.rb +0 -69
- data/features/step_definitions/removing_documents_steps.rb +0 -14
- data/features/step_definitions/scope_steps.rb +0 -18
- data/features/step_definitions/string_casting_steps.rb +0 -29
- data/features/step_definitions/util_steps.rb +0 -7
- data/features/string_casting.feature +0 -10
- data/features/support/support.rb +0 -12
- data/features/timestamps.feature +0 -14
- data/features/using_criteria.feature +0 -148
- data/mongo_doc.gemspec +0 -272
- data/mongodb.example.yml +0 -14
- data/perf/mongo_doc_object.rb +0 -83
- data/perf/mongo_document.rb +0 -84
- data/perf/ruby_driver.rb +0 -49
- data/script/console +0 -8
- data/spec/active_model_behavior.rb +0 -64
- data/spec/array_including_argument_matcher.rb +0 -62
- data/spec/associations/collection_proxy_spec.rb +0 -233
- data/spec/associations/document_proxy_spec.rb +0 -45
- data/spec/associations/hash_proxy_spec.rb +0 -181
- data/spec/associations/proxy_base_spec.rb +0 -92
- data/spec/associations_spec.rb +0 -218
- data/spec/attributes_accessor_spec.rb +0 -39
- data/spec/attributes_spec.rb +0 -184
- data/spec/bson_matchers.rb +0 -54
- data/spec/bson_spec.rb +0 -196
- data/spec/collection_spec.rb +0 -169
- data/spec/connection_spec.rb +0 -169
- data/spec/contexts/ids_spec.rb +0 -49
- data/spec/contexts/mongo_spec.rb +0 -241
- data/spec/contexts_spec.rb +0 -56
- data/spec/criteria/optional_spec.rb +0 -26
- data/spec/criteria_spec.rb +0 -73
- data/spec/cursor_spec.rb +0 -91
- data/spec/database_cleaner_spec.rb +0 -24
- data/spec/document_ext.rb +0 -9
- data/spec/document_spec.rb +0 -569
- data/spec/embedded_save_spec.rb +0 -73
- data/spec/ext_spec.rb +0 -100
- data/spec/finders_spec.rb +0 -61
- data/spec/hash_matchers.rb +0 -29
- data/spec/index_spec.rb +0 -79
- data/spec/matchers_spec.rb +0 -342
- data/spec/mongodb.yml +0 -6
- data/spec/mongodb_pairs.yml +0 -8
- data/spec/new_record_spec.rb +0 -128
- data/spec/polymorphic_collection_spec.rb +0 -47
- data/spec/references_many_spec.rb +0 -214
- data/spec/references_spec.rb +0 -121
- data/spec/root_spec.rb +0 -41
- data/spec/scope_spec.rb +0 -88
- data/spec/spec_helper.rb +0 -16
- data/spec/timestamps_spec.rb +0 -154
- data/spec/update_spec.rb +0 -167
- data/spec/validations_spec.rb +0 -30
data/spec/document_spec.rb
DELETED
@@ -1,569 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "MongoDoc::Document" do
|
4
|
-
|
5
|
-
describe "#_collection" do
|
6
|
-
class DocumentCollectionTest
|
7
|
-
include MongoDoc::Document
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:doc) do
|
11
|
-
doc = DocumentCollectionTest.new
|
12
|
-
doc._root = stub
|
13
|
-
doc
|
14
|
-
end
|
15
|
-
|
16
|
-
before do
|
17
|
-
DocumentCollectionTest.stub(:collection).and_return('collection')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "delegates to the root's collection" do
|
21
|
-
doc._root.should_receive :_collection
|
22
|
-
doc._collection
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "ActiveModel" do
|
27
|
-
class FormForTest
|
28
|
-
include MongoDoc::Document
|
29
|
-
|
30
|
-
attr_accessor :data
|
31
|
-
end
|
32
|
-
|
33
|
-
describe FormForTest do
|
34
|
-
it_should_behave_like AnActiveModel
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:doc) { FormForTest.new }
|
38
|
-
|
39
|
-
context "persisted record" do
|
40
|
-
subject { doc._id = '1'; doc }
|
41
|
-
|
42
|
-
it { should_not be_new_record }
|
43
|
-
it { should be_persisted }
|
44
|
-
its(:id) { should == doc._id }
|
45
|
-
its(:to_param) { should == doc._id.to_s }
|
46
|
-
its(:to_key) { should == [doc._id] }
|
47
|
-
end
|
48
|
-
|
49
|
-
context "record has not been persisted" do
|
50
|
-
subject { doc }
|
51
|
-
|
52
|
-
it { should be_new_record }
|
53
|
-
it { should_not be_persisted }
|
54
|
-
its(:id) { should be_nil }
|
55
|
-
its(:to_param) { should be_nil }
|
56
|
-
its(:to_key) { should be_nil }
|
57
|
-
end
|
58
|
-
|
59
|
-
it "#initialize takes a hash" do
|
60
|
-
data = 'data'
|
61
|
-
FormForTest.new(:data => data).data.should == data
|
62
|
-
end
|
63
|
-
|
64
|
-
it "#initialize accepts a nil" do
|
65
|
-
expect do
|
66
|
-
FormForTest.new(nil)
|
67
|
-
end.should_not raise_error
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
context "saving" do
|
73
|
-
class SaveRoot
|
74
|
-
include MongoDoc::Document
|
75
|
-
|
76
|
-
embed_many :save_children
|
77
|
-
end
|
78
|
-
|
79
|
-
class SaveChild
|
80
|
-
include MongoDoc::Document
|
81
|
-
|
82
|
-
attr_accessor :data
|
83
|
-
end
|
84
|
-
|
85
|
-
before do
|
86
|
-
@root = SaveRoot.new
|
87
|
-
@root.stub(:_save)
|
88
|
-
@child = SaveChild.new
|
89
|
-
@root.save_children << @child
|
90
|
-
end
|
91
|
-
|
92
|
-
context "#save" do
|
93
|
-
it "delegates to the root" do
|
94
|
-
validate = true
|
95
|
-
@root.should_receive(:save).with(validate)
|
96
|
-
@child.save(validate)
|
97
|
-
end
|
98
|
-
|
99
|
-
context "when validating" do
|
100
|
-
it "validates" do
|
101
|
-
@root.should_receive(:valid?)
|
102
|
-
@root.save(true)
|
103
|
-
end
|
104
|
-
|
105
|
-
context "and valid" do
|
106
|
-
it "delegates to _save" do
|
107
|
-
@root.should_receive(:_save).with(false)
|
108
|
-
@root.save(true)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "returns the result of _save if valid" do
|
112
|
-
id = 'id'
|
113
|
-
@root.stub(:valid?).and_return(true)
|
114
|
-
@root.should_receive(:_save).and_return(id)
|
115
|
-
@root.save(true).should == id
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "and invalid" do
|
120
|
-
it "does not call _save" do
|
121
|
-
@root.stub(:valid?).and_return(false)
|
122
|
-
@root.should_not_receive(:_save)
|
123
|
-
@root.save(true)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "returns false" do
|
127
|
-
@root.stub(:valid?).and_return(false)
|
128
|
-
@root.save(true).should be_false
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "when not validating" do
|
134
|
-
it "does not validate" do
|
135
|
-
@root.should_not_receive(:valid?)
|
136
|
-
@root.save(false)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "delegates to _save" do
|
140
|
-
@root.should_receive(:_save).with(false)
|
141
|
-
@root.save(false)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "returns the result of _save" do
|
145
|
-
id = 'id'
|
146
|
-
@root.stub(:_save).and_return(id)
|
147
|
-
@root.save(false).should == id
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "#save!" do
|
153
|
-
it "delegates to the root" do
|
154
|
-
@root.should_receive(:save!)
|
155
|
-
@child.save!
|
156
|
-
end
|
157
|
-
|
158
|
-
it "validates" do
|
159
|
-
@root.should_receive(:valid?).and_return(true)
|
160
|
-
@root.save!
|
161
|
-
end
|
162
|
-
|
163
|
-
it "returns the result of _save if valid" do
|
164
|
-
id = 'id'
|
165
|
-
@root.stub(:valid?).and_return(true)
|
166
|
-
@root.should_receive(:_save).with(true).and_return(id)
|
167
|
-
@root.save!.should == id
|
168
|
-
end
|
169
|
-
|
170
|
-
it "raises if invalid" do
|
171
|
-
@root.stub(:valid?).and_return(false)
|
172
|
-
expect do
|
173
|
-
@root.save!
|
174
|
-
end.should raise_error(MongoDoc::DocumentInvalidError)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context "#_save" do
|
180
|
-
class SaveTest
|
181
|
-
include MongoDoc::Document
|
182
|
-
end
|
183
|
-
|
184
|
-
before do
|
185
|
-
@collection = stub('collection')
|
186
|
-
@doc = SaveTest.new
|
187
|
-
@doc.stub(:_collection).and_return(@collection)
|
188
|
-
end
|
189
|
-
|
190
|
-
it "delegates to the collection save" do
|
191
|
-
safe = true
|
192
|
-
@collection.should_receive(:save)
|
193
|
-
@doc.send(:_save, safe)
|
194
|
-
end
|
195
|
-
|
196
|
-
it "sets the _id of the document" do
|
197
|
-
id = 'id'
|
198
|
-
@collection.stub(:save).and_return(id)
|
199
|
-
@doc.send(:_save, true)
|
200
|
-
@doc._id.should == id
|
201
|
-
end
|
202
|
-
|
203
|
-
it "returns the _id" do
|
204
|
-
id = 'id'
|
205
|
-
@collection.stub(:save).and_return(id)
|
206
|
-
@doc.send(:_save, true).should == id
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context "creating" do
|
211
|
-
class CreateTest
|
212
|
-
include MongoDoc::Document
|
213
|
-
|
214
|
-
attr_accessor :data
|
215
|
-
validates_presence_of :data
|
216
|
-
end
|
217
|
-
|
218
|
-
let(:data) { 'data' }
|
219
|
-
let(:instance) { CreateTest.new(:data => data) }
|
220
|
-
|
221
|
-
before do
|
222
|
-
instance.stub(:save)
|
223
|
-
instance.stub(:save!)
|
224
|
-
end
|
225
|
-
|
226
|
-
context ".create" do
|
227
|
-
it "creates a new document with the attributes" do
|
228
|
-
CreateTest.should_receive(:new).with(:data => data).and_return(instance)
|
229
|
-
CreateTest.create(:data => data)
|
230
|
-
end
|
231
|
-
|
232
|
-
context "with the new document" do
|
233
|
-
before do
|
234
|
-
CreateTest.stub(:new).and_return(instance)
|
235
|
-
end
|
236
|
-
|
237
|
-
it "calls save on the instance with validate => true" do
|
238
|
-
instance.should_receive(:save).with(true)
|
239
|
-
CreateTest.create(:data => data)
|
240
|
-
end
|
241
|
-
|
242
|
-
it "returns the new object" do
|
243
|
-
CreateTest.create(:data => data).should == instance
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context ".create!" do
|
249
|
-
it "creates a new document with the attributes" do
|
250
|
-
CreateTest.should_receive(:new).with(:data => data).and_return(instance)
|
251
|
-
CreateTest.create!(:data => data)
|
252
|
-
end
|
253
|
-
|
254
|
-
context "with the new document" do
|
255
|
-
before do
|
256
|
-
CreateTest.stub(:new).and_return(instance)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "calls save! on the instance" do
|
260
|
-
instance.should_receive(:save!).with(no_args)
|
261
|
-
CreateTest.create!(:data => data)
|
262
|
-
end
|
263
|
-
|
264
|
-
it "returns the new object" do
|
265
|
-
CreateTest.create!(:data => data).should == instance
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe "bson" do
|
272
|
-
class BSONTest
|
273
|
-
include MongoDoc::Document
|
274
|
-
|
275
|
-
attr_accessor :other
|
276
|
-
end
|
277
|
-
|
278
|
-
class BSONDerived < BSONTest
|
279
|
-
include MongoDoc::Document
|
280
|
-
|
281
|
-
attr_accessor :derived
|
282
|
-
end
|
283
|
-
|
284
|
-
class OtherObject
|
285
|
-
attr_accessor :value
|
286
|
-
end
|
287
|
-
|
288
|
-
before do
|
289
|
-
@value = 'value'
|
290
|
-
@other = OtherObject.new
|
291
|
-
@other.value = @value
|
292
|
-
@doc = BSONTest.new(:other => @other)
|
293
|
-
end
|
294
|
-
|
295
|
-
it "encodes the class for the object" do
|
296
|
-
@doc.to_bson[MongoDoc::BSON::CLASS_KEY].should == BSONTest.name
|
297
|
-
end
|
298
|
-
|
299
|
-
it "renders a json representation of the object" do
|
300
|
-
@doc.to_bson.should be_bson_eql({MongoDoc::BSON::CLASS_KEY => BSONTest.name, "other" => {MongoDoc::BSON::CLASS_KEY => OtherObject.name, "value" => @value}})
|
301
|
-
end
|
302
|
-
|
303
|
-
it "includes the _id of the object" do
|
304
|
-
@doc._id = BSON::ObjectID.new
|
305
|
-
@doc.to_bson.should be_bson_eql({MongoDoc::BSON::CLASS_KEY => BSONTest.name, "_id" => @doc._id.to_bson, "other" => {MongoDoc::BSON::CLASS_KEY => OtherObject.name, "value" => @value}})
|
306
|
-
end
|
307
|
-
|
308
|
-
it "roundtrips the object" do
|
309
|
-
MongoDoc::BSON.decode(@doc.to_bson).should be_kind_of(BSONTest)
|
310
|
-
end
|
311
|
-
|
312
|
-
it "ignores the class hash when the :raw_json option is used" do
|
313
|
-
MongoDoc::BSON.decode(@doc.to_bson.except(MongoDoc::BSON::CLASS_KEY), :raw_json => true)['other'].should == @other.to_bson
|
314
|
-
end
|
315
|
-
|
316
|
-
it "allows for derived classes" do
|
317
|
-
derived = BSONDerived.new(:other => @other, :derived => 'derived')
|
318
|
-
MongoDoc::BSON.decode(derived.to_bson).other.should be_kind_of(OtherObject)
|
319
|
-
end
|
320
|
-
|
321
|
-
it "roundtrips embedded ruby objects" do
|
322
|
-
MongoDoc::BSON.decode(@doc.to_bson).other.should be_kind_of(OtherObject)
|
323
|
-
end
|
324
|
-
|
325
|
-
context "associations" do
|
326
|
-
context "embed" do
|
327
|
-
class TestEmbedBsonDoc
|
328
|
-
include MongoDoc::Document
|
329
|
-
|
330
|
-
embed :subdoc
|
331
|
-
end
|
332
|
-
|
333
|
-
class SubEmbedBsonDoc
|
334
|
-
include MongoDoc::Document
|
335
|
-
|
336
|
-
attr_accessor :attr
|
337
|
-
end
|
338
|
-
|
339
|
-
it "#to_bson renders a bson representation of the document" do
|
340
|
-
doc = TestEmbedBsonDoc.new
|
341
|
-
subdoc = SubEmbedBsonDoc.new(:attr => "value")
|
342
|
-
bson = doc.to_bson
|
343
|
-
bson["subdoc"] = subdoc.to_bson
|
344
|
-
doc.subdoc = subdoc
|
345
|
-
doc.to_bson.should == bson
|
346
|
-
end
|
347
|
-
|
348
|
-
it "roundtrips" do
|
349
|
-
doc = TestEmbedBsonDoc.new
|
350
|
-
subdoc = SubEmbedBsonDoc.new(:attr => "value")
|
351
|
-
doc.subdoc = subdoc
|
352
|
-
MongoDoc::BSON.decode(doc.to_bson).should == doc
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
context "embed_many" do
|
357
|
-
|
358
|
-
class SubEmbedManyBsonDoc
|
359
|
-
include MongoDoc::Document
|
360
|
-
|
361
|
-
attr_accessor :attr
|
362
|
-
end
|
363
|
-
|
364
|
-
class TestEmbedManyBsonDoc
|
365
|
-
include MongoDoc::Document
|
366
|
-
embed_many :subdoc, :class_name => 'SubEmbedManyBsonDoc'
|
367
|
-
end
|
368
|
-
|
369
|
-
it "#to_bson renders a bson representation of the document" do
|
370
|
-
doc = TestEmbedManyBsonDoc.new
|
371
|
-
subdoc = SubEmbedManyBsonDoc.new(:attr => "value")
|
372
|
-
bson = doc.to_bson
|
373
|
-
bson["subdoc"] = [subdoc].to_bson
|
374
|
-
doc.subdoc = subdoc
|
375
|
-
doc.to_bson.should == bson
|
376
|
-
end
|
377
|
-
|
378
|
-
it "roundtrips" do
|
379
|
-
doc = TestEmbedManyBsonDoc.new
|
380
|
-
subdoc = SubEmbedManyBsonDoc.new(:attr => "value")
|
381
|
-
doc.subdoc = subdoc
|
382
|
-
MongoDoc::BSON.decode(doc.to_bson).should == doc
|
383
|
-
end
|
384
|
-
|
385
|
-
it "roundtrips the proxy" do
|
386
|
-
doc = TestEmbedManyBsonDoc.new(:subdoc => SubEmbedManyBsonDoc.new(:attr => "value"))
|
387
|
-
MongoDoc::Associations::CollectionProxy.should === MongoDoc::BSON.decode(doc.to_bson).subdoc
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
context "removing documents" do
|
394
|
-
class RemoveDocument
|
395
|
-
include MongoDoc::Document
|
396
|
-
end
|
397
|
-
|
398
|
-
let(:doc) { RemoveDocument.new }
|
399
|
-
|
400
|
-
context "#remove" do
|
401
|
-
it "when called on a embedded document with a _root raises UnsupportedOperation" do
|
402
|
-
doc._root = RemoveDocument.new
|
403
|
-
expect { doc.remove }.to raise_error(MongoDoc::UnsupportedOperation)
|
404
|
-
end
|
405
|
-
|
406
|
-
it "delegates to remove document" do
|
407
|
-
doc.should_receive(:remove_document)
|
408
|
-
doc.remove
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
context "#remove_document" do
|
413
|
-
it "when the document is the root, removes the document" do
|
414
|
-
doc.should_receive(:_remove)
|
415
|
-
doc.remove_document
|
416
|
-
end
|
417
|
-
|
418
|
-
it "when the document is not the root, calls remove_document on the root" do
|
419
|
-
doc._root = root = RemoveDocument.new
|
420
|
-
root.should_receive(:remove_document)
|
421
|
-
doc.remove_document
|
422
|
-
end
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
context "misc class methods" do
|
427
|
-
class MiscClassMethods
|
428
|
-
include MongoDoc::Document
|
429
|
-
end
|
430
|
-
|
431
|
-
it ".collection_name returns the name of the collection for this class" do
|
432
|
-
MiscClassMethods.collection_name.should == MiscClassMethods.to_s.tableize.gsub('/', '.')
|
433
|
-
end
|
434
|
-
|
435
|
-
it ".collection returns a wrapped MongoDoc::Collection" do
|
436
|
-
db = stub('db')
|
437
|
-
db.should_receive(:collection).with(MiscClassMethods.to_s.tableize.gsub('/', '.'))
|
438
|
-
MongoDoc::Connection.should_receive(:database).and_return(db)
|
439
|
-
MongoDoc::Collection.should === MiscClassMethods.collection
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
context "ActiveModel compliance" do
|
444
|
-
class ActiveModelComplianceTest
|
445
|
-
include MongoDoc::Document
|
446
|
-
end
|
447
|
-
|
448
|
-
let(:model) { ActiveModelComplianceTest.new }
|
449
|
-
|
450
|
-
describe "#to_param" do
|
451
|
-
let(:string_id) { mock }
|
452
|
-
|
453
|
-
before(:each) do
|
454
|
-
model.instance_variable_set(:@_id, mock(:oid, :to_s => string_id))
|
455
|
-
end
|
456
|
-
|
457
|
-
it "returns the string form of the document id" do
|
458
|
-
model.to_param.should == string_id
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
describe "#valid?" do
|
463
|
-
subject { model }
|
464
|
-
it "responds to #valid?" do
|
465
|
-
should respond_to(:valid?)
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
describe "#new_record?" do
|
470
|
-
subject { model }
|
471
|
-
it "responds to #new_record?" do
|
472
|
-
should respond_to(:new_record?)
|
473
|
-
end
|
474
|
-
|
475
|
-
context "when the object has an id" do
|
476
|
-
before(:each) do
|
477
|
-
model.instance_variable_set(:@_id, mock(:id))
|
478
|
-
end
|
479
|
-
|
480
|
-
it "is false" do
|
481
|
-
should_not be_new_record
|
482
|
-
end
|
483
|
-
end
|
484
|
-
|
485
|
-
context "when the object has no id" do
|
486
|
-
before(:each) do
|
487
|
-
model.instance_variable_set(:@_id, nil)
|
488
|
-
end
|
489
|
-
|
490
|
-
it "is true" do
|
491
|
-
should be_new_record
|
492
|
-
end
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
describe "#destroyed?" do
|
497
|
-
subject { model }
|
498
|
-
|
499
|
-
it "responds to #destroyed?" do
|
500
|
-
should respond_to(:destroyed?)
|
501
|
-
end
|
502
|
-
|
503
|
-
context "when the object has an id" do
|
504
|
-
before(:each) do
|
505
|
-
model.instance_variable_set(:@_id, mock(:id))
|
506
|
-
end
|
507
|
-
|
508
|
-
it "is false" do
|
509
|
-
should_not be_destroyed
|
510
|
-
end
|
511
|
-
end
|
512
|
-
|
513
|
-
context "when the object has no id" do
|
514
|
-
before(:each) do
|
515
|
-
model.instance_variable_set(:@_id, nil)
|
516
|
-
end
|
517
|
-
|
518
|
-
it "is true" do
|
519
|
-
should be_destroyed
|
520
|
-
end
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
describe "#errors" do
|
525
|
-
subject { model }
|
526
|
-
it "responds to errors" do
|
527
|
-
should respond_to(:errors)
|
528
|
-
end
|
529
|
-
|
530
|
-
describe "#[]" do
|
531
|
-
it "returns an array on a missing key lookup" do
|
532
|
-
model.errors[:does_not_exist].should be_an(Array)
|
533
|
-
end
|
534
|
-
end
|
535
|
-
|
536
|
-
describe "#full_messages" do
|
537
|
-
it "returns an array" do
|
538
|
-
model.errors.full_messages.should be_an(Array)
|
539
|
-
end
|
540
|
-
end
|
541
|
-
end
|
542
|
-
|
543
|
-
describe ".model_name" do
|
544
|
-
it "responds to model_name" do
|
545
|
-
ActiveModelComplianceTest.should respond_to(:model_name)
|
546
|
-
end
|
547
|
-
|
548
|
-
it "is a string" do
|
549
|
-
ActiveModelComplianceTest.model_name.should be_a(String)
|
550
|
-
end
|
551
|
-
|
552
|
-
it "has a human inflector" do
|
553
|
-
ActiveModelComplianceTest.model_name.human.should be_a(String)
|
554
|
-
end
|
555
|
-
|
556
|
-
it "has a partial path inflector" do
|
557
|
-
ActiveModelComplianceTest.model_name.partial_path.should be_a(String)
|
558
|
-
end
|
559
|
-
|
560
|
-
it "has a singular inflector" do
|
561
|
-
ActiveModelComplianceTest.model_name.singular.should be_a(String)
|
562
|
-
end
|
563
|
-
|
564
|
-
it "has a plural inflector" do
|
565
|
-
ActiveModelComplianceTest.model_name.plural.should be_a(String)
|
566
|
-
end
|
567
|
-
end
|
568
|
-
end
|
569
|
-
end
|
data/spec/embedded_save_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Saving embedded documents" do
|
4
|
-
class NestedDocsRoot
|
5
|
-
include MongoDoc::Document
|
6
|
-
|
7
|
-
embed_many :nested_children
|
8
|
-
end
|
9
|
-
|
10
|
-
class NestedChild
|
11
|
-
include MongoDoc::Document
|
12
|
-
|
13
|
-
embed :leaf
|
14
|
-
end
|
15
|
-
|
16
|
-
class LeafDoc
|
17
|
-
include MongoDoc::Document
|
18
|
-
|
19
|
-
attr_accessor :data
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:leaf) do
|
23
|
-
doc = LeafDoc.new
|
24
|
-
doc._id = 'id'
|
25
|
-
doc
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:data) { 'data' }
|
29
|
-
|
30
|
-
context "#save" do
|
31
|
-
let(:root) { NestedDocsRoot.new(:nested_children => [NestedChild.new(:leaf => leaf)]) }
|
32
|
-
|
33
|
-
it "calls the root document's save" do
|
34
|
-
root.should_receive(:save).with(true)
|
35
|
-
leaf.save
|
36
|
-
end
|
37
|
-
|
38
|
-
it "(with bang!) calls the root documents save!" do
|
39
|
-
root.should_receive(:save!)
|
40
|
-
leaf.save!
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "update_attributes" do
|
45
|
-
context "with no embed_many, update_attributes" do
|
46
|
-
let(:root) { NestedChild.new(:leaf => leaf) }
|
47
|
-
|
48
|
-
it "calls the root document's _update with a full attribute path and not safe" do
|
49
|
-
root.should_receive(:_update).with({"leaf._id"=>"id"}, {'leaf.data' => data}, false)
|
50
|
-
leaf.update_attributes(:data => data)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "(with bang!) calls the root document's _update with a full attribute path and safe" do
|
54
|
-
root.should_receive(:_update).with({"leaf._id"=>"id"}, {'leaf.data' => data}, true)
|
55
|
-
leaf.update_attributes!(:data => data)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "with embed_many, update_attributes" do
|
60
|
-
let(:root) { NestedDocsRoot.new(:nested_children => [NestedChild.new(:leaf => leaf)]) }
|
61
|
-
|
62
|
-
it "calls the root document's _update with a full attribute path and not safe" do
|
63
|
-
root.should_receive(:_update).with({"nested_children.leaf._id"=>"id"}, {'nested_children.$.leaf.data' => data}, false)
|
64
|
-
leaf.update_attributes(:data => data)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "(with bang!) calls the root document's _update with a full attribute path and safe" do
|
68
|
-
root.should_receive(:_update).with({"nested_children.leaf._id"=>"id"}, {'nested_children.$.leaf.data' => data}, true)
|
69
|
-
leaf.update_attributes!(:data => data)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|