previous_error and reset_error_history. snuck in a quick fix to OrderedHash equality
This commit is contained in:
parent
dc44751d2f
commit
cabca61e0d
|
@ -264,6 +264,27 @@ module XGen
|
||||||
error != nil
|
error != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get the most recent error to have occured on this database
|
||||||
|
#
|
||||||
|
# Only returns errors that have occured since the last call to
|
||||||
|
# DB#reset_error_history - returns +nil+ if there is no such error.
|
||||||
|
def previous_error
|
||||||
|
error = db_command(:getpreverror => 1)
|
||||||
|
if error["err"]
|
||||||
|
error
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Reset the error history of this database
|
||||||
|
#
|
||||||
|
# Calls to DB#previous_error will only return errors that have occurred
|
||||||
|
# since the most recent call to this method.
|
||||||
|
def reset_error_history
|
||||||
|
db_command(:reseterror => 1)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns true if this database is a master (or is not paired with any
|
# Returns true if this database is a master (or is not paired with any
|
||||||
# other database), false if it is a slave.
|
# other database), false if it is a slave.
|
||||||
def master?
|
def master?
|
||||||
|
|
|
@ -21,9 +21,13 @@
|
||||||
class OrderedHash < Hash
|
class OrderedHash < Hash
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
begin
|
||||||
!other.nil? &&
|
!other.nil? &&
|
||||||
keys == other.keys &&
|
keys == other.keys &&
|
||||||
values == other.values
|
values == other.values
|
||||||
|
rescue
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# We only need the body of this class if the RUBY_VERSION is before 1.9
|
# We only need the body of this class if the RUBY_VERSION is before 1.9
|
||||||
|
|
|
@ -122,15 +122,33 @@ class DBTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_error
|
def test_error
|
||||||
doc = @@db.send(:db_command, :forceerror => 1)
|
@@db.reset_error_history
|
||||||
assert @@db.error?
|
assert_nil @@db.error
|
||||||
err = @@db.error
|
assert !@@db.error?
|
||||||
assert_match /forced error/, err
|
assert_nil @@db.previous_error
|
||||||
|
|
||||||
# ask again
|
@@db.send(:db_command, :forceerror => 1)
|
||||||
assert @@db.error?
|
assert @@db.error?
|
||||||
err2 = @@db.error
|
assert_not_nil @@db.error
|
||||||
assert_equal err, err2
|
assert_not_nil @@db.previous_error
|
||||||
|
|
||||||
|
@@db.send(:db_command, :forceerror => 1)
|
||||||
|
assert @@db.error?
|
||||||
|
assert @@db.error
|
||||||
|
prev_error = @@db.previous_error
|
||||||
|
assert_equal 1, prev_error['nPrev']
|
||||||
|
assert_equal prev_error["err"], @@db.error
|
||||||
|
|
||||||
|
@@db.collection('test').find_first
|
||||||
|
assert_nil @@db.error
|
||||||
|
assert !@@db.error?
|
||||||
|
assert @@db.previous_error
|
||||||
|
assert_equal 2, @@db.previous_error['nPrev']
|
||||||
|
|
||||||
|
@@db.reset_error_history
|
||||||
|
assert_nil @@db.error
|
||||||
|
assert !@@db.error?
|
||||||
|
assert_nil @@db.previous_error
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_port_number
|
def test_text_port_number
|
||||||
|
|
Loading…
Reference in New Issue