test/unit/test_keys.rb in mongo_mapper-0.7.0 vs test/unit/test_keys.rb in mongo_mapper-0.7.1

- old
+ new

@@ -40,29 +40,29 @@ end should "symbolize option keys" do Key.new(:foo, Integer, 'required' => true).options[:required].should be(true) end - + should "work with just name" do key = Key.new(:foo) key.name.should == 'foo' end - + should "work with name and type" do key = Key.new(:foo, String) key.name.should == 'foo' key.type.should == String end - + should "work with name, type, and options" do key = Key.new(:foo, String, :required => true) key.name.should == 'foo' key.type.should == String key.options[:required].should be_true end - + should "work with name and options" do key = Key.new(:foo, :required => true) key.name.should == 'foo' key.options[:required].should be_true end @@ -78,24 +78,24 @@ end should "not be equal to another key with different type" do Key.new(:name, String).should_not == Key.new(:name, Integer) end - + should "know if it is a embedded_document" do Key.new(:name, EDoc()).embeddable?.should be_true end should "know if it is not a embedded_document" do Key.new(:name, String).embeddable?.should be_false end - + should "know if it is a number" do Key.new(:age, Integer).number?.should be_true Key.new(:age, Float).number?.should be_true end - + should "know if it is not a number" do Key.new(:age, String).number?.should be_false end end @@ -108,11 +108,11 @@ should "correctly typecast if object of that type is given" do key = Key.new(:foo, FooType) key.set(FooType.new('something')).should == 'to_mongo' end end - + context "getting a value with a custom type" do should "use #from_mongo to convert back to custom type" do key = Key.new(:foo, FooType) key.get('something').should == 'from_mongo' end @@ -121,11 +121,11 @@ context "getting a value" do should "work with a type" do key = Key.new(:foo, String) key.get('bar').should == 'bar' end - + should "work without type" do key = Key.new(:foo) key.get([1, '2']).should == [1, '2'] key.get(false).should == false key.get({}).should == {} @@ -142,11 +142,11 @@ key = Key.new(:foo, Address) key.get(address).should == address end end end - + context "getting a value with a default set" do setup do @key = Key.new(:foo, String, :default => 'baz') end @@ -155,15 +155,19 @@ end should "return value if not blank" do @key.get('foobar').should == 'foobar' end - + should "work with Boolean type and false value" do Key.new(:active, Boolean, :default => false).get(nil).should be_false end should "work with Boolean type and true value" do Key.new(:active, Boolean, :default => true).get(nil).should be_true + end + + should "work with procs" do + Key.new(:foo, String, :default => lambda { return 'hello world' }).get(nil).should == "hello world" end end end # KeyTest