Added to_json for Mongo::ObjectID.
This commit is contained in:
parent
2087cd4286
commit
8ab4e77a81
|
@ -101,6 +101,10 @@ module Mongo
|
||||||
|
|
||||||
def inspect; to_s; end
|
def inspect; to_s; end
|
||||||
|
|
||||||
|
def to_json(*args)
|
||||||
|
%Q("#{to_s}")
|
||||||
|
end
|
||||||
|
|
||||||
# Get a string representation of this ObjectID using the legacy byte
|
# Get a string representation of this ObjectID using the legacy byte
|
||||||
# ordering. This method may eventually be removed. If you are not sure
|
# ordering. This method may eventually be removed. If you are not sure
|
||||||
# that you need this method you should be using the regular to_s.
|
# that you need this method you should be using the regular to_s.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'test/test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ObjectIDTest < Test::Unit::TestCase
|
class ObjectIDTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
@ -139,4 +139,9 @@ class ObjectIDTest < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_in_delta time.to_i, id.generation_time.to_i, 2
|
assert_in_delta time.to_i, id.generation_time.to_i, 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_json
|
||||||
|
id = ObjectID.new
|
||||||
|
assert_equal %Q("#{id}"), id.to_json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue