Comparing using attribute hash if ids are nil

This commit is contained in:
Sam Lown 2011-06-25 02:30:47 +02:00
parent a8a1372e57
commit e91812ca53
3 changed files with 38 additions and 13 deletions

View file

@ -99,7 +99,12 @@ module CouchRest
# a Hash comparison on the attributes.
def == other
return false unless other.is_a?(Base)
database == other.database && id == other.id
if id.nil? && other.id.nil?
# no ids? assume comparing nested and revert to hash comparison
to_hash == other.to_hash
else
database == other.database && id == other.id
end
end
alias :eql? :==