mongoid 1.1.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +69 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongoid.rb +39 -13
- data/lib/mongoid/associations.rb +1 -0
- data/lib/mongoid/associations/has_many.rb +19 -3
- data/lib/mongoid/attributes.rb +6 -1
- data/lib/mongoid/collection.rb +106 -0
- data/lib/mongoid/collections/cyclic_iterator.rb +34 -0
- data/lib/mongoid/collections/master.rb +28 -0
- data/lib/mongoid/collections/mimic.rb +46 -0
- data/lib/mongoid/collections/operations.rb +39 -0
- data/lib/mongoid/collections/slaves.rb +44 -0
- data/lib/mongoid/commands.rb +1 -0
- data/lib/mongoid/config.rb +61 -9
- data/lib/mongoid/contexts/enumerable.rb +24 -15
- data/lib/mongoid/contexts/mongo.rb +25 -31
- data/lib/mongoid/contexts/paging.rb +2 -2
- data/lib/mongoid/criteria.rb +48 -7
- data/lib/mongoid/criterion/exclusion.rb +2 -0
- data/lib/mongoid/criterion/optional.rb +2 -2
- data/lib/mongoid/cursor.rb +82 -0
- data/lib/mongoid/document.rb +12 -13
- data/lib/mongoid/errors.rb +35 -4
- data/lib/mongoid/extensions.rb +1 -0
- data/lib/mongoid/extensions/array/aliasing.rb +4 -0
- data/lib/mongoid/extensions/string/inflections.rb +44 -1
- data/lib/mongoid/factory.rb +17 -0
- data/lib/mongoid/finders.rb +7 -2
- data/lib/mongoid/matchers/default.rb +6 -0
- data/lib/mongoid/matchers/gt.rb +1 -1
- data/lib/mongoid/matchers/gte.rb +1 -1
- data/lib/mongoid/matchers/lt.rb +1 -1
- data/lib/mongoid/matchers/lte.rb +1 -1
- data/mongoid.gemspec +30 -5
- data/perf/benchmark.rb +5 -3
- data/spec/integration/mongoid/associations_spec.rb +12 -0
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +20 -0
- data/spec/integration/mongoid/criteria_spec.rb +28 -0
- data/spec/integration/mongoid/document_spec.rb +1 -1
- data/spec/integration/mongoid/inheritance_spec.rb +2 -2
- data/spec/models/person.rb +1 -1
- data/spec/spec_helper.rb +9 -4
- data/spec/unit/mongoid/associations/has_many_spec.rb +19 -0
- data/spec/unit/mongoid/associations_spec.rb +9 -0
- data/spec/unit/mongoid/attributes_spec.rb +4 -4
- data/spec/unit/mongoid/collection_spec.rb +113 -0
- data/spec/unit/mongoid/collections/cyclic_iterator_spec.rb +75 -0
- data/spec/unit/mongoid/collections/master_spec.rb +41 -0
- data/spec/unit/mongoid/collections/mimic_spec.rb +43 -0
- data/spec/unit/mongoid/collections/slaves_spec.rb +81 -0
- data/spec/unit/mongoid/commands_spec.rb +7 -0
- data/spec/unit/mongoid/config_spec.rb +52 -1
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +38 -12
- data/spec/unit/mongoid/contexts/mongo_spec.rb +38 -31
- data/spec/unit/mongoid/criteria_spec.rb +20 -12
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +26 -0
- data/spec/unit/mongoid/criterion/optional_spec.rb +13 -0
- data/spec/unit/mongoid/cursor_spec.rb +74 -0
- data/spec/unit/mongoid/document_spec.rb +4 -5
- data/spec/unit/mongoid/errors_spec.rb +5 -9
- data/spec/unit/mongoid/extensions/string/inflections_spec.rb +21 -2
- data/spec/unit/mongoid/factory_spec.rb +16 -0
- data/spec/unit/mongoid_spec.rb +4 -4
- metadata +28 -3
@@ -27,6 +27,32 @@ describe Mongoid::Criterion::Exclusion do
|
|
27
27
|
@criteria.excludes(:title => "Bad").should == @criteria
|
28
28
|
end
|
29
29
|
|
30
|
+
context "when passing an id" do
|
31
|
+
|
32
|
+
it "accepts id" do
|
33
|
+
@criteria.excludes(:id => "1")
|
34
|
+
@criteria.selector.should ==
|
35
|
+
{ :_type =>
|
36
|
+
{ "$in" =>
|
37
|
+
["Doctor", "Person"]
|
38
|
+
},
|
39
|
+
:_id => { "$ne" => "1" }
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "accepts _id" do
|
44
|
+
@criteria.excludes(:_id => "1")
|
45
|
+
@criteria.selector.should ==
|
46
|
+
{ :_type =>
|
47
|
+
{ "$in" =>
|
48
|
+
["Doctor", "Person"]
|
49
|
+
},
|
50
|
+
:_id => { "$ne" => "1" }
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
30
56
|
end
|
31
57
|
|
32
58
|
describe "#not_in" do
|
@@ -139,6 +139,19 @@ describe Mongoid::Criterion::Optional do
|
|
139
139
|
|
140
140
|
end
|
141
141
|
|
142
|
+
context "when an argument is provided" do
|
143
|
+
|
144
|
+
before do
|
145
|
+
@criteria = Mongoid::Criteria.new(Person)
|
146
|
+
@criteria.offset(40)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "delegates to skip" do
|
150
|
+
@criteria.options[:skip].should == 40
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
142
155
|
context "when no option exists" do
|
143
156
|
|
144
157
|
context "when page option exists" do
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Cursor do
|
4
|
+
|
5
|
+
let(:collection) do
|
6
|
+
stub.quacks_like(Mongoid::Collection.allocate)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:proxy) do
|
10
|
+
stub.quacks_like(Mongo::Cursor.allocate)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:cursor) do
|
14
|
+
Mongoid::Cursor.new(collection, proxy)
|
15
|
+
end
|
16
|
+
|
17
|
+
(Mongoid::Cursor::OPERATIONS - [ :timeout ]).each do |name|
|
18
|
+
|
19
|
+
describe "##{name}" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
proxy.expects(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "delegates to the proxy" do
|
26
|
+
cursor.send(name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#collection" do
|
32
|
+
|
33
|
+
it "returns the mongoid collection" do
|
34
|
+
cursor.collection.should == collection
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#each" do
|
39
|
+
|
40
|
+
before do
|
41
|
+
proxy.expects(:each).yields({ "_type" => "Person" })
|
42
|
+
end
|
43
|
+
|
44
|
+
it "yields to the next document" do
|
45
|
+
cursor.each do |doc|
|
46
|
+
doc.attributes.except(:_id).should == Person.new.attributes.except(:_id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#next_document" do
|
52
|
+
|
53
|
+
before do
|
54
|
+
proxy.expects(:next_document).returns({ "_type" => "Person" })
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns the next document from the proxied cursor" do
|
58
|
+
doc = cursor.next_document
|
59
|
+
doc.attributes.except(:_id).should == Person.new.attributes.except(:_id)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#to_a" do
|
64
|
+
|
65
|
+
before do
|
66
|
+
proxy.expects(:to_a).returns([{ "_type" => "Person" }])
|
67
|
+
end
|
68
|
+
|
69
|
+
it "converts the proxy cursor to an array of documents" do
|
70
|
+
docs = cursor.to_a
|
71
|
+
docs[0].attributes.except(:_id).should == Person.new.attributes.except(:_id)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -4,11 +4,10 @@ describe Mongoid::Document do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@database = mock
|
7
|
-
Mongoid.stubs(:database).returns(@database)
|
8
7
|
@collection = stub(:name => "people")
|
9
8
|
@canvas_collection = stub(:name => "canvases")
|
10
|
-
|
11
|
-
|
9
|
+
Mongoid::Collection.stubs(:new).with("people").returns(@collection)
|
10
|
+
Mongoid::Collection.stubs(:new).with("canvases").returns(@canvas_collection)
|
12
11
|
@collection.stubs(:create_index).with(:_type, false)
|
13
12
|
@canvas_collection.stubs(:create_index).with(:_type, false)
|
14
13
|
end
|
@@ -553,7 +552,7 @@ describe Mongoid::Document do
|
|
553
552
|
context "on a parent class" do
|
554
553
|
|
555
554
|
it "sets the collection name and collection for the document" do
|
556
|
-
|
555
|
+
Mongoid::Collection.expects(:new).with("population").returns(@collection)
|
557
556
|
Patient.store_in :population
|
558
557
|
Patient.collection_name.should == "population"
|
559
558
|
end
|
@@ -567,7 +566,7 @@ describe Mongoid::Document do
|
|
567
566
|
end
|
568
567
|
|
569
568
|
it "changes the collection name for the entire hierarchy" do
|
570
|
-
|
569
|
+
Mongoid::Collection.expects(:new).with("browsers").returns(@collection)
|
571
570
|
Firefox.store_in :browsers
|
572
571
|
Canvas.collection_name.should == "browsers"
|
573
572
|
end
|
@@ -46,16 +46,12 @@ describe Mongoid::Errors do
|
|
46
46
|
|
47
47
|
describe "#message" do
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@error = Mongoid::Errors::InvalidDatabase.new
|
53
|
-
end
|
54
|
-
|
55
|
-
it "returns the class name" do
|
56
|
-
@error.message.should == @error.class.name
|
57
|
-
end
|
49
|
+
before do
|
50
|
+
@error = Mongoid::Errors::InvalidDatabase.new("Test")
|
51
|
+
end
|
58
52
|
|
53
|
+
it "returns a message with the bad db object class" do
|
54
|
+
@error.message.should include("String")
|
59
55
|
end
|
60
56
|
|
61
57
|
end
|
@@ -24,8 +24,27 @@ describe Mongoid::Extensions::String::Inflections do
|
|
24
24
|
|
25
25
|
describe "#identify" do
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
context "when parameterizing composite keys" do
|
28
|
+
|
29
|
+
it "converts the string to all lowercase and dashed" do
|
30
|
+
"A Midsummer Night's Dream".identify.should == "a-midsummer-night-quo-s-dream"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when not parameterizing keys" do
|
36
|
+
|
37
|
+
before do
|
38
|
+
Mongoid.parameterize_keys = false
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
Mongoid.parameterize_keys = true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does nothing to the keys" do
|
46
|
+
"A Midsummer Night's Dream".identify.should == "A Midsummer Night's Dream"
|
47
|
+
end
|
29
48
|
end
|
30
49
|
|
31
50
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Factory do
|
4
|
+
|
5
|
+
describe ".build" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@attributes = { "_type" => "Person", "title" => "Sir" }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "instantiates based on the type" do
|
12
|
+
person = Mongoid::Factory.build(@attributes)
|
13
|
+
person.title.should == "Sir"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/unit/mongoid_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongoid do
|
4
4
|
|
5
|
-
describe ".
|
5
|
+
describe ".configure" do
|
6
6
|
|
7
7
|
context "when no block supplied" do
|
8
8
|
|
9
9
|
it "returns the config singleton" do
|
10
|
-
Mongoid.
|
10
|
+
Mongoid.configure.should == Mongoid::Config.instance
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
@@ -15,13 +15,13 @@ describe Mongoid do
|
|
15
15
|
context "when a block is supplied" do
|
16
16
|
|
17
17
|
before do
|
18
|
-
Mongoid.
|
18
|
+
Mongoid.configure do |config|
|
19
19
|
config.allow_dynamic_fields = false
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
after do
|
24
|
-
Mongoid.
|
24
|
+
Mongoid.configure do |config|
|
25
25
|
config.allow_dynamic_fields = true
|
26
26
|
end
|
27
27
|
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: 1.
|
4
|
+
version: 1.2.0
|
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: 2010-
|
12
|
+
date: 2010-02-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 2.0.1
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
46
|
+
name: will_paginate
|
47
47
|
type: :runtime
|
48
48
|
version_requirement:
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -101,6 +101,12 @@ files:
|
|
101
101
|
- lib/mongoid/associations/proxy.rb
|
102
102
|
- lib/mongoid/attributes.rb
|
103
103
|
- lib/mongoid/callbacks.rb
|
104
|
+
- lib/mongoid/collection.rb
|
105
|
+
- lib/mongoid/collections/cyclic_iterator.rb
|
106
|
+
- lib/mongoid/collections/master.rb
|
107
|
+
- lib/mongoid/collections/mimic.rb
|
108
|
+
- lib/mongoid/collections/operations.rb
|
109
|
+
- lib/mongoid/collections/slaves.rb
|
104
110
|
- lib/mongoid/commands.rb
|
105
111
|
- lib/mongoid/commands/create.rb
|
106
112
|
- lib/mongoid/commands/delete.rb
|
@@ -120,10 +126,12 @@ files:
|
|
120
126
|
- lib/mongoid/criterion/exclusion.rb
|
121
127
|
- lib/mongoid/criterion/inclusion.rb
|
122
128
|
- lib/mongoid/criterion/optional.rb
|
129
|
+
- lib/mongoid/cursor.rb
|
123
130
|
- lib/mongoid/document.rb
|
124
131
|
- lib/mongoid/errors.rb
|
125
132
|
- lib/mongoid/extensions.rb
|
126
133
|
- lib/mongoid/extensions/array/accessors.rb
|
134
|
+
- lib/mongoid/extensions/array/aliasing.rb
|
127
135
|
- lib/mongoid/extensions/array/assimilation.rb
|
128
136
|
- lib/mongoid/extensions/array/conversions.rb
|
129
137
|
- lib/mongoid/extensions/array/parentization.rb
|
@@ -144,6 +152,7 @@ files:
|
|
144
152
|
- lib/mongoid/extensions/string/inflections.rb
|
145
153
|
- lib/mongoid/extensions/symbol/inflections.rb
|
146
154
|
- lib/mongoid/extensions/time/conversions.rb
|
155
|
+
- lib/mongoid/factory.rb
|
147
156
|
- lib/mongoid/field.rb
|
148
157
|
- lib/mongoid/fields.rb
|
149
158
|
- lib/mongoid/finders.rb
|
@@ -171,6 +180,7 @@ files:
|
|
171
180
|
- spec/integration/mongoid/associations_spec.rb
|
172
181
|
- spec/integration/mongoid/attributes_spec.rb
|
173
182
|
- spec/integration/mongoid/commands_spec.rb
|
183
|
+
- spec/integration/mongoid/contexts/enumerable_spec.rb
|
174
184
|
- spec/integration/mongoid/criteria_spec.rb
|
175
185
|
- spec/integration/mongoid/document_spec.rb
|
176
186
|
- spec/integration/mongoid/extensions_spec.rb
|
@@ -208,6 +218,11 @@ files:
|
|
208
218
|
- spec/unit/mongoid/associations_spec.rb
|
209
219
|
- spec/unit/mongoid/attributes_spec.rb
|
210
220
|
- spec/unit/mongoid/callbacks_spec.rb
|
221
|
+
- spec/unit/mongoid/collection_spec.rb
|
222
|
+
- spec/unit/mongoid/collections/cyclic_iterator_spec.rb
|
223
|
+
- spec/unit/mongoid/collections/master_spec.rb
|
224
|
+
- spec/unit/mongoid/collections/mimic_spec.rb
|
225
|
+
- spec/unit/mongoid/collections/slaves_spec.rb
|
211
226
|
- spec/unit/mongoid/commands/create_spec.rb
|
212
227
|
- spec/unit/mongoid/commands/delete_all_spec.rb
|
213
228
|
- spec/unit/mongoid/commands/delete_spec.rb
|
@@ -223,6 +238,7 @@ files:
|
|
223
238
|
- spec/unit/mongoid/criterion/exclusion_spec.rb
|
224
239
|
- spec/unit/mongoid/criterion/inclusion_spec.rb
|
225
240
|
- spec/unit/mongoid/criterion/optional_spec.rb
|
241
|
+
- spec/unit/mongoid/cursor_spec.rb
|
226
242
|
- spec/unit/mongoid/document_spec.rb
|
227
243
|
- spec/unit/mongoid/errors_spec.rb
|
228
244
|
- spec/unit/mongoid/extensions/array/accessors_spec.rb
|
@@ -246,6 +262,7 @@ files:
|
|
246
262
|
- spec/unit/mongoid/extensions/string/inflections_spec.rb
|
247
263
|
- spec/unit/mongoid/extensions/symbol/inflections_spec.rb
|
248
264
|
- spec/unit/mongoid/extensions/time/conversions_spec.rb
|
265
|
+
- spec/unit/mongoid/factory_spec.rb
|
249
266
|
- spec/unit/mongoid/field_spec.rb
|
250
267
|
- spec/unit/mongoid/fields_spec.rb
|
251
268
|
- spec/unit/mongoid/finders_spec.rb
|
@@ -301,6 +318,7 @@ test_files:
|
|
301
318
|
- spec/integration/mongoid/associations_spec.rb
|
302
319
|
- spec/integration/mongoid/attributes_spec.rb
|
303
320
|
- spec/integration/mongoid/commands_spec.rb
|
321
|
+
- spec/integration/mongoid/contexts/enumerable_spec.rb
|
304
322
|
- spec/integration/mongoid/criteria_spec.rb
|
305
323
|
- spec/integration/mongoid/document_spec.rb
|
306
324
|
- spec/integration/mongoid/extensions_spec.rb
|
@@ -337,6 +355,11 @@ test_files:
|
|
337
355
|
- spec/unit/mongoid/associations_spec.rb
|
338
356
|
- spec/unit/mongoid/attributes_spec.rb
|
339
357
|
- spec/unit/mongoid/callbacks_spec.rb
|
358
|
+
- spec/unit/mongoid/collection_spec.rb
|
359
|
+
- spec/unit/mongoid/collections/cyclic_iterator_spec.rb
|
360
|
+
- spec/unit/mongoid/collections/master_spec.rb
|
361
|
+
- spec/unit/mongoid/collections/mimic_spec.rb
|
362
|
+
- spec/unit/mongoid/collections/slaves_spec.rb
|
340
363
|
- spec/unit/mongoid/commands/create_spec.rb
|
341
364
|
- spec/unit/mongoid/commands/delete_all_spec.rb
|
342
365
|
- spec/unit/mongoid/commands/delete_spec.rb
|
@@ -352,6 +375,7 @@ test_files:
|
|
352
375
|
- spec/unit/mongoid/criterion/exclusion_spec.rb
|
353
376
|
- spec/unit/mongoid/criterion/inclusion_spec.rb
|
354
377
|
- spec/unit/mongoid/criterion/optional_spec.rb
|
378
|
+
- spec/unit/mongoid/cursor_spec.rb
|
355
379
|
- spec/unit/mongoid/document_spec.rb
|
356
380
|
- spec/unit/mongoid/errors_spec.rb
|
357
381
|
- spec/unit/mongoid/extensions/array/accessors_spec.rb
|
@@ -375,6 +399,7 @@ test_files:
|
|
375
399
|
- spec/unit/mongoid/extensions/string/inflections_spec.rb
|
376
400
|
- spec/unit/mongoid/extensions/symbol/inflections_spec.rb
|
377
401
|
- spec/unit/mongoid/extensions/time/conversions_spec.rb
|
402
|
+
- spec/unit/mongoid/factory_spec.rb
|
378
403
|
- spec/unit/mongoid/field_spec.rb
|
379
404
|
- spec/unit/mongoid/fields_spec.rb
|
380
405
|
- spec/unit/mongoid/finders_spec.rb
|