djsun-mongo_mapper 0.5.5.2 → 0.5.5.3

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.5.2
1
+ 0.5.5.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{djsun-mongo_mapper}
8
- s.version = "0.5.5.2"
8
+ s.version = "0.5.5.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker"]
12
- s.date = %q{2009-10-16}
12
+ s.date = %q{2009-10-19}
13
13
  s.default_executable = %q{mmconsole}
14
14
  s.email = %q{nunemaker@gmail.com}
15
15
  s.executables = ["mmconsole"]
@@ -270,7 +270,12 @@ module MongoMapper
270
270
  end
271
271
 
272
272
  def ==(other)
273
- other.is_a?(self.class) && id == other.id
273
+ ignore = { '_id' => nil }
274
+ attributes.merge(ignore) == other.attributes.merge(ignore)
275
+ end
276
+
277
+ def eql?(other)
278
+ other.is_a?(self.class) && (self == other)
274
279
  end
275
280
 
276
281
  def id
@@ -4,12 +4,6 @@ require 'models'
4
4
  class NamespaceTest < Test::Unit::TestCase
5
5
  include Hollywood
6
6
 
7
- def setup
8
- Movie.collection.clear
9
- Actor.collection.clear
10
- Role.collection.clear
11
- end
12
-
13
7
  context "Hollywood namespace" do
14
8
  setup do
15
9
  @movie = Movie.create
@@ -160,24 +160,62 @@ class DocumentTest < Test::Unit::TestCase
160
160
  clone.age.should == 27
161
161
  end
162
162
  end
163
-
164
163
 
165
- context "equality" do
166
- should "be equal if id and class are the same" do
167
- (@document.new('_id' => 1) == @document.new('_id' => 1)).should be(true)
164
+ context "==" do
165
+ should "be == if key values are the same" do
166
+ doc_1 = @document.new('name' => "Doc 1")
167
+ doc_2 = @document.new('name' => "Doc 1")
168
+ doc_1.should == doc_2
169
+ doc_2.should == doc_1 # check transitivity
168
170
  end
169
171
 
170
- should "not be equal if class same but id different" do
171
- (@document.new('_id' => 1) == @document.new('_id' => 2)).should be(false)
172
+ should "not be == if key values are different" do
173
+ doc_1 = @document.new('name' => "Doc 1")
174
+ doc_2 = @document.new('name' => "Doc 2")
175
+ doc_1.should_not == doc_2
176
+ doc_2.should_not == doc_1 # check transitivity
172
177
  end
173
178
 
174
- should "not be equal if id same but class different" do
175
- @another_document = Class.new do
176
- include MongoMapper::Document
177
- set_collection_name 'test'
179
+ should "not care about type" do
180
+ @person = Class.new do
181
+ include MongoMapper::EmbeddedDocument
182
+
183
+ key :name, String
184
+ key :age, Integer
178
185
  end
186
+ doc = @document.new('name' => "Doc 1")
187
+ person = @person.new('name' => "Doc 1")
188
+ doc.should == person
189
+ person.should == doc # check transitivity
190
+ end
191
+ end
192
+
193
+ context "eql?" do
194
+ should "be eql? if type matches and key values are the same" do
195
+ doc_1 = @document.new('name' => "Doc 1")
196
+ doc_2 = @document.new('name' => "Doc 1")
197
+ doc_1.should eql?(doc_2)
198
+ doc_2.should eql?(doc_1) # check transitivity
199
+ end
200
+
201
+ should "not be == if type matches but key values are different" do
202
+ doc_1 = @document.new('name' => "Doc 1")
203
+ doc_2 = @document.new('name' => "Doc 2")
204
+ doc_1.should_not eql?(doc_2)
205
+ doc_2.should_not eql?(doc_1) # check transitivity
206
+ end
179
207
 
180
- (@document.new('_id' => 1) == @another_document.new('_id' => 1)).should be(false)
208
+ should "not be eql? if types are different even if values are the same" do
209
+ @person = Class.new do
210
+ include MongoMapper::EmbeddedDocument
211
+
212
+ key :name, String
213
+ key :age, Integer
214
+ end
215
+ doc = @document.new('name' => "Doc 1")
216
+ person = @person.new('name' => "Doc 1")
217
+ doc.should_not eql?(person)
218
+ person.should_not eql?(doc) # check transitivity
181
219
  end
182
220
  end
183
221
  end # instance of a document
@@ -644,22 +644,63 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
644
644
  end
645
645
  end
646
646
 
647
- context "equality" do
648
- should "be equal if id and class are the same" do
649
- (@document.new('_id' => 1) == @document.new('_id' => 1)).should be(true)
647
+ context "==" do
648
+ should "be == if key values are the same" do
649
+ doc_1 = @document.new('name' => "Doc 1")
650
+ doc_2 = @document.new('name' => "Doc 1")
651
+ doc_1.should == doc_2
652
+ doc_2.should == doc_1 # check transitivity
650
653
  end
651
654
 
652
- should "not be equal if class same but id different" do
653
- (@document.new('_id' => 1) == @document.new('_id' => 2)).should be(false)
655
+ should "not be == if key values are different" do
656
+ doc_1 = @document.new('name' => "Doc 1")
657
+ doc_2 = @document.new('name' => "Doc 2")
658
+ doc_1.should_not == doc_2
659
+ doc_2.should_not == doc_1 # check transitivity
654
660
  end
655
661
 
656
- should "not be equal if id same but class different" do
657
- @another_document = Class.new do
658
- include MongoMapper::Document
662
+ should "not care about type" do
663
+ @person = Class.new do
664
+ include MongoMapper::EmbeddedDocument
665
+
666
+ key :name, String
667
+ key :age, Integer
659
668
  end
669
+ doc = @document.new('name' => "Doc 1")
670
+ person = @person.new('name' => "Doc 1")
671
+ doc.should == person
672
+ person.should == doc # check transitivity
673
+ end
674
+ end
675
+
676
+ context "eql?" do
677
+ should "be eql? if type matches and key values are the same" do
678
+ doc_1 = @document.new('name' => "Doc 1")
679
+ doc_2 = @document.new('name' => "Doc 1")
680
+ doc_1.should eql?(doc_2)
681
+ doc_2.should eql?(doc_1) # check transitivity
682
+ end
660
683
 
661
- (@document.new('_id' => 1) == @another_document.new('_id' => 1)).should be(false)
684
+ should "not be == if type matches but key values are different" do
685
+ doc_1 = @document.new('name' => "Doc 1")
686
+ doc_2 = @document.new('name' => "Doc 2")
687
+ doc_1.should_not eql?(doc_2)
688
+ doc_2.should_not eql?(doc_1) # check transitivity
689
+ end
690
+
691
+ should "not be eql? if types are different even if values are the same" do
692
+ @person = Class.new do
693
+ include MongoMapper::EmbeddedDocument
694
+
695
+ key :name, String
696
+ key :age, Integer
697
+ end
698
+ doc = @document.new('name' => "Doc 1")
699
+ person = @person.new('name' => "Doc 1")
700
+ doc.should_not eql?(person)
701
+ person.should_not eql?(doc) # check transitivity
662
702
  end
663
703
  end
704
+
664
705
  end # instance of a embedded document
665
706
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djsun-mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5.2
4
+ version: 0.5.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-16 00:00:00 -04:00
12
+ date: 2009-10-19 00:00:00 -04:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency