mongoid 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid.rb +2 -1
- data/lib/mongoid/document.rb +8 -1
- data/mongoid.gemspec +1 -1
- data/spec/integration/mongoid/document_spec.rb +2 -2
- data/spec/unit/mongoid/document_spec.rb +42 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/mongoid.rb
CHANGED
@@ -46,7 +46,8 @@ module Mongoid
|
|
46
46
|
class NoConnectionError < RuntimeError; end
|
47
47
|
|
48
48
|
# Raised when an association is defined on the class, but the
|
49
|
-
# attribute in the hash is not an Array or Hash
|
49
|
+
# attribute in the hash is not an Array or Hash, or when
|
50
|
+
# checking equality on objects of different types.
|
50
51
|
class TypeMismatchError < RuntimeError; end
|
51
52
|
|
52
53
|
# Raised when an association is defined that is not valid. Must
|
data/lib/mongoid/document.rb
CHANGED
@@ -153,6 +153,13 @@ module Mongoid #:nodoc:
|
|
153
153
|
|
154
154
|
end
|
155
155
|
|
156
|
+
# Performs equality checking on the attributes.
|
157
|
+
def ==(other)
|
158
|
+
raise TypeMismatchError unless other.is_a?(Document)
|
159
|
+
@attributes.except(:modified_at).except(:created_at) ==
|
160
|
+
other.attributes.except(:modified_at).except(:created_at)
|
161
|
+
end
|
162
|
+
|
156
163
|
# Get the Mongo::Collection associated with this Document.
|
157
164
|
def collection
|
158
165
|
self.class.collection
|
@@ -215,7 +222,7 @@ module Mongoid #:nodoc:
|
|
215
222
|
notify
|
216
223
|
end
|
217
224
|
|
218
|
-
# Writes all the attributes of this Document, and delegate up to
|
225
|
+
# Writes all the attributes of this Document, and delegate up to
|
219
226
|
# the parent.
|
220
227
|
def write_attributes(attrs)
|
221
228
|
@attributes = attrs
|
data/mongoid.gemspec
CHANGED
@@ -130,7 +130,7 @@ describe Mongoid::Document do
|
|
130
130
|
|
131
131
|
it "saves the entire graph up from the has_one" do
|
132
132
|
person = Person.first(:conditions => { :title => "Sir" })
|
133
|
-
person.
|
133
|
+
person.should == @person
|
134
134
|
end
|
135
135
|
|
136
136
|
end
|
@@ -143,7 +143,7 @@ describe Mongoid::Document do
|
|
143
143
|
|
144
144
|
it "saves the entire graph up from the has_many" do
|
145
145
|
person = Person.first(:conditions => { :title => "Sir" })
|
146
|
-
person.
|
146
|
+
person.should == @person
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -14,6 +14,48 @@ describe Mongoid::Document do
|
|
14
14
|
@collection = nil
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "#==" do
|
18
|
+
|
19
|
+
context "when other object is a Document" do
|
20
|
+
|
21
|
+
context "when attributes are equal" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
@document = Person.new(:title => "Sir")
|
25
|
+
@other = Person.new(:title => "Sir")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns true" do
|
29
|
+
@document.should == @other
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when attributes are not equal" do
|
35
|
+
|
36
|
+
before do
|
37
|
+
@document = Person.new(:title => "Sir")
|
38
|
+
@other = Person.new(:title => "Madam")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns false" do
|
42
|
+
@document.should_not == @other
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when other object is not a Document" do
|
50
|
+
|
51
|
+
it "raises an exception" do
|
52
|
+
lambda { Person.new.==("Test") }.should raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
17
59
|
describe "#all" do
|
18
60
|
|
19
61
|
before do
|