Added #hash method for ObjectID.
This commit is contained in:
parent
48b5e069e0
commit
db1f382150
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue