Added #hash method for ObjectID.

This commit is contained in:
Kyle Banker 2009-11-11 10:47:42 -05:00
parent 48b5e069e0
commit db1f382150
3 changed files with 21 additions and 1 deletions

View File

@ -356,6 +356,9 @@ Les Hill, leshill on github
Sean Cribbs, seancribbs on github
* Modify standard_benchmark to allow profiling
Sunny Hirai
* Suggested hashcode fix for Mongo::ObjectID
= License
Copyright 2008-2009 10gen Inc.

View File

@ -57,6 +57,12 @@ module Mongo
end
alias_method :==, :eql?
# Returns a unique hashcode for the object.
# This is required since we've defined an #eql? method.
def hash
@data.hash
end
def to_a
@data.dup
end

View File

@ -7,7 +7,18 @@ class ObjectIDTest < Test::Unit::TestCase
include Mongo
def setup
@o = ObjectID.new()
@o = ObjectID.new
end
def test_hashcode
assert_equal @o.instance_variable_get(:@data).hash, @o.hash
end
def test_array_uniq_for_equilavent_ids
a = ObjectID.new('123')
b = ObjectID.new('123')
assert_equal a, b
assert_equal 1, [a, b].uniq.size
end
def test_create_pk_method