public
Created

BSON id parsing

  • Download Gist
bson_id_parsing_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
require 'spec_helper'
 
def parse_id(id)
BSON::ObjectId(id)
rescue BSON::InvalidObjectId
nil
end
 
describe BSON do
describe 'when the id is a valid BSON id' do
it 'returns it' do
parse_id("SOME VALID BSON ID").must_be_kind_of BSON::ObjectId
end
end
 
describe 'otherwise' do
it 'returns nil' do
parse_id("aiejfioaej").must_be_nil
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.