mongoid 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid/document.rb +12 -6
- data/mongoid.gemspec +1 -1
- data/spec/unit/mongoid/document_spec.rb +67 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.6
|
data/lib/mongoid/document.rb
CHANGED
@@ -7,12 +7,7 @@ module Mongoid #:nodoc:
|
|
7
7
|
include InstanceMethods
|
8
8
|
extend ClassMethods
|
9
9
|
|
10
|
-
cattr_accessor
|
11
|
-
:_collection,
|
12
|
-
:collection_name,
|
13
|
-
:embedded,
|
14
|
-
:primary_key,
|
15
|
-
:hereditary
|
10
|
+
cattr_accessor :_collection, :collection_name, :embedded, :primary_key, :hereditary
|
16
11
|
|
17
12
|
self.embedded = false
|
18
13
|
self.hereditary = false
|
@@ -118,6 +113,17 @@ module Mongoid #:nodoc:
|
|
118
113
|
other.attributes.except(:modified_at).except(:created_at)
|
119
114
|
end
|
120
115
|
|
116
|
+
# Delegates to ==
|
117
|
+
def eql?(comparison_object)
|
118
|
+
self == (comparison_object)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Delegates to id in order to allow two records of the same type and id to work with something like:
|
122
|
+
# [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]
|
123
|
+
def hash
|
124
|
+
id.hash
|
125
|
+
end
|
126
|
+
|
121
127
|
# Introduces a child object into the +Document+ object graph. This will
|
122
128
|
# set up the relationships between the parent and child and update the
|
123
129
|
# attributes of the parent +Document+.
|
data/mongoid.gemspec
CHANGED
@@ -67,6 +67,73 @@ 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
|
+
|
70
137
|
describe "#alias_method_chain" do
|
71
138
|
|
72
139
|
context "on a field setter" do
|