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
@@ -1,175 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::Persistence::Insert do
|
4
|
-
|
5
|
-
let(:document) do
|
6
|
-
Patient.new(:title => "Mr")
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:address) do
|
10
|
-
Address.new(:street => "Oxford St")
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:collection) do
|
14
|
-
stub.quacks_like(Mongoid::Collection.allocate)
|
15
|
-
end
|
16
|
-
|
17
|
-
before do
|
18
|
-
document.stubs(:collection).returns(collection)
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#initialize" do
|
22
|
-
|
23
|
-
let(:insert) do
|
24
|
-
Mongoid::Persistence::Insert.new(document)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "sets the document" do
|
28
|
-
insert.document.should == document
|
29
|
-
end
|
30
|
-
|
31
|
-
it "sets the collection" do
|
32
|
-
insert.collection.should == document.collection
|
33
|
-
end
|
34
|
-
|
35
|
-
it "defaults validation to true" do
|
36
|
-
insert.validate.should == true
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets the options" do
|
40
|
-
insert.options.should ==
|
41
|
-
{ :safe => Mongoid.persist_in_safe_mode }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#persist" do
|
46
|
-
|
47
|
-
def root_set_expectation
|
48
|
-
lambda {
|
49
|
-
collection.expects(:insert).with(
|
50
|
-
document.raw_attributes,
|
51
|
-
:safe => true
|
52
|
-
).returns("Object")
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def root_push_expectation
|
57
|
-
lambda {
|
58
|
-
collection.expects(:update).with(
|
59
|
-
{ "_id" => document.id },
|
60
|
-
{ "addresses" => { "$push" => address.raw_attributes } },
|
61
|
-
:safe => true
|
62
|
-
).returns("Object")
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
let(:insert) do
|
67
|
-
Mongoid::Persistence::Insert.new(document)
|
68
|
-
end
|
69
|
-
|
70
|
-
context "when the document is valid" do
|
71
|
-
|
72
|
-
it "inserts the new document" do
|
73
|
-
root_set_expectation.call
|
74
|
-
insert.persist
|
75
|
-
end
|
76
|
-
|
77
|
-
it "returns the document" do
|
78
|
-
root_set_expectation.call
|
79
|
-
insert.persist.should == document
|
80
|
-
end
|
81
|
-
|
82
|
-
it "sets new_record to false" do
|
83
|
-
root_set_expectation.call
|
84
|
-
insert.persist
|
85
|
-
document.new_record?.should == false
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "when the document is not valid" do
|
90
|
-
|
91
|
-
before do
|
92
|
-
document.stubs(:valid?).returns(false)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "returns the document" do
|
96
|
-
insert.persist.should == document
|
97
|
-
end
|
98
|
-
|
99
|
-
it "leaves the document as a new record" do
|
100
|
-
insert.persist
|
101
|
-
document.new_record?.should == true
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "when not validating" do
|
106
|
-
|
107
|
-
before do
|
108
|
-
insert.instance_variable_set(:@validate, false)
|
109
|
-
document.stubs(:valid?).returns(false)
|
110
|
-
end
|
111
|
-
|
112
|
-
after do
|
113
|
-
insert.instance_variable_set(:@validate, true)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "inserts the document in the database" do
|
117
|
-
root_set_expectation.call
|
118
|
-
insert.persist
|
119
|
-
document.new_record?.should == false
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context "when the document is embedded" do
|
124
|
-
|
125
|
-
context "when the embedded document is an embeds_one" do
|
126
|
-
|
127
|
-
context "when the parent is new" do
|
128
|
-
|
129
|
-
it "notifies its changes to parent and inserts the parent"
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
context "when the parent is not new" do
|
134
|
-
|
135
|
-
it "performs an in place $set on the embedded document"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "when the embedded document is an embeds_many" do
|
140
|
-
|
141
|
-
before do
|
142
|
-
document.addresses << address
|
143
|
-
end
|
144
|
-
|
145
|
-
context "when the parent is new" do
|
146
|
-
|
147
|
-
let(:insert) do
|
148
|
-
Mongoid::Persistence::Insert.new(address)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "notifies its changes to the parent and inserts the parent" do
|
152
|
-
root_set_expectation.call
|
153
|
-
insert.persist.should == address
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context "when the parent is not new" do
|
158
|
-
|
159
|
-
let(:insert) do
|
160
|
-
Mongoid::Persistence::Insert.new(address)
|
161
|
-
end
|
162
|
-
|
163
|
-
before do
|
164
|
-
document.instance_variable_set(:@new_record, false)
|
165
|
-
end
|
166
|
-
|
167
|
-
it "performs a $push on the embedded array" do
|
168
|
-
root_push_expectation.call
|
169
|
-
insert.persist.should == address
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::Persistence::Update do
|
4
|
-
|
5
|
-
let(:document) do
|
6
|
-
Patient.new(:_id => Mongo::ObjectID.new.to_s)
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:address) do
|
10
|
-
Address.new(:_id => Mongo::ObjectID.new.to_s, :street => "Oxford St")
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:collection) do
|
14
|
-
stub.quacks_like(Mongoid::Collection.allocate)
|
15
|
-
end
|
16
|
-
|
17
|
-
before do
|
18
|
-
document.stubs(:collection).returns(collection)
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#initialize" do
|
22
|
-
|
23
|
-
let(:update) do
|
24
|
-
Mongoid::Persistence::Update.new(document)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "sets the document" do
|
28
|
-
update.document.should == document
|
29
|
-
end
|
30
|
-
|
31
|
-
it "sets the collection" do
|
32
|
-
update.collection.should == document.collection
|
33
|
-
end
|
34
|
-
|
35
|
-
it "defaults validation to true" do
|
36
|
-
update.validate.should == true
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets the options" do
|
40
|
-
update.options.should ==
|
41
|
-
{ :multi => false, :safe => Mongoid.persist_in_safe_mode }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#persist" do
|
46
|
-
|
47
|
-
def root_set_expectation
|
48
|
-
lambda {
|
49
|
-
collection.expects(:update).with(
|
50
|
-
{ "_id" => document.id },
|
51
|
-
{ "$set" => document.setters },
|
52
|
-
:multi => false,
|
53
|
-
:safe => true
|
54
|
-
).returns("Object")
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
def embedded_set_expectation
|
59
|
-
lambda {
|
60
|
-
collection.expects(:update).with(
|
61
|
-
{ "_id" => document.id, "addresses._id" => address.id },
|
62
|
-
{ "$set" => address.setters },
|
63
|
-
:multi => false,
|
64
|
-
:safe => true
|
65
|
-
).returns("Object")
|
66
|
-
}
|
67
|
-
end
|
68
|
-
|
69
|
-
let(:update) do
|
70
|
-
Mongoid::Persistence::Update.new(document)
|
71
|
-
end
|
72
|
-
|
73
|
-
context "when the document is changed" do
|
74
|
-
|
75
|
-
before do
|
76
|
-
document.title = "Sir"
|
77
|
-
end
|
78
|
-
|
79
|
-
context "when the document is valid" do
|
80
|
-
|
81
|
-
it "performs a $set for changed fields" do
|
82
|
-
root_set_expectation.call
|
83
|
-
update.persist.should == true
|
84
|
-
end
|
85
|
-
|
86
|
-
it "moves the changed fields to previously changed" do
|
87
|
-
root_set_expectation.call
|
88
|
-
update.persist
|
89
|
-
document.changed?.should == false
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
context "when the document is not valid" do
|
95
|
-
|
96
|
-
before do
|
97
|
-
document.stubs(:valid?).returns(false)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "returns false" do
|
101
|
-
update.persist.should == false
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "when not validating" do
|
106
|
-
|
107
|
-
before do
|
108
|
-
update.instance_variable_set(:@validate, false)
|
109
|
-
document.stubs(:valid?).returns(false)
|
110
|
-
end
|
111
|
-
|
112
|
-
after do
|
113
|
-
update.instance_variable_set(:@validate, true)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "updates the document in the database" do
|
117
|
-
root_set_expectation.call
|
118
|
-
update.persist.should == true
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "when the document is embedded" do
|
123
|
-
|
124
|
-
let(:embedded) do
|
125
|
-
Mongoid::Persistence::Update.new(address)
|
126
|
-
end
|
127
|
-
|
128
|
-
before do
|
129
|
-
# TODO: What to do about composite keys?
|
130
|
-
document.addresses << address
|
131
|
-
address.city = "London"
|
132
|
-
end
|
133
|
-
|
134
|
-
it "performs a $set for the embedded changed fields" do
|
135
|
-
embedded_set_expectation.call
|
136
|
-
embedded.persist
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "when the document is not changed" do
|
142
|
-
|
143
|
-
it "returns true" do
|
144
|
-
update.persist.should == true
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::Persistence do
|
4
|
-
|
5
|
-
let(:person) do
|
6
|
-
Person.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "#insert" do
|
10
|
-
|
11
|
-
let(:insert) do
|
12
|
-
stub.quacks_like(Mongoid::Persistence::Insert.allocate)
|
13
|
-
end
|
14
|
-
|
15
|
-
before do
|
16
|
-
Mongoid::Persistence::Insert.expects(:new).with(person).returns(insert)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "delegates to the insert persistence command" do
|
20
|
-
insert.expects(:persist).returns(person)
|
21
|
-
person.insert.should == person
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#update" do
|
26
|
-
|
27
|
-
let(:update) do
|
28
|
-
stub.quacks_like(Mongoid::Persistence::Update.allocate)
|
29
|
-
end
|
30
|
-
|
31
|
-
before do
|
32
|
-
Mongoid::Persistence::Update.expects(:new).with(person).returns(update)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "delegates to the update persistence command" do
|
36
|
-
update.expects(:persist).returns(true)
|
37
|
-
person.update.should == true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::State do
|
4
|
-
|
5
|
-
describe "#new_record?" do
|
6
|
-
|
7
|
-
context "when the object has been saved" do
|
8
|
-
|
9
|
-
before do
|
10
|
-
@person = Person.new(:_id => "1")
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns false" do
|
14
|
-
@person.new_record?.should be_false
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when the object has not been saved" do
|
20
|
-
|
21
|
-
before do
|
22
|
-
@person = Person.new
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns true" do
|
26
|
-
@person.new_record?.should be_true
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#persisted?" do
|
34
|
-
|
35
|
-
before do
|
36
|
-
@person = Person.new
|
37
|
-
end
|
38
|
-
|
39
|
-
it "delegates to new_record?" do
|
40
|
-
@person.persisted?.should be_false
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "destroyed?" do
|
45
|
-
|
46
|
-
before do
|
47
|
-
@person = Person.new
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when destroyed is true" do
|
51
|
-
|
52
|
-
before do
|
53
|
-
@person.destroyed = true
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns true" do
|
57
|
-
@person.destroyed?.should be_true
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when destroyed is false" do
|
62
|
-
|
63
|
-
before do
|
64
|
-
@person.destroyed = false
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns true" do
|
68
|
-
@person.destroyed?.should be_false
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when destroyed is nil" do
|
73
|
-
|
74
|
-
before do
|
75
|
-
@person.destroyed = nil
|
76
|
-
end
|
77
|
-
|
78
|
-
it "returns false" do
|
79
|
-
@person.destroyed?.should be_false
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|