forked from mongoid/moped
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- For compatibility with apps that may use the 10gen driver API with regards to creating object ids from strings. - No inspection override here. - Closes mongoid#4.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,52 @@ | |||
require "spec_helper" | |||
|
|||
describe Moped::BSON do | |||
|
|||
describe ".ObjectId" do | |||
|
|||
context "when provided a string" do | |||
|
|||
context "when the string is a valid id" do | |||
|
|||
let(:id) do | |||
described_class.ObjectId("4faf83c7dbf89b7b29000001") | |||
end | |||
|
|||
let(:expected) do | |||
Moped::BSON::ObjectId.from_string("4faf83c7dbf89b7b29000001") | |||
end | |||
|
|||
it "returns an object id" do | |||
id.should eq(expected) | |||
end | |||
end | |||
|
|||
context "when the string is not a valid id" do | |||
|
|||
it "raises an error" do | |||
expect { | |||
described_class.ObjectId("test") | |||
}.to raise_error(Moped::Errors::InvalidObjectId) | |||
end | |||
end | |||
end | |||
|
|||
context "when provided a non string" do | |||
|
|||
it "raises an error" do | |||
expect { | |||
described_class.ObjectId(1) | |||
}.to raise_error | |||
end | |||
end | |||
|
|||
context "when provided nil" do | |||
|
|||
it "raises an error" do | |||
expect { | |||
described_class.ObjectId(nil) | |||
}.to raise_error | |||
end | |||
end | |||
end | |||
end |