Created
September 6, 2011 07:18
-
-
Save txus/1196825 to your computer and use it in GitHub Desktop.
BSON id parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment