mongoid-pre 2.0.0.beta1 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.watchr +15 -10
- data/HISTORY +342 -0
- data/README.rdoc +8 -1
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/mongoid/associations/{embedded_in.rb → belongs_to.rb} +4 -4
- data/lib/mongoid/associations/belongs_to_related.rb +9 -6
- data/lib/mongoid/associations/{embeds_many.rb → has_many.rb} +20 -33
- data/lib/mongoid/associations/has_many_related.rb +4 -28
- data/lib/mongoid/associations/{embeds_one.rb → has_one.rb} +6 -6
- data/lib/mongoid/associations/options.rb +6 -1
- data/lib/mongoid/associations.rb +32 -41
- data/lib/mongoid/attributes.rb +6 -13
- data/lib/mongoid/collection.rb +1 -2
- data/lib/mongoid/commands/delete.rb +1 -1
- data/lib/mongoid/commands/delete_all.rb +1 -4
- data/lib/mongoid/commands/destroy.rb +1 -1
- data/lib/mongoid/commands/destroy_all.rb +1 -3
- data/lib/mongoid/commands/save.rb +0 -1
- data/lib/mongoid/commands.rb +13 -2
- data/lib/mongoid/components.rb +1 -6
- data/lib/mongoid/config.rb +1 -5
- data/lib/mongoid/contexts/enumerable.rb +17 -54
- data/lib/mongoid/contexts/mongo.rb +38 -101
- data/lib/mongoid/contexts/paging.rb +2 -2
- data/lib/mongoid/contexts.rb +0 -21
- data/lib/mongoid/criteria.rb +73 -15
- data/lib/mongoid/criterion/inclusion.rb +0 -2
- data/lib/mongoid/criterion/optional.rb +2 -10
- data/lib/mongoid/document.rb +30 -41
- data/lib/mongoid/extensions.rb +0 -15
- data/lib/mongoid/field.rb +7 -20
- data/lib/mongoid/fields.rb +10 -15
- data/lib/mongoid/finders.rb +98 -10
- data/lib/mongoid/identity.rb +2 -8
- data/lib/mongoid/named_scope.rb +0 -2
- data/lib/mongoid/validations/associated.rb +8 -3
- data/lib/mongoid/validations/uniqueness.rb +7 -2
- data/lib/mongoid/validations.rb +2 -2
- data/lib/mongoid/versioning.rb +1 -1
- data/lib/mongoid.rb +5 -21
- data/mongoid.gemspec +19 -59
- data/spec/integration/mongoid/associations_spec.rb +3 -42
- data/spec/integration/mongoid/attributes_spec.rb +2 -2
- data/spec/integration/mongoid/commands_spec.rb +13 -27
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +0 -13
- data/spec/integration/mongoid/criteria_spec.rb +3 -50
- data/spec/integration/mongoid/document_spec.rb +5 -72
- data/spec/integration/mongoid/finders_spec.rb +28 -85
- data/spec/models/address.rb +3 -3
- data/spec/models/animal.rb +2 -2
- data/spec/models/country_code.rb +2 -2
- data/spec/models/game.rb +1 -2
- data/spec/models/inheritance.rb +5 -5
- data/spec/models/location.rb +2 -2
- data/spec/models/name.rb +3 -3
- data/spec/models/namespacing.rb +2 -2
- data/spec/models/patient.rb +0 -2
- data/spec/models/person.rb +4 -6
- data/spec/models/pet.rb +3 -3
- data/spec/models/pet_owner.rb +3 -3
- data/spec/models/phone.rb +3 -3
- data/spec/models/post.rb +1 -1
- data/spec/models/translation.rb +2 -2
- data/spec/models/vet_visit.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +0 -4
- data/spec/unit/mongoid/associations/{embedded_in_spec.rb → belongs_to_spec.rb} +11 -11
- data/spec/unit/mongoid/associations/has_many_related_spec.rb +14 -45
- data/spec/unit/mongoid/associations/{embeds_many_spec.rb → has_many_spec.rb} +34 -79
- data/spec/unit/mongoid/associations/{embeds_one_spec.rb → has_one_spec.rb} +18 -18
- data/spec/unit/mongoid/associations/options_spec.rb +19 -20
- data/spec/unit/mongoid/associations_spec.rb +12 -74
- data/spec/unit/mongoid/attributes_spec.rb +51 -83
- data/spec/unit/mongoid/collection_spec.rb +0 -46
- data/spec/unit/mongoid/commands/delete_all_spec.rb +8 -9
- data/spec/unit/mongoid/commands/delete_spec.rb +3 -6
- data/spec/unit/mongoid/commands/destroy_all_spec.rb +2 -0
- data/spec/unit/mongoid/commands/destroy_spec.rb +3 -10
- data/spec/unit/mongoid/commands_spec.rb +11 -20
- data/spec/unit/mongoid/config_spec.rb +0 -18
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +11 -198
- data/spec/unit/mongoid/contexts/mongo_spec.rb +54 -357
- data/spec/unit/mongoid/criteria_spec.rb +78 -107
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +13 -3
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +19 -25
- data/spec/unit/mongoid/criterion/optional_spec.rb +18 -25
- data/spec/unit/mongoid/document_spec.rb +34 -71
- data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
- data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +3 -0
- data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -16
- data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
- data/spec/unit/mongoid/field_spec.rb +0 -62
- data/spec/unit/mongoid/fields_spec.rb +0 -33
- data/spec/unit/mongoid/finders_spec.rb +1 -37
- data/spec/unit/mongoid/identity_spec.rb +6 -47
- data/spec/unit/mongoid/named_scope_spec.rb +2 -15
- data/spec/unit/mongoid/scope_spec.rb +1 -1
- data/spec/unit/mongoid/validations/uniqueness_spec.rb +3 -3
- data/spec/unit/mongoid_spec.rb +2 -11
- metadata +14 -64
- data/lib/mongoid/associations/meta_data.rb +0 -28
- data/lib/mongoid/contexts/ids.rb +0 -25
- data/lib/mongoid/deprecation.rb +0 -22
- data/lib/mongoid/dirty.rb +0 -203
- data/lib/mongoid/extensions/big_decimal/conversions.rb +0 -19
- data/lib/mongoid/extensions/binary/conversions.rb +0 -17
- data/lib/mongoid/extensions/objectid/conversions.rb +0 -15
- data/lib/mongoid/extras.rb +0 -61
- data/lib/mongoid/javascript/functions.yml +0 -37
- data/lib/mongoid/javascript.rb +0 -21
- data/lib/mongoid/observable.rb +0 -30
- data/lib/mongoid/paths.rb +0 -54
- data/lib/mongoid/persistence/command.rb +0 -20
- data/lib/mongoid/persistence/insert.rb +0 -71
- data/lib/mongoid/persistence/update.rb +0 -78
- data/lib/mongoid/persistence.rb +0 -27
- data/lib/mongoid/state.rb +0 -32
- data/spec/integration/mongoid/dirty_spec.rb +0 -70
- data/spec/integration/mongoid/persistence/update_spec.rb +0 -46
- data/spec/models/callbacks.rb +0 -18
- data/spec/unit/mongoid/associations/meta_data_spec.rb +0 -88
- data/spec/unit/mongoid/contexts_spec.rb +0 -25
- data/spec/unit/mongoid/deprecation_spec.rb +0 -24
- data/spec/unit/mongoid/dirty_spec.rb +0 -286
- data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extras_spec.rb +0 -102
- data/spec/unit/mongoid/javascript_spec.rb +0 -48
- data/spec/unit/mongoid/observable_spec.rb +0 -46
- data/spec/unit/mongoid/paths_spec.rb +0 -124
- data/spec/unit/mongoid/persistence/insert_spec.rb +0 -175
- data/spec/unit/mongoid/persistence/update_spec.rb +0 -148
- data/spec/unit/mongoid/persistence_spec.rb +0 -40
- data/spec/unit/mongoid/state_spec.rb +0 -83
@@ -67,73 +67,6 @@ describe Mongoid::Document do
|
|
67
67
|
|
68
68
|
end
|
69
69
|
|
70
|
-
describe "#eql?" do
|
71
|
-
|
72
|
-
context "when other object is a Document" do
|
73
|
-
|
74
|
-
context "when attributes are equal" do
|
75
|
-
|
76
|
-
before do
|
77
|
-
@document = Person.new(:_id => 1, :title => "Sir")
|
78
|
-
@other = Person.new(:_id => 1, :title => "Sir")
|
79
|
-
end
|
80
|
-
|
81
|
-
it "returns true" do
|
82
|
-
@document.eql?(@other).should be_true
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when attributes are not equal" do
|
88
|
-
|
89
|
-
before do
|
90
|
-
@document = Person.new(:title => "Sir")
|
91
|
-
@other = Person.new(:title => "Madam")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "returns false" do
|
95
|
-
@document.eql?(@other).should_not be_true
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
context "when other object is not a Document" do
|
103
|
-
|
104
|
-
it "returns false" do
|
105
|
-
Person.new.eql?("Test").should be_false
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when comapring parent to its subclass" do
|
111
|
-
|
112
|
-
it "returns false" do
|
113
|
-
Canvas.new.eql?(Firefox.new).should_not be_true
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "#hash" do
|
121
|
-
|
122
|
-
before do
|
123
|
-
@document = Person.new(:_id => 1, :title => "Sir")
|
124
|
-
@other = Person.new(:_id => 2, :title => "Sir")
|
125
|
-
end
|
126
|
-
|
127
|
-
it "deligates to id" do
|
128
|
-
@document.hash.should == @document.id.hash
|
129
|
-
end
|
130
|
-
|
131
|
-
it "has unique hash per id" do
|
132
|
-
@document.hash.should_not == @other.hash
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
70
|
describe "#alias_method_chain" do
|
138
71
|
|
139
72
|
context "on a field setter" do
|
@@ -471,6 +404,34 @@ describe Mongoid::Document do
|
|
471
404
|
|
472
405
|
end
|
473
406
|
|
407
|
+
describe "#new_record?" do
|
408
|
+
|
409
|
+
context "when the object has been saved" do
|
410
|
+
|
411
|
+
before do
|
412
|
+
@person = Person.new(:_id => "1")
|
413
|
+
end
|
414
|
+
|
415
|
+
it "returns false" do
|
416
|
+
@person.new_record?.should be_false
|
417
|
+
end
|
418
|
+
|
419
|
+
end
|
420
|
+
|
421
|
+
context "when the object has not been saved" do
|
422
|
+
|
423
|
+
before do
|
424
|
+
@person = Person.new
|
425
|
+
end
|
426
|
+
|
427
|
+
it "returns true" do
|
428
|
+
@person.new_record?.should be_true
|
429
|
+
end
|
430
|
+
|
431
|
+
end
|
432
|
+
|
433
|
+
end
|
434
|
+
|
474
435
|
describe "#_parent" do
|
475
436
|
|
476
437
|
before do
|
@@ -526,10 +487,6 @@ describe Mongoid::Document do
|
|
526
487
|
@person.attributes.should == @attributes
|
527
488
|
end
|
528
489
|
|
529
|
-
it 'should return a person object' do
|
530
|
-
@person.reload.should be_kind_of(Person)
|
531
|
-
end
|
532
|
-
|
533
490
|
end
|
534
491
|
|
535
492
|
describe "#remove" do
|
@@ -561,7 +518,9 @@ describe Mongoid::Document do
|
|
561
518
|
@person.remove(@name)
|
562
519
|
@person.name.should be_nil
|
563
520
|
end
|
521
|
+
|
564
522
|
end
|
523
|
+
|
565
524
|
end
|
566
525
|
|
567
526
|
describe "#_root" do
|
@@ -579,6 +538,7 @@ describe Mongoid::Document do
|
|
579
538
|
it "returns self" do
|
580
539
|
@person._root.should == @person
|
581
540
|
end
|
541
|
+
|
582
542
|
end
|
583
543
|
|
584
544
|
context "when document is embedded one level" do
|
@@ -586,6 +546,7 @@ describe Mongoid::Document do
|
|
586
546
|
it "returns the parent" do
|
587
547
|
@phone_number._root.should == @person
|
588
548
|
end
|
549
|
+
|
589
550
|
end
|
590
551
|
|
591
552
|
context "when document is embedded multiple levels" do
|
@@ -593,7 +554,9 @@ describe Mongoid::Document do
|
|
593
554
|
it "returns the top level parent" do
|
594
555
|
@country_code._root.should == @person
|
595
556
|
end
|
557
|
+
|
596
558
|
end
|
559
|
+
|
597
560
|
end
|
598
561
|
|
599
562
|
describe ".store_in" do
|
@@ -10,8 +10,8 @@ describe Mongoid::Extensions::Array::Conversions do
|
|
10
10
|
Person.new(:_id => 2, :title => "Madam")
|
11
11
|
]
|
12
12
|
array.mongoidize.should ==
|
13
|
-
[ HashWithIndifferentAccess.new({ :_id => 1, :title => "Sir", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0
|
14
|
-
HashWithIndifferentAccess.new({ :_id => 2, :title => "Madam", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0
|
13
|
+
[ HashWithIndifferentAccess.new({ :_id => 1, :title => "Sir", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0 }),
|
14
|
+
HashWithIndifferentAccess.new({ :_id => 2, :title => "Madam", :age => 100, :_type => "Person", "blood_alcohol_content" => 0.0 }) ]
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -6,14 +6,7 @@ describe Mongoid::Extensions::Object::Conversions do
|
|
6
6
|
|
7
7
|
it "returns its attributes" do
|
8
8
|
Person.new(:_id => 1, :title => "Sir").mongoidize.should ==
|
9
|
-
{
|
10
|
-
"_id" => 1,
|
11
|
-
"title" => "Sir",
|
12
|
-
"age" => 100,
|
13
|
-
"_type" => "Person",
|
14
|
-
"blood_alcohol_content" => 0.0,
|
15
|
-
"pets" => false
|
16
|
-
}
|
9
|
+
{ "_id" => 1, "title" => "Sir", "age" => 100, "_type" => "Person", "blood_alcohol_content" => 0.0 }
|
17
10
|
end
|
18
11
|
|
19
12
|
end
|
@@ -35,14 +28,7 @@ describe Mongoid::Extensions::Object::Conversions do
|
|
35
28
|
context "when object has attributes" do
|
36
29
|
|
37
30
|
before do
|
38
|
-
@attributes = {
|
39
|
-
"_id" => "test",
|
40
|
-
"title" => "Sir",
|
41
|
-
"age" => 100,
|
42
|
-
"_type" => "Person",
|
43
|
-
"blood_alcohol_content" => 0.0,
|
44
|
-
"pets" => false
|
45
|
-
}
|
31
|
+
@attributes = { "_id" => "test", "title" => "Sir", "age" => 100, "_type" => "Person", "blood_alcohol_content" => 0.0 }
|
46
32
|
@person = Person.new(@attributes)
|
47
33
|
end
|
48
34
|
|
@@ -2,42 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongoid::Field do
|
4
4
|
|
5
|
-
describe "#accessible?" do
|
6
|
-
|
7
|
-
context "when value is not set" do
|
8
|
-
|
9
|
-
before do
|
10
|
-
@field = Mongoid::Field.new(:name)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "defaults to true" do
|
14
|
-
@field.accessible?.should be_true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when set to true" do
|
19
|
-
|
20
|
-
before do
|
21
|
-
@field = Mongoid::Field.new(:name, :accessible => true)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns true" do
|
25
|
-
@field.accessible?.should be_true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when set to false" do
|
30
|
-
|
31
|
-
before do
|
32
|
-
@field = Mongoid::Field.new(:name, :accessible => false)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns false" do
|
36
|
-
@field.accessible?.should be_false
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
5
|
describe "#default" do
|
42
6
|
|
43
7
|
before do
|
@@ -48,32 +12,6 @@ describe Mongoid::Field do
|
|
48
12
|
@field.default.should == 0
|
49
13
|
end
|
50
14
|
|
51
|
-
context "when the field is an array" do
|
52
|
-
|
53
|
-
before do
|
54
|
-
@field = Mongoid::Field.new(:vals, :type => Array, :default => [ "first" ])
|
55
|
-
end
|
56
|
-
|
57
|
-
it "dups the array" do
|
58
|
-
array = @field.default
|
59
|
-
array << "second"
|
60
|
-
@field.default.should == [ "first" ]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "when the field is a hash" do
|
65
|
-
|
66
|
-
before do
|
67
|
-
@field = Mongoid::Field.new(:vals, :type => Hash, :default => { :key => "value" })
|
68
|
-
end
|
69
|
-
|
70
|
-
it "dups the hash" do
|
71
|
-
hash = @field.default
|
72
|
-
hash[:key_two] = "value2"
|
73
|
-
@field.default.should == { :key => "value" }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
15
|
end
|
78
16
|
|
79
17
|
describe "#name" do
|
@@ -12,29 +12,6 @@ describe Mongoid::Fields do
|
|
12
12
|
|
13
13
|
describe "#defaults" do
|
14
14
|
|
15
|
-
context "with defaults specified as a non-primitive" do
|
16
|
-
|
17
|
-
before do
|
18
|
-
Person.field(:hash_testing, :type => Hash, :default => {})
|
19
|
-
Person.field(:array_testing, :type => Array, :default => [])
|
20
|
-
@first_person = Person.new
|
21
|
-
@second_person = Person.new
|
22
|
-
end
|
23
|
-
|
24
|
-
after do
|
25
|
-
Person.fields.delete("hash_testing")
|
26
|
-
Person.fields.delete("array_testing")
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should not return the same object when calling defaults with a default hash" do
|
30
|
-
@first_person.hash_testing.object_id.should_not == @second_person.hash_testing.object_id
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should not return the same object when calling defaults with a default array" do
|
34
|
-
@first_person.array_testing.object_id.should_not == @second_person.array_testing.object_id
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
15
|
context "on parent classes" do
|
39
16
|
|
40
17
|
before do
|
@@ -80,12 +57,6 @@ describe Mongoid::Fields do
|
|
80
57
|
@person.testing.should == "Testy"
|
81
58
|
end
|
82
59
|
|
83
|
-
it "adds an reader method with a question mark" do
|
84
|
-
@person = Person.new(:testing => "Test")
|
85
|
-
@person.testing?.should be_true
|
86
|
-
Person.new.testing?.should be_false
|
87
|
-
end
|
88
|
-
|
89
60
|
end
|
90
61
|
|
91
62
|
context "when type is an object" do
|
@@ -102,10 +73,6 @@ describe Mongoid::Fields do
|
|
102
73
|
{ "name" => "Jack and Coke" }
|
103
74
|
end
|
104
75
|
|
105
|
-
it "adds an reader method with a question mark" do
|
106
|
-
@person.mixed_drink?.should be_true
|
107
|
-
end
|
108
|
-
|
109
76
|
end
|
110
77
|
|
111
78
|
context "when type is a boolean" do
|
@@ -40,24 +40,6 @@ describe Mongoid::Finders do
|
|
40
40
|
|
41
41
|
end
|
42
42
|
|
43
|
-
describe ".all_in" do
|
44
|
-
|
45
|
-
it "returns a new criteria with select conditions added" do
|
46
|
-
criteria = Person.all_in(:aliases => [ "Bond", "007" ])
|
47
|
-
criteria.selector.should == { :aliases => { "$all" => [ "Bond", "007" ] } }
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
describe ".any_in" do
|
53
|
-
|
54
|
-
it "returns a new criteria with select conditions added" do
|
55
|
-
criteria = Person.any_in(:aliases => [ "Bond", "007" ])
|
56
|
-
criteria.selector.should == { :aliases => { "$in" => [ "Bond", "007" ] } }
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
43
|
describe ".count" do
|
62
44
|
|
63
45
|
before do
|
@@ -83,15 +65,6 @@ describe Mongoid::Finders do
|
|
83
65
|
|
84
66
|
end
|
85
67
|
|
86
|
-
describe ".excludes" do
|
87
|
-
|
88
|
-
it "returns a new criteria with select conditions added" do
|
89
|
-
criteria = Person.excludes(:title => "Sir")
|
90
|
-
criteria.selector.should == { :title => { "$ne" => "Sir" } }
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
68
|
describe ".find" do
|
96
69
|
|
97
70
|
before do
|
@@ -323,15 +296,6 @@ describe Mongoid::Finders do
|
|
323
296
|
|
324
297
|
end
|
325
298
|
|
326
|
-
describe ".not_in" do
|
327
|
-
|
328
|
-
it "returns a new criteria with select conditions added" do
|
329
|
-
criteria = Person.not_in(:aliases => [ "Bond", "007" ])
|
330
|
-
criteria.selector.should == { :aliases => { "$nin" => [ "Bond", "007" ] } }
|
331
|
-
end
|
332
|
-
|
333
|
-
end
|
334
|
-
|
335
299
|
describe ".paginate" do
|
336
300
|
|
337
301
|
before do
|
@@ -396,7 +360,7 @@ describe Mongoid::Finders do
|
|
396
360
|
|
397
361
|
it "returns a new criteria with select conditions added" do
|
398
362
|
criteria = Person.where(:title => "Sir")
|
399
|
-
criteria.selector.should == { :title => "Sir" }
|
363
|
+
criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir" }
|
400
364
|
end
|
401
365
|
|
402
366
|
end
|
@@ -6,30 +6,9 @@ describe Mongoid::Identity do
|
|
6
6
|
|
7
7
|
let(:name) { Name.new }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Mongoid::Identity.create(name)
|
13
|
-
name._type.should == "Name"
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when not persisting types" do
|
19
|
-
|
20
|
-
before do
|
21
|
-
Mongoid.persist_types = false
|
22
|
-
@name = Name.new
|
23
|
-
end
|
24
|
-
|
25
|
-
after do
|
26
|
-
Mongoid.persist_types = true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "does not set the type" do
|
30
|
-
@name._type.should be_nil
|
31
|
-
end
|
32
|
-
|
9
|
+
it "sets the document _type to the class name" do
|
10
|
+
Mongoid::Identity.create(name)
|
11
|
+
name._type.should == "Name"
|
33
12
|
end
|
34
13
|
|
35
14
|
it "returns the document" do
|
@@ -61,29 +40,9 @@ describe Mongoid::Identity do
|
|
61
40
|
Mongo::ObjectID.expects(:new).returns(@object_id)
|
62
41
|
end
|
63
42
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
Mongoid.use_object_ids = true
|
68
|
-
end
|
69
|
-
|
70
|
-
after do
|
71
|
-
Mongoid.use_object_ids = false
|
72
|
-
end
|
73
|
-
|
74
|
-
it "sets the id to a mongo object id" do
|
75
|
-
Mongoid::Identity.create(@person)
|
76
|
-
@person.id.should == @object_id
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "when not using object ids" do
|
81
|
-
|
82
|
-
it "sets the id to a mongo object id string" do
|
83
|
-
Mongoid::Identity.create(@person)
|
84
|
-
@person.id.should == "1"
|
85
|
-
end
|
86
|
-
|
43
|
+
it "sets the id to a mongo object id" do
|
44
|
+
Mongoid::Identity.create(@person)
|
45
|
+
@person.id.should == "1"
|
87
46
|
end
|
88
47
|
|
89
48
|
end
|
@@ -17,7 +17,6 @@ describe Mongoid::NamedScope do
|
|
17
17
|
named_scope :inactive, :where => { :active => false }
|
18
18
|
named_scope :frags_over, lambda { |count| { :where => { :frags.gt => count } } }
|
19
19
|
named_scope :deaths_under, lambda { |count| criteria.where(:deaths.lt => count) }
|
20
|
-
scope :deaths_over, lambda { |count| criteria.where(:deaths.gt => count) }
|
21
20
|
|
22
21
|
class << self
|
23
22
|
def alive
|
@@ -74,22 +73,10 @@ describe Mongoid::NamedScope do
|
|
74
73
|
|
75
74
|
context "when a block is supplied" do
|
76
75
|
|
77
|
-
it "adds
|
78
|
-
Player.should
|
76
|
+
it "adds the block as an extension" do
|
77
|
+
Player.active.extension.should == "extension"
|
79
78
|
end
|
80
79
|
|
81
|
-
it "adds the scope to the scopes" do
|
82
|
-
Player.scopes.should include(:deaths_over)
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
describe ".scope" do
|
90
|
-
|
91
|
-
it "aliases to named_scope" do
|
92
|
-
Player.should respond_to(:deaths_over)
|
93
80
|
end
|
94
81
|
|
95
82
|
end
|
@@ -14,7 +14,7 @@ describe Mongoid::Validations::UniquenessValidator do
|
|
14
14
|
|
15
15
|
before do
|
16
16
|
@criteria = stub(:empty? => false)
|
17
|
-
Person.expects(:where).with(
|
17
|
+
Person.expects(:where).with(:title => "Sir").returns(@criteria)
|
18
18
|
validator.validate_each(@document, :title, "Sir")
|
19
19
|
end
|
20
20
|
|
@@ -28,11 +28,11 @@ describe Mongoid::Validations::UniquenessValidator do
|
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
-
context "when no
|
31
|
+
context "when no document exists with the attribute" do
|
32
32
|
|
33
33
|
before do
|
34
34
|
@criteria = stub(:empty? => true)
|
35
|
-
Person.expects(:where).with(
|
35
|
+
Person.expects(:where).with(:title => "Sir").returns(@criteria)
|
36
36
|
validator.validate_each(@document, :title, "Sir")
|
37
37
|
end
|
38
38
|
|
data/spec/unit/mongoid_spec.rb
CHANGED
@@ -9,6 +9,7 @@ describe Mongoid do
|
|
9
9
|
it "returns the config singleton" do
|
10
10
|
Mongoid.configure.should == Mongoid::Config.instance
|
11
11
|
end
|
12
|
+
|
12
13
|
end
|
13
14
|
|
14
15
|
context "when a block is supplied" do
|
@@ -28,19 +29,9 @@ describe Mongoid do
|
|
28
29
|
it "sets the values on the config instance" do
|
29
30
|
Mongoid.allow_dynamic_fields.should be_false
|
30
31
|
end
|
31
|
-
end
|
32
|
-
end
|
33
32
|
|
34
|
-
describe ".deprecate" do
|
35
|
-
|
36
|
-
before do
|
37
|
-
@deprecation = mock
|
38
|
-
Mongoid::Deprecation.expects(:instance).returns(@deprecation)
|
39
33
|
end
|
40
34
|
|
41
|
-
it "calls alert on the deprecation singleton" do
|
42
|
-
@deprecation.expects(:alert).with("testing")
|
43
|
-
Mongoid.deprecate("testing")
|
44
|
-
end
|
45
35
|
end
|
36
|
+
|
46
37
|
end
|