test/unit/test_keys.rb in mongo_mapper-0.8.2 vs test/unit/test_keys.rb in mongo_mapper-0.8.3
- old
+ new
@@ -2,9 +2,43 @@
require 'models'
class KeyTest < Test::Unit::TestCase
include MongoMapper::Plugins::Keys
+ context ".new with no id and _id of type integer" do
+ should "not error" do
+ lambda {
+ klass = Doc() do
+ key :_id, Integer
+ end
+ # No sensible default id for integer, people better pass them in if they user this
+ klass.new.id.should be_nil
+ }.should_not raise_error
+ end
+ end
+
+ context ".new with no id and _id of type string" do
+ should "not error" do
+ lambda {
+ klass = Doc() do
+ key :_id, String
+ end
+ klass.new.id.should_not be_nil
+ }.should_not raise_error
+ end
+ end
+
+ context ".new with no id and _id of type object id" do
+ should "not error" do
+ lambda {
+ klass = Doc() do
+ key :_id, ObjectId
+ end
+ klass.new.should_not be_nil
+ }.should_not raise_error
+ end
+ end
+
context ".key?(:symbol)" do
should "be true if document has key" do
Address.key?(:city).should be_true
end