mongodoc 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.textile +42 -12
  2. data/Rakefile +4 -4
  3. data/TODO +26 -0
  4. data/VERSION +1 -1
  5. data/examples/simple_document.rb +1 -1
  6. data/examples/simple_object.rb +0 -2
  7. data/features/mongodb.yml +6 -5
  8. data/features/removing_documents.feature +68 -0
  9. data/features/step_definitions/collection_steps.rb +3 -3
  10. data/features/step_definitions/document_steps.rb +2 -2
  11. data/features/step_definitions/removing_documents_steps.rb +14 -0
  12. data/features/support/support.rb +2 -2
  13. data/lib/mongodoc.rb +4 -7
  14. data/lib/mongodoc/associations/collection_proxy.rb +103 -0
  15. data/lib/mongodoc/associations/document_proxy.rb +53 -0
  16. data/lib/mongodoc/associations/hash_proxy.rb +96 -0
  17. data/lib/mongodoc/associations/proxy_base.rb +51 -0
  18. data/lib/mongodoc/attributes.rb +49 -17
  19. data/lib/mongodoc/collection.rb +15 -5
  20. data/lib/mongodoc/connection.rb +83 -20
  21. data/lib/mongodoc/criteria.rb +9 -4
  22. data/lib/mongodoc/cursor.rb +9 -3
  23. data/lib/mongodoc/document.rb +37 -24
  24. data/lib/mongodoc/validations/macros.rb +11 -0
  25. data/lib/mongodoc/validations/validates_embedded.rb +13 -0
  26. data/mongodb.example.yml +13 -5
  27. data/mongodoc.gemspec +33 -23
  28. data/spec/associations/collection_proxy_spec.rb +200 -0
  29. data/spec/associations/document_proxy_spec.rb +42 -0
  30. data/spec/associations/hash_proxy_spec.rb +163 -0
  31. data/spec/attributes_spec.rb +113 -47
  32. data/spec/bson_spec.rb +24 -24
  33. data/spec/collection_spec.rb +67 -86
  34. data/spec/connection_spec.rb +98 -150
  35. data/spec/criteria_spec.rb +4 -3
  36. data/spec/cursor_spec.rb +33 -27
  37. data/spec/document_spec.rb +173 -156
  38. data/spec/embedded_save_spec.rb +8 -3
  39. data/spec/new_record_spec.rb +33 -121
  40. metadata +80 -39
  41. data/lib/mongodoc/parent_proxy.rb +0 -44
  42. data/lib/mongodoc/proxy.rb +0 -83
  43. data/spec/parent_proxy_spec.rb +0 -44
  44. data/spec/proxy_spec.rb +0 -80
@@ -19,7 +19,12 @@ describe "Saving embedded documents" do
19
19
  key :data
20
20
  end
21
21
 
22
- let(:leaf) { LeafDoc.new }
22
+ let(:leaf) do
23
+ doc = LeafDoc.new
24
+ doc._id = 'id'
25
+ doc
26
+ end
27
+
23
28
  let(:data) { 'data' }
24
29
 
25
30
  context "#save" do
@@ -91,12 +96,12 @@ describe "Saving embedded documents" do
91
96
  let(:root) { NestedDocsRoot.new(:nested_children => [NestedChild.new(:leaf => leaf)]) }
92
97
 
93
98
  it "calls the root document's _naive_update_attributes with a full attribute path and not safe" do
94
- root.should_receive(:_strict_update_attributes).with({'nested_children.0.leaf.data' => data}, false, 'nested_children.leaf._id' => leaf_id)
99
+ root.should_receive(:_strict_update_attributes).with({'nested_children.0.leaf.data' => data}, false, 'nested_children.0.leaf._id' => leaf_id)
95
100
  leaf.update_attributes(:data => data, :__strict__ => true)
96
101
  end
97
102
 
98
103
  it "(with bang!) calls the root document's _naive_update_attributes with a full attribute path and safe" do
99
- root.should_receive(:_strict_update_attributes).with({'nested_children.0.leaf.data' => data}, true, 'nested_children.leaf._id' => leaf_id)
104
+ root.should_receive(:_strict_update_attributes).with({'nested_children.0.leaf.data' => data}, true, 'nested_children.0.leaf._id' => leaf_id)
100
105
  leaf.update_attributes!(:data => data, :__strict__ => true)
101
106
  end
102
107
  end
@@ -16,199 +16,111 @@ describe "MongoDoc::Document _id and #new_record?" do
16
16
  validates_presence_of :data
17
17
  end
18
18
 
19
- before do
20
- @child = Child.new
21
- end
19
+ let(:id) { 'id' }
20
+ let(:collection) { stub('collection', :save => id) }
21
+ let(:child) { Child.new }
22
22
 
23
- context "as a has one@child" do
23
+ context "as a has_one child" do
24
24
  it "when added to the parent is a new record" do
25
- Parent.new(:data => 'data', :child => @child)
26
- @child.should be_new_record
27
- end
28
-
29
- context "creating" do
30
- before do
31
- @id = 'id'
32
- @collection = stub('collection')
33
- @collection.stub(:insert).and_return(@id)
34
- Parent.stub(:collection).and_return(@collection)
35
- end
36
-
37
- context ".create" do
38
- it "when created is not a new record" do
39
- Parent.create(:data => 'data', :child => @child)
40
- @child.should_not be_new_record
41
- end
42
-
43
- it "if parent is invalid, remains a new record" do
44
- Parent.create(:child =>@child)
45
- @child.should be_new_record
46
- end
47
- end
48
-
49
- context ".create!" do
50
- it "when created is not a new record" do
51
- Parent.create!(:data => 'data', :child => @child)
52
- @child.should_not be_new_record
53
- end
54
-
55
- it "if parent is invalid, remains a new record" do
56
- Parent.create!(:child => @child) rescue nil
57
- @child.should be_new_record
58
- end
59
-
60
- it "when db error is raised, remains a new record" do
61
- @collection.stub(:insert).and_raise(Mongo::OperationFailure)
62
- expect do
63
- Parent.create!(:data => 'data', :child => @child)
64
- end.should raise_error(Mongo::OperationFailure)
65
- @child.should be_new_record
66
- end
67
- end
25
+ Parent.new(:data => 'data', :child => child)
26
+ child.should be_new_record
68
27
  end
69
28
 
70
29
  context "saving" do
71
30
  before do
72
- @id = 'id'
73
- @collection = stub('collection')
74
- @collection.stub(:save).and_return(@id)
75
- Parent.stub(:collection).and_return(@collection)
31
+ Parent.stub(:collection).and_return(collection)
76
32
  end
77
33
 
78
34
  context "#save" do
79
35
  it "when saved is not a new record" do
80
- parent = Parent.new(:data => 'data', :child => @child)
36
+ parent = Parent.new(:data => 'data', :child => child)
81
37
  parent.save
82
- @child.should_not be_new_record
38
+ child.should_not be_new_record
83
39
  end
84
40
 
85
41
  it "if parent is invalid, remains a new record" do
86
- parent = Parent.new(:child => @child)
42
+ parent = Parent.new(:child => child)
87
43
  parent.save
88
- @child.should be_new_record
44
+ child.should be_new_record
89
45
  end
90
46
  end
91
47
 
92
48
  context "#save!" do
93
49
  it "when saved is not a new record" do
94
- parent = Parent.new(:data => 'data', :child => @child)
50
+ parent = Parent.new(:data => 'data', :child => child)
95
51
  parent.save!
96
- @child.should_not be_new_record
52
+ child.should_not be_new_record
97
53
  end
98
54
 
99
55
  it "if parent is invalid, remains a new record" do
100
- parent = Parent.new(:child => @child)
56
+ parent = Parent.new(:child => child)
101
57
  parent.save! rescue nil
102
- @child.should be_new_record
58
+ child.should be_new_record
103
59
  end
104
60
 
105
61
  it "when db error is raised, remains a new record" do
106
- @collection.stub(:save).and_raise(Mongo::OperationFailure)
107
- parent = Parent.new(:data => 'data', :child => @child)
62
+ collection.stub(:save).and_raise(Mongo::OperationFailure)
63
+ parent = Parent.new(:data => 'data', :child => child)
108
64
  expect do
109
65
  parent.save!
110
66
  end.should raise_error(Mongo::OperationFailure)
111
- @child.should be_new_record
67
+ child.should be_new_record
112
68
  end
113
69
  end
114
70
  end
115
71
  end
116
72
 
117
- context "as a has many@child" do
73
+ context "as a has_many child" do
118
74
  it "when added to the parent is a new record" do
119
75
  parent = Parent.new(:data => 'data')
120
- parent.children << @child
121
- @child.should be_new_record
122
- end
123
-
124
- context "creating" do
125
- before do
126
- @id = 'id'
127
- @collection = stub('collection')
128
- @collection.stub(:insert).and_return(@id)
129
- Parent.stub(:collection).and_return(@collection)
130
- end
131
-
132
- context ".create" do
133
- it "when created is not a new record" do
134
- Parent.create(:data => 'data', :children => [@child])
135
- @child.should_not be_new_record
136
- end
137
-
138
- it "if parent is invalid, remains a new record" do
139
- Parent.create(:children => [@child])
140
- @child.should be_new_record
141
- end
142
- end
143
-
144
- context ".create!" do
145
- it "when created is not a new record" do
146
- Parent.create!(:data => 'data', :children => [@child])
147
- @child.should_not be_new_record
148
- end
149
-
150
- it "if parent is invalid, remains a new record" do
151
- Parent.create!(:children => [@child]) rescue nil
152
- @child.should be_new_record
153
- end
154
-
155
- it "when db error is raised, remains a new record" do
156
- @collection.stub(:insert).and_raise(Mongo::OperationFailure)
157
- expect do
158
- Parent.create!(:data => 'data', :children => [@child])
159
- end.should raise_error(Mongo::OperationFailure)
160
- @child.should be_new_record
161
- end
162
- end
76
+ parent.children << child
77
+ child.should be_new_record
163
78
  end
164
79
 
165
80
  context "saving" do
166
81
  before do
167
- @id = 'id'
168
- @collection = stub('collection')
169
- @collection.stub(:save).and_return(@id)
170
- Parent.stub(:collection).and_return(@collection)
82
+ Parent.stub(:collection).and_return(collection)
171
83
  end
172
84
 
173
85
  context "#save" do
174
86
  it "when saved is not a new record" do
175
87
  parent = Parent.new(:data => 'data')
176
- parent.children << @child
88
+ parent.children << child
177
89
  parent.save
178
- @child.should_not be_new_record
90
+ child.should_not be_new_record
179
91
  end
180
92
 
181
93
  it "if parent is invalid, remains a new record" do
182
94
  parent = Parent.new
183
- parent.children << @child
95
+ parent.children << child
184
96
  parent.save
185
- @child.should be_new_record
97
+ child.should be_new_record
186
98
  end
187
99
  end
188
100
 
189
101
  context "#save!" do
190
102
  it "when saved is not a new record" do
191
103
  parent = Parent.new(:data => 'data')
192
- parent.children << @child
104
+ parent.children << child
193
105
  parent.save!
194
- @child.should_not be_new_record
106
+ child.should_not be_new_record
195
107
  end
196
108
 
197
109
  it "if parent is invalid, remains a new record" do
198
110
  parent = Parent.new
199
- parent.children << @child
111
+ parent.children << child
200
112
  parent.save! rescue nil
201
- @child.should be_new_record
113
+ child.should be_new_record
202
114
  end
203
115
 
204
116
  it "when db error is raised, remains a new record" do
205
- @collection.stub(:save).and_raise(Mongo::OperationFailure)
117
+ collection.stub(:save).and_raise(Mongo::OperationFailure)
206
118
  parent = Parent.new(:data => 'data')
207
- parent.children << @child
119
+ parent.children << child
208
120
  expect do
209
121
  parent.save!
210
122
  end.should raise_error(Mongo::OperationFailure)
211
- @child.should be_new_record
123
+ child.should be_new_record
212
124
  end
213
125
  end
214
126
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 2
9
+ version: 0.2.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Les Hill
@@ -9,69 +14,93 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-18 00:00:00 -05:00
17
+ date: 2010-02-16 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: mongo
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - "="
22
26
  - !ruby/object:Gem::Version
23
- version: 0.18.2
24
- version:
27
+ segments:
28
+ - 0
29
+ - 18
30
+ - 3
31
+ version: 0.18.3
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: mongo_ext
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - "="
32
40
  - !ruby/object:Gem::Version
33
- version: 0.18.2
34
- version:
41
+ segments:
42
+ - 0
43
+ - 18
44
+ - 3
45
+ version: 0.18.3
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: durran-validatable
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - "="
42
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 0
58
+ - 1
43
59
  version: 2.0.1
44
- version:
60
+ type: :runtime
61
+ version_requirements: *id003
45
62
  - !ruby/object:Gem::Dependency
46
63
  name: leshill-will_paginate
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
50
66
  requirements:
51
67
  - - "="
52
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 3
72
+ - 11
53
73
  version: 2.3.11
54
- version:
74
+ type: :runtime
75
+ version_requirements: *id004
55
76
  - !ruby/object:Gem::Dependency
56
77
  name: rspec
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
60
80
  requirements:
61
81
  - - "="
62
82
  - !ruby/object:Gem::Version
63
- version: 1.2.9
64
- version:
83
+ segments:
84
+ - 1
85
+ - 3
86
+ - 0
87
+ version: 1.3.0
88
+ type: :development
89
+ version_requirements: *id005
65
90
  - !ruby/object:Gem::Dependency
66
91
  name: cucumber
67
- type: :development
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
70
94
  requirements:
71
95
  - - "="
72
96
  - !ruby/object:Gem::Version
73
- version: 0.4.4
74
- version:
97
+ segments:
98
+ - 0
99
+ - 6
100
+ - 2
101
+ version: 0.6.2
102
+ type: :development
103
+ version_requirements: *id006
75
104
  description: ODM for MongoDB
76
105
  email: leshill@gmail.com
77
106
  executables: []
@@ -81,12 +110,14 @@ extensions: []
81
110
  extra_rdoc_files:
82
111
  - LICENSE
83
112
  - README.textile
113
+ - TODO
84
114
  files:
85
115
  - .document
86
116
  - .gitignore
87
117
  - LICENSE
88
118
  - README.textile
89
119
  - Rakefile
120
+ - TODO
90
121
  - VERSION
91
122
  - data/.gitignore
92
123
  - examples/simple_document.rb
@@ -97,6 +128,7 @@ files:
97
128
  - features/named_scopes.feature
98
129
  - features/new_record.feature
99
130
  - features/partial_updates.feature
131
+ - features/removing_documents.feature
100
132
  - features/saving_an_object.feature
101
133
  - features/step_definitions/collection_steps.rb
102
134
  - features/step_definitions/criteria_steps.rb
@@ -109,10 +141,15 @@ files:
109
141
  - features/step_definitions/objects.rb
110
142
  - features/step_definitions/partial_update_steps.rb
111
143
  - features/step_definitions/query_steps.rb
144
+ - features/step_definitions/removing_documents_steps.rb
112
145
  - features/step_definitions/util_steps.rb
113
146
  - features/support/support.rb
114
147
  - features/using_criteria.feature
115
148
  - lib/mongodoc.rb
149
+ - lib/mongodoc/associations/collection_proxy.rb
150
+ - lib/mongodoc/associations/document_proxy.rb
151
+ - lib/mongodoc/associations/hash_proxy.rb
152
+ - lib/mongodoc/associations/proxy_base.rb
116
153
  - lib/mongodoc/attributes.rb
117
154
  - lib/mongodoc/bson.rb
118
155
  - lib/mongodoc/collection.rb
@@ -137,15 +174,18 @@ files:
137
174
  - lib/mongodoc/ext/time.rb
138
175
  - lib/mongodoc/finders.rb
139
176
  - lib/mongodoc/named_scope.rb
140
- - lib/mongodoc/parent_proxy.rb
141
- - lib/mongodoc/proxy.rb
142
177
  - lib/mongodoc/query.rb
178
+ - lib/mongodoc/validations/macros.rb
179
+ - lib/mongodoc/validations/validates_embedded.rb
143
180
  - mongod.example.yml
144
181
  - mongodb.example.yml
145
182
  - mongodoc.gemspec
146
183
  - perf/mongodoc_runner.rb
147
184
  - perf/ruby_driver_runner.rb
148
185
  - script/console
186
+ - spec/associations/collection_proxy_spec.rb
187
+ - spec/associations/document_proxy_spec.rb
188
+ - spec/associations/hash_proxy_spec.rb
149
189
  - spec/attributes_spec.rb
150
190
  - spec/bson_matchers.rb
151
191
  - spec/bson_spec.rb
@@ -162,8 +202,6 @@ files:
162
202
  - spec/mongodb_pairs.yml
163
203
  - spec/named_scope_spec.rb
164
204
  - spec/new_record_spec.rb
165
- - spec/parent_proxy_spec.rb
166
- - spec/proxy_spec.rb
167
205
  - spec/query_spec.rb
168
206
  - spec/spec.opts
169
207
  - spec/spec_helper.rb
@@ -180,22 +218,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
218
  requirements:
181
219
  - - ">="
182
220
  - !ruby/object:Gem::Version
221
+ segments:
222
+ - 0
183
223
  version: "0"
184
- version:
185
224
  required_rubygems_version: !ruby/object:Gem::Requirement
186
225
  requirements:
187
226
  - - ">="
188
227
  - !ruby/object:Gem::Version
228
+ segments:
229
+ - 0
189
230
  version: "0"
190
- version:
191
231
  requirements: []
192
232
 
193
233
  rubyforge_project:
194
- rubygems_version: 1.3.5
234
+ rubygems_version: 1.3.6.pre.3
195
235
  signing_key:
196
236
  specification_version: 3
197
237
  summary: ODM for MongoDB
198
238
  test_files:
239
+ - spec/associations/collection_proxy_spec.rb
240
+ - spec/associations/document_proxy_spec.rb
241
+ - spec/associations/hash_proxy_spec.rb
199
242
  - spec/attributes_spec.rb
200
243
  - spec/bson_matchers.rb
201
244
  - spec/bson_spec.rb
@@ -210,8 +253,6 @@ test_files:
210
253
  - spec/hash_matchers.rb
211
254
  - spec/named_scope_spec.rb
212
255
  - spec/new_record_spec.rb
213
- - spec/parent_proxy_spec.rb
214
- - spec/proxy_spec.rb
215
256
  - spec/query_spec.rb
216
257
  - spec/spec_helper.rb
217
258
  - examples/simple_document.rb