mongoid 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/VERSION +1 -1
  2. data/lib/mongoid.rb +2 -2
  3. data/lib/mongoid/associations.rb +16 -9
  4. data/lib/mongoid/associations/belongs_to.rb +29 -5
  5. data/lib/mongoid/associations/has_many.rb +12 -0
  6. data/lib/mongoid/associations/has_one.rb +29 -9
  7. data/lib/mongoid/associations/options.rb +5 -0
  8. data/lib/mongoid/associations/relates_to_many.rb +10 -0
  9. data/lib/mongoid/associations/relates_to_one.rb +24 -5
  10. data/lib/mongoid/commands.rb +8 -0
  11. data/lib/mongoid/commands/quick_save.rb +19 -0
  12. data/lib/mongoid/commands/save.rb +1 -1
  13. data/lib/mongoid/criteria.rb +8 -18
  14. data/lib/mongoid/document.rb +27 -59
  15. data/mongoid.gemspec +8 -9
  16. data/spec/integration/mongoid/associations_spec.rb +41 -0
  17. data/spec/integration/mongoid/document_spec.rb +0 -13
  18. data/spec/spec_helper.rb +1 -8
  19. data/spec/unit/mongoid/associations/belongs_to_spec.rb +34 -4
  20. data/spec/unit/mongoid/associations/has_many_spec.rb +9 -0
  21. data/spec/unit/mongoid/associations/has_one_spec.rb +23 -2
  22. data/spec/unit/mongoid/associations/options_spec.rb +12 -1
  23. data/spec/unit/mongoid/associations/relates_to_many_spec.rb +22 -0
  24. data/spec/unit/mongoid/associations/relates_to_one_spec.rb +65 -1
  25. data/spec/unit/mongoid/associations_spec.rb +53 -1
  26. data/spec/unit/mongoid/commands/quick_save_spec.rb +24 -0
  27. data/spec/unit/mongoid/commands/save_spec.rb +2 -2
  28. data/spec/unit/mongoid/commands_spec.rb +107 -102
  29. data/spec/unit/mongoid/criteria_spec.rb +33 -1
  30. metadata +7 -8
  31. data/lib/mongoid/associations/accessor.rb +0 -30
  32. data/lib/mongoid/associations/decorator.rb +0 -27
  33. data/spec/unit/mongoid/associations/accessor_spec.rb +0 -123
  34. data/spec/unit/mongoid/associations/decorator_spec.rb +0 -36
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Commands::QuickSave do
4
+
5
+ describe "#execute" do
6
+
7
+ before do
8
+ @collection = mock
9
+ @document = stub(:collection => @collection, :attributes => {})
10
+ end
11
+
12
+ it "saves the document" do
13
+ @collection.expects(:save).with(@document.attributes)
14
+ Mongoid::Commands::QuickSave.execute(@document)
15
+ end
16
+
17
+ it "returns true" do
18
+ @collection.expects(:save).with(@document.attributes)
19
+ Mongoid::Commands::QuickSave.execute(@document)
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -30,8 +30,8 @@ describe Mongoid::Commands::Save do
30
30
  Mongoid::Commands::Save.execute(@document)
31
31
  end
32
32
 
33
- it "returns the document" do
34
- Mongoid::Commands::Save.execute(@document).should == @document
33
+ it "returns true" do
34
+ Mongoid::Commands::Save.execute(@document).should be_true
35
35
  end
36
36
 
37
37
  context "when the document has a parent" do
@@ -2,185 +2,190 @@ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Commands do
4
4
 
5
- context "instance methods" do
5
+ before do
6
+ @person = Person.new(:_id => Mongo::ObjectID.new.to_s)
7
+ end
6
8
 
7
- before do
8
- @person = Person.new(:_id => Mongo::ObjectID.new.to_s)
9
+ describe "#delete" do
10
+
11
+ it "delegates to the Delete command" do
12
+ Mongoid::Commands::Delete.expects(:execute).with(@person)
13
+ @person.delete
9
14
  end
10
15
 
11
- describe "#delete" do
16
+ end
12
17
 
13
- it "delegates to the Delete command" do
14
- Mongoid::Commands::Delete.expects(:execute).with(@person)
15
- @person.delete
16
- end
18
+ describe "#destroy" do
17
19
 
20
+ it "delegates to the Destroy command" do
21
+ Mongoid::Commands::Destroy.expects(:execute).with(@person)
22
+ @person.destroy
18
23
  end
19
24
 
20
- describe "#destroy" do
25
+ end
21
26
 
22
- it "delegates to the Destroy command" do
23
- Mongoid::Commands::Destroy.expects(:execute).with(@person)
24
- @person.destroy
25
- end
27
+ describe "#save" do
26
28
 
29
+ it "delegates to the Save command" do
30
+ Mongoid::Commands::Save.expects(:execute).with(@person).returns(true)
31
+ @person.save
27
32
  end
28
33
 
29
- describe "#save" do
34
+ context "when document is new" do
35
+
36
+ before do
37
+ @person = Person.new
38
+ end
30
39
 
31
- it "delegates to the Save command" do
32
- Mongoid::Commands::Save.expects(:execute).with(@person).returns(true)
40
+ it "delegates to the Create command" do
41
+ Mongoid::Commands::Create.expects(:execute).with(@person).returns(@person)
33
42
  @person.save
34
43
  end
35
44
 
36
- context "when document is new" do
45
+ end
37
46
 
38
- before do
39
- @person = Person.new
40
- end
47
+ end
41
48
 
42
- it "delegates to the Create command" do
43
- Mongoid::Commands::Create.expects(:execute).with(@person).returns(@person)
44
- @person.save
45
- end
49
+ describe "#save!" do
46
50
 
51
+ context "when validation passes" do
52
+
53
+ it "it returns the person" do
54
+ Mongoid::Commands::Save.expects(:execute).with(@person).returns(@person)
55
+ @person.save!.should == @person
47
56
  end
48
57
 
49
58
  end
50
59
 
51
- describe "#save!" do
60
+ context "when validation fails" do
52
61
 
53
- context "when validation passes" do
62
+ it "it raises a ValidationsError" do
63
+ Mongoid::Commands::Save.expects(:execute).with(@person).returns(false)
64
+ lambda { @person.save! }.should raise_error
65
+ end
54
66
 
55
- it "it returns the person" do
56
- Mongoid::Commands::Save.expects(:execute).with(@person).returns(@person)
57
- @person.save!.should == @person
58
- end
67
+ end
68
+
69
+ context "when document is new" do
59
70
 
71
+ before do
72
+ @person = Person.new
73
+ end
74
+
75
+ it "delegates to the Create command" do
76
+ Mongoid::Commands::Create.expects(:execute).with(@person).returns(@person)
77
+ @person.save!
60
78
  end
61
79
 
62
80
  context "when validation fails" do
63
81
 
64
82
  it "it raises a ValidationsError" do
65
- Mongoid::Commands::Save.expects(:execute).with(@person).returns(false)
83
+ Mongoid::Commands::Create.expects(:execute).with(@person).returns(false)
66
84
  lambda { @person.save! }.should raise_error
67
85
  end
68
86
 
69
87
  end
70
88
 
71
- context "when document is new" do
72
-
73
- before do
74
- @person = Person.new
75
- end
76
-
77
- it "delegates to the Create command" do
78
- Mongoid::Commands::Create.expects(:execute).with(@person).returns(@person)
79
- @person.save!
80
- end
81
-
82
- context "when validation fails" do
89
+ end
83
90
 
84
- it "it raises a ValidationsError" do
85
- Mongoid::Commands::Create.expects(:execute).with(@person).returns(false)
86
- lambda { @person.save! }.should raise_error
87
- end
91
+ end
88
92
 
89
- end
93
+ describe "#quick_save" do
90
94
 
91
- end
95
+ before do
96
+ @person = Person.new
97
+ end
92
98
 
99
+ it "delegates to the QuickSave command" do
100
+ Mongoid::Commands::QuickSave.expects(:execute).with(@person).returns(true)
101
+ @person.quick_save
93
102
  end
94
103
 
95
- describe "#update_attributes" do
104
+ end
96
105
 
97
- it "delegates to the Save command" do
98
- Mongoid::Commands::Save.expects(:execute).with(@person).returns(@person)
99
- @person.update_attributes({})
100
- end
106
+ describe "#update_attributes" do
101
107
 
108
+ it "delegates to the Save command" do
109
+ Mongoid::Commands::Save.expects(:execute).with(@person).returns(@person)
110
+ @person.update_attributes({})
102
111
  end
103
112
 
104
- describe "#update_attributes!" do
113
+ end
105
114
 
106
- context "when validation passes" do
115
+ describe "#update_attributes!" do
107
116
 
108
- it "it returns the person" do
109
- Mongoid::Commands::Save.expects(:execute).with(@person).returns(@person)
110
- @person.update_attributes({}).should == @person
111
- end
117
+ context "when validation passes" do
112
118
 
119
+ it "it returns the person" do
120
+ Mongoid::Commands::Save.expects(:execute).with(@person).returns(@person)
121
+ @person.update_attributes({}).should == @person
113
122
  end
114
123
 
115
- context "when validation fails" do
124
+ end
116
125
 
117
- it "it raises a ValidationsError" do
118
- Mongoid::Commands::Save.expects(:execute).with(@person).returns(false)
119
- lambda { @person.update_attributes!({}) }.should raise_error
120
- end
126
+ context "when validation fails" do
121
127
 
128
+ it "it raises a ValidationsError" do
129
+ Mongoid::Commands::Save.expects(:execute).with(@person).returns(false)
130
+ lambda { @person.update_attributes!({}) }.should raise_error
122
131
  end
123
132
 
124
133
  end
125
134
 
126
135
  end
127
136
 
128
- context "class methods" do
129
-
130
- describe ".create" do
137
+ describe ".create" do
131
138
 
132
- it "delegates to the Create command" do
133
- Mongoid::Commands::Create.expects(:execute)
134
- Person.create
135
- end
136
-
137
- it "returns the document" do
138
- Mongoid::Commands::Create.expects(:execute).returns(Person.new)
139
- Person.create.should_not be_nil
140
- end
139
+ it "delegates to the Create command" do
140
+ Mongoid::Commands::Create.expects(:execute)
141
+ Person.create
142
+ end
141
143
 
144
+ it "returns the document" do
145
+ Mongoid::Commands::Create.expects(:execute).returns(Person.new)
146
+ Person.create.should_not be_nil
142
147
  end
143
148
 
144
- describe ".create!" do
149
+ end
145
150
 
146
- it "delegates to the Create command" do
147
- Mongoid::Commands::Create.expects(:execute).returns(Person.new)
148
- Person.create!
149
- end
151
+ describe ".create!" do
150
152
 
151
- it "returns the document" do
152
- Mongoid::Commands::Create.expects(:execute).returns(Person.new)
153
- Person.create!.should_not be_nil
154
- end
153
+ it "delegates to the Create command" do
154
+ Mongoid::Commands::Create.expects(:execute).returns(Person.new)
155
+ Person.create!
156
+ end
155
157
 
156
- context "when validation fails" do
158
+ it "returns the document" do
159
+ Mongoid::Commands::Create.expects(:execute).returns(Person.new)
160
+ Person.create!.should_not be_nil
161
+ end
157
162
 
158
- it "raises an exception" do
159
- person = stub(:errors => stub(:empty? => false))
160
- Mongoid::Commands::Create.expects(:execute).returns(person)
161
- lambda { Person.create! }.should raise_error
162
- end
163
+ context "when validation fails" do
163
164
 
165
+ it "raises an exception" do
166
+ person = stub(:errors => stub(:empty? => false))
167
+ Mongoid::Commands::Create.expects(:execute).returns(person)
168
+ lambda { Person.create! }.should raise_error
164
169
  end
165
170
 
166
171
  end
167
172
 
168
- describe ".delete_all" do
173
+ end
169
174
 
170
- it "delegates to the DeleteAll command" do
171
- Mongoid::Commands::DeleteAll.expects(:execute).with(Person, {})
172
- Person.delete_all
173
- end
175
+ describe ".delete_all" do
174
176
 
177
+ it "delegates to the DeleteAll command" do
178
+ Mongoid::Commands::DeleteAll.expects(:execute).with(Person, {})
179
+ Person.delete_all
175
180
  end
176
181
 
177
- describe ".destroy_all" do
182
+ end
178
183
 
179
- it "delegates to the DestroyAll command" do
180
- Mongoid::Commands::DestroyAll.expects(:execute).with(Person, {})
181
- Person.destroy_all
182
- end
184
+ describe ".destroy_all" do
183
185
 
186
+ it "delegates to the DestroyAll command" do
187
+ Mongoid::Commands::DestroyAll.expects(:execute).with(Person, {})
188
+ Person.destroy_all
184
189
  end
185
190
 
186
191
  end
@@ -6,6 +6,30 @@ describe Mongoid::Criteria do
6
6
  @criteria = Mongoid::Criteria.new(Person)
7
7
  end
8
8
 
9
+ describe "#[]" do
10
+
11
+ before do
12
+ @criteria.where(:title => "Sir")
13
+ @collection = stub
14
+ @person = Person.new(:title => "Sir")
15
+ @cursor = stub(:count => 10, :collect => [@person])
16
+ end
17
+
18
+ context "when the criteria has not been executed" do
19
+
20
+ before do
21
+ Person.expects(:collection).returns(@collection)
22
+ @collection.expects(:find).with({ :title => "Sir" }, {}).returns(@cursor)
23
+ end
24
+
25
+ it "executes the criteria and returns the element at the index" do
26
+ @criteria[0].should == @person
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
9
33
  describe "#aggregate" do
10
34
 
11
35
  context "when klass provided" do
@@ -210,6 +234,14 @@ describe Mongoid::Criteria do
210
234
 
211
235
  end
212
236
 
237
+ context "when no block is passed" do
238
+
239
+ it "returns self" do
240
+ @criteria.each.should == @criteria
241
+ end
242
+
243
+ end
244
+
213
245
  end
214
246
 
215
247
  describe "#excludes" do
@@ -303,7 +335,7 @@ describe Mongoid::Criteria do
303
335
 
304
336
  it "calls group on the collection with the aggregate js" do
305
337
  @collection.expects(:group).with([:field1], {}, {:group => []}, @reduce).returns(@grouping)
306
- @criteria.select(:field1).group(Person)
338
+ @criteria.select(:field1).group
307
339
  end
308
340
 
309
341
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-09 00:00:00 -05:00
12
+ date: 2009-12-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -99,9 +99,7 @@ files:
99
99
  - VERSION
100
100
  - lib/mongoid.rb
101
101
  - lib/mongoid/associations.rb
102
- - lib/mongoid/associations/accessor.rb
103
102
  - lib/mongoid/associations/belongs_to.rb
104
- - lib/mongoid/associations/decorator.rb
105
103
  - lib/mongoid/associations/has_many.rb
106
104
  - lib/mongoid/associations/has_one.rb
107
105
  - lib/mongoid/associations/options.rb
@@ -114,6 +112,7 @@ files:
114
112
  - lib/mongoid/commands/delete_all.rb
115
113
  - lib/mongoid/commands/destroy.rb
116
114
  - lib/mongoid/commands/destroy_all.rb
115
+ - lib/mongoid/commands/quick_save.rb
117
116
  - lib/mongoid/commands/save.rb
118
117
  - lib/mongoid/commands/validate.rb
119
118
  - lib/mongoid/criteria.rb
@@ -144,12 +143,11 @@ files:
144
143
  - lib/mongoid/versioning.rb
145
144
  - mongoid.gemspec
146
145
  - perf/benchmark.rb
146
+ - spec/integration/mongoid/associations_spec.rb
147
147
  - spec/integration/mongoid/document_spec.rb
148
148
  - spec/spec.opts
149
149
  - spec/spec_helper.rb
150
- - spec/unit/mongoid/associations/accessor_spec.rb
151
150
  - spec/unit/mongoid/associations/belongs_to_spec.rb
152
- - spec/unit/mongoid/associations/decorator_spec.rb
153
151
  - spec/unit/mongoid/associations/has_many_spec.rb
154
152
  - spec/unit/mongoid/associations/has_one_spec.rb
155
153
  - spec/unit/mongoid/associations/options_spec.rb
@@ -162,6 +160,7 @@ files:
162
160
  - spec/unit/mongoid/commands/delete_spec.rb
163
161
  - spec/unit/mongoid/commands/destroy_all_spec.rb
164
162
  - spec/unit/mongoid/commands/destroy_spec.rb
163
+ - spec/unit/mongoid/commands/quick_save_spec.rb
165
164
  - spec/unit/mongoid/commands/save_spec.rb
166
165
  - spec/unit/mongoid/commands/validate_spec.rb
167
166
  - spec/unit/mongoid/commands_spec.rb
@@ -219,11 +218,10 @@ signing_key:
219
218
  specification_version: 3
220
219
  summary: ODM framework for MongoDB
221
220
  test_files:
221
+ - spec/integration/mongoid/associations_spec.rb
222
222
  - spec/integration/mongoid/document_spec.rb
223
223
  - spec/spec_helper.rb
224
- - spec/unit/mongoid/associations/accessor_spec.rb
225
224
  - spec/unit/mongoid/associations/belongs_to_spec.rb
226
- - spec/unit/mongoid/associations/decorator_spec.rb
227
225
  - spec/unit/mongoid/associations/has_many_spec.rb
228
226
  - spec/unit/mongoid/associations/has_one_spec.rb
229
227
  - spec/unit/mongoid/associations/options_spec.rb
@@ -236,6 +234,7 @@ test_files:
236
234
  - spec/unit/mongoid/commands/delete_spec.rb
237
235
  - spec/unit/mongoid/commands/destroy_all_spec.rb
238
236
  - spec/unit/mongoid/commands/destroy_spec.rb
237
+ - spec/unit/mongoid/commands/quick_save_spec.rb
239
238
  - spec/unit/mongoid/commands/save_spec.rb
240
239
  - spec/unit/mongoid/commands/validate_spec.rb
241
240
  - spec/unit/mongoid/commands_spec.rb