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 CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -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
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
@@ -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.name.first_name.should == @person.name.first_name
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.addresses.first.street.should == @person.addresses.first.street
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
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: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan