mongo_doc 0.3.2 → 0.4.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.
- data/README.textile +32 -16
- data/VERSION +1 -1
- data/examples/simple_document.rb +10 -10
- data/features/step_definitions/documents.rb +15 -15
- data/lib/mongo_doc/associations.rb +100 -0
- data/lib/mongo_doc/attributes.rb +20 -104
- data/lib/mongo_doc/contexts/mongo.rb +1 -1
- data/lib/mongo_doc/contexts.rb +1 -1
- data/lib/mongo_doc/document.rb +2 -0
- data/lib/mongo_doc.rb +1 -1
- data/mongo_doc.gemspec +5 -2
- data/spec/associations/collection_proxy_spec.rb +2 -2
- data/spec/associations/hash_proxy_spec.rb +2 -2
- data/spec/associations_spec.rb +230 -0
- data/spec/attributes_accessor_spec.rb +3 -3
- data/spec/attributes_spec.rb +19 -203
- data/spec/contexts/enumerable_spec.rb +2 -2
- data/spec/contexts/ids_spec.rb +2 -2
- data/spec/contexts/mongo_spec.rb +2 -2
- data/spec/contexts_spec.rb +1 -1
- data/spec/document_spec.rb +28 -28
- data/spec/embedded_save_spec.rb +7 -7
- data/spec/finders_spec.rb +1 -1
- data/spec/new_record_spec.rb +5 -5
- data/spec/scope_spec.rb +2 -2
- metadata +7 -4
data/spec/document_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe "MongoDoc::Document" do
|
|
6
6
|
class FormForTest
|
7
7
|
include MongoDoc::Document
|
8
8
|
|
9
|
-
|
9
|
+
attr_accessor :data
|
10
10
|
end
|
11
11
|
|
12
12
|
before do
|
@@ -43,7 +43,7 @@ describe "MongoDoc::Document" do
|
|
43
43
|
class SimpleValidationTest
|
44
44
|
include MongoDoc::Document
|
45
45
|
|
46
|
-
|
46
|
+
attr_accessor :data
|
47
47
|
validates_presence_of :data
|
48
48
|
end
|
49
49
|
|
@@ -62,13 +62,13 @@ describe "MongoDoc::Document" do
|
|
62
62
|
class SaveRoot
|
63
63
|
include MongoDoc::Document
|
64
64
|
|
65
|
-
|
65
|
+
embed_many :save_children
|
66
66
|
end
|
67
67
|
|
68
68
|
class SaveChild
|
69
69
|
include MongoDoc::Document
|
70
70
|
|
71
|
-
|
71
|
+
attr_accessor :data
|
72
72
|
end
|
73
73
|
|
74
74
|
before do
|
@@ -200,7 +200,7 @@ describe "MongoDoc::Document" do
|
|
200
200
|
class CreateTest
|
201
201
|
include MongoDoc::Document
|
202
202
|
|
203
|
-
|
203
|
+
attr_accessor :data
|
204
204
|
validates_presence_of :data
|
205
205
|
end
|
206
206
|
|
@@ -261,13 +261,13 @@ describe "MongoDoc::Document" do
|
|
261
261
|
class UpdateAttributesRoot
|
262
262
|
include MongoDoc::Document
|
263
263
|
|
264
|
-
|
264
|
+
embed :update_attributes_child
|
265
265
|
end
|
266
266
|
|
267
267
|
class UpdateAttributesChild
|
268
268
|
include MongoDoc::Document
|
269
269
|
|
270
|
-
|
270
|
+
attr_accessor :data
|
271
271
|
end
|
272
272
|
|
273
273
|
let(:data) {'data'}
|
@@ -479,13 +479,13 @@ describe "MongoDoc::Document" do
|
|
479
479
|
class BSONTest
|
480
480
|
include MongoDoc::Document
|
481
481
|
|
482
|
-
|
482
|
+
attr_accessor :other
|
483
483
|
end
|
484
484
|
|
485
485
|
class BSONDerived < BSONTest
|
486
486
|
include MongoDoc::Document
|
487
487
|
|
488
|
-
|
488
|
+
attr_accessor :derived
|
489
489
|
end
|
490
490
|
|
491
491
|
class OtherObject
|
@@ -530,22 +530,22 @@ describe "MongoDoc::Document" do
|
|
530
530
|
end
|
531
531
|
|
532
532
|
context "associations" do
|
533
|
-
context "
|
534
|
-
class
|
533
|
+
context "embed" do
|
534
|
+
class TestEmbedBsonDoc
|
535
535
|
include MongoDoc::Document
|
536
536
|
|
537
|
-
|
537
|
+
embed :subdoc
|
538
538
|
end
|
539
539
|
|
540
|
-
class
|
540
|
+
class SubEmbedBsonDoc
|
541
541
|
include MongoDoc::Document
|
542
542
|
|
543
|
-
|
543
|
+
attr_accessor :attr
|
544
544
|
end
|
545
545
|
|
546
546
|
it "#to_bson renders a bson representation of the document" do
|
547
|
-
doc =
|
548
|
-
subdoc =
|
547
|
+
doc = TestEmbedBsonDoc.new
|
548
|
+
subdoc = SubEmbedBsonDoc.new(:attr => "value")
|
549
549
|
bson = doc.to_bson
|
550
550
|
bson["subdoc"] = subdoc.to_bson
|
551
551
|
doc.subdoc = subdoc
|
@@ -553,29 +553,29 @@ describe "MongoDoc::Document" do
|
|
553
553
|
end
|
554
554
|
|
555
555
|
it "roundtrips" do
|
556
|
-
doc =
|
557
|
-
subdoc =
|
556
|
+
doc = TestEmbedBsonDoc.new
|
557
|
+
subdoc = SubEmbedBsonDoc.new(:attr => "value")
|
558
558
|
doc.subdoc = subdoc
|
559
559
|
MongoDoc::BSON.decode(doc.to_bson).should == doc
|
560
560
|
end
|
561
561
|
end
|
562
562
|
|
563
|
-
context "
|
563
|
+
context "embed_many" do
|
564
564
|
|
565
|
-
class
|
565
|
+
class SubEmbedManyBsonDoc
|
566
566
|
include MongoDoc::Document
|
567
567
|
|
568
|
-
|
568
|
+
attr_accessor :attr
|
569
569
|
end
|
570
570
|
|
571
|
-
class
|
571
|
+
class TestEmbedManyBsonDoc
|
572
572
|
include MongoDoc::Document
|
573
|
-
|
573
|
+
embed_many :subdoc, :class_name => 'SubEmbedManyBsonDoc'
|
574
574
|
end
|
575
575
|
|
576
576
|
it "#to_bson renders a bson representation of the document" do
|
577
|
-
doc =
|
578
|
-
subdoc =
|
577
|
+
doc = TestEmbedManyBsonDoc.new
|
578
|
+
subdoc = SubEmbedManyBsonDoc.new(:attr => "value")
|
579
579
|
bson = doc.to_bson
|
580
580
|
bson["subdoc"] = [subdoc].to_bson
|
581
581
|
doc.subdoc = subdoc
|
@@ -583,14 +583,14 @@ describe "MongoDoc::Document" do
|
|
583
583
|
end
|
584
584
|
|
585
585
|
it "roundtrips" do
|
586
|
-
doc =
|
587
|
-
subdoc =
|
586
|
+
doc = TestEmbedManyBsonDoc.new
|
587
|
+
subdoc = SubEmbedManyBsonDoc.new(:attr => "value")
|
588
588
|
doc.subdoc = subdoc
|
589
589
|
MongoDoc::BSON.decode(doc.to_bson).should == doc
|
590
590
|
end
|
591
591
|
|
592
592
|
it "roundtrips the proxy" do
|
593
|
-
doc =
|
593
|
+
doc = TestEmbedManyBsonDoc.new(:subdoc => SubEmbedManyBsonDoc.new(:attr => "value"))
|
594
594
|
MongoDoc::Associations::CollectionProxy.should === MongoDoc::BSON.decode(doc.to_bson).subdoc
|
595
595
|
end
|
596
596
|
end
|
data/spec/embedded_save_spec.rb
CHANGED
@@ -4,19 +4,19 @@ describe "Saving embedded documents" do
|
|
4
4
|
class NestedDocsRoot
|
5
5
|
include MongoDoc::Document
|
6
6
|
|
7
|
-
|
7
|
+
embed_many :nested_children
|
8
8
|
end
|
9
9
|
|
10
10
|
class NestedChild
|
11
11
|
include MongoDoc::Document
|
12
12
|
|
13
|
-
|
13
|
+
embed :leaf
|
14
14
|
end
|
15
15
|
|
16
16
|
class LeafDoc
|
17
17
|
include MongoDoc::Document
|
18
18
|
|
19
|
-
|
19
|
+
attr_accessor :data
|
20
20
|
end
|
21
21
|
|
22
22
|
let(:leaf) do
|
@@ -42,7 +42,7 @@ describe "Saving embedded documents" do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context "update_attributes naive" do
|
45
|
-
context "with no
|
45
|
+
context "with no embed_many, update_attributes" do
|
46
46
|
let(:root) { NestedChild.new(:leaf => leaf) }
|
47
47
|
|
48
48
|
it "calls the root document's _naive_update_attributes with a full attribute path and not safe" do
|
@@ -56,7 +56,7 @@ describe "Saving embedded documents" do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
context "with
|
59
|
+
context "with embed_many, update_attributes" do
|
60
60
|
let(:root) { NestedDocsRoot.new(:nested_children => [NestedChild.new(:leaf => leaf)]) }
|
61
61
|
|
62
62
|
it "calls the root document's _naive_update_attributes with a full attribute path and not safe" do
|
@@ -78,7 +78,7 @@ describe "Saving embedded documents" do
|
|
78
78
|
leaf.stub(:_id).and_return(leaf_id)
|
79
79
|
end
|
80
80
|
|
81
|
-
context "with no
|
81
|
+
context "with no embed_many, update_attributes" do
|
82
82
|
let(:root) { NestedChild.new(:leaf => leaf) }
|
83
83
|
|
84
84
|
it "calls the root document's _strict_update_attributes with a full attribute path and not safe" do
|
@@ -92,7 +92,7 @@ describe "Saving embedded documents" do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
context "with
|
95
|
+
context "with embed_many, update_attributes" do
|
96
96
|
let(:root) { NestedDocsRoot.new(:nested_children => [NestedChild.new(:leaf => leaf)]) }
|
97
97
|
|
98
98
|
it "calls the root document's _naive_update_attributes with a full attribute path and not safe" do
|
data/spec/finders_spec.rb
CHANGED
data/spec/new_record_spec.rb
CHANGED
@@ -8,10 +8,10 @@ describe "MongoDoc::Document _id and #new_record?" do
|
|
8
8
|
class Parent
|
9
9
|
include MongoDoc::Document
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
embed :child
|
12
|
+
embed_many :children
|
13
13
|
|
14
|
-
|
14
|
+
attr_accessor :data
|
15
15
|
|
16
16
|
validates_presence_of :data
|
17
17
|
end
|
@@ -20,7 +20,7 @@ describe "MongoDoc::Document _id and #new_record?" do
|
|
20
20
|
let(:collection) { stub('collection', :save => id) }
|
21
21
|
let(:child) { Child.new }
|
22
22
|
|
23
|
-
context "as a
|
23
|
+
context "as a embed child" do
|
24
24
|
it "when added to the parent is a new record" do
|
25
25
|
Parent.new(:data => 'data', :child => child)
|
26
26
|
child.should be_new_record
|
@@ -70,7 +70,7 @@ describe "MongoDoc::Document _id and #new_record?" do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context "as a
|
73
|
+
context "as a embed_many child" do
|
74
74
|
it "when added to the parent is a new record" do
|
75
75
|
parent = Parent.new(:data => 'data')
|
76
76
|
parent.children << child
|
data/spec/scope_spec.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Les Hill
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-13 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- features/support/support.rb
|
161
161
|
- features/using_criteria.feature
|
162
162
|
- lib/mongo_doc.rb
|
163
|
+
- lib/mongo_doc/associations.rb
|
163
164
|
- lib/mongo_doc/associations/collection_proxy.rb
|
164
165
|
- lib/mongo_doc/associations/document_proxy.rb
|
165
166
|
- lib/mongo_doc/associations/hash_proxy.rb
|
@@ -225,6 +226,7 @@ files:
|
|
225
226
|
- spec/associations/collection_proxy_spec.rb
|
226
227
|
- spec/associations/document_proxy_spec.rb
|
227
228
|
- spec/associations/hash_proxy_spec.rb
|
229
|
+
- spec/associations_spec.rb
|
228
230
|
- spec/attributes_accessor_spec.rb
|
229
231
|
- spec/attributes_spec.rb
|
230
232
|
- spec/bson_matchers.rb
|
@@ -285,6 +287,7 @@ test_files:
|
|
285
287
|
- spec/associations/collection_proxy_spec.rb
|
286
288
|
- spec/associations/document_proxy_spec.rb
|
287
289
|
- spec/associations/hash_proxy_spec.rb
|
290
|
+
- spec/associations_spec.rb
|
288
291
|
- spec/attributes_accessor_spec.rb
|
289
292
|
- spec/attributes_spec.rb
|
290
293
|
- spec/bson_matchers.rb
|