Permalink
Browse files

adding equality operator to Sdb::Base

  • Loading branch information...
ahoward committed Jul 8, 2009
1 parent 36bd204 commit 448d152d220647957c851d0cd768ca6ccd1471c4
Showing with 31 additions and 0 deletions.
  1. +6 −0 lib/helene/sdb/base.rb
  2. +25 −0 test/integration/sdb/equality.rb
View
@@ -851,6 +851,12 @@ def initialize(*args, &block)
end
end
+ # equality method
+ #
+ def == other
+ domain == other.domain and id == other.id
+ end
+
def klass
self.class
end
@@ -0,0 +1,25 @@
+testing Helene::Sdb::Base do
+ context 'equality' do
+ setup do
+ @a = model(:a)
+ end
+
+ should 'compare identical objects as equal' do
+ a = @a.create!
+ assert(a==a)
+ end
+
+ should 'not compare different objects as equal' do
+ a = @a.create!
+ b = @a.create!
+ assert(a!=b)
+ end
+
+ should 'not compare equally to only object from the same domain' do
+ 10.times{ @a.create! }
+ list = @a.all(:limit => 10)
+ first = list.first
+ assert(list.select{|element| element==first}.size==1)
+ end
+ end
+end

0 comments on commit 448d152

Please sign in to comment.