mongoid/mongoid — Issue #1389: validates_presence_of allow empty string for embeds documents
Author: gorkunov
Created: 2011-10-31 10:13:41+00:00
State: open

**Affected versions:** 2.1.9, 2.2.4
**ruby:** ruby-1.9.2-p290

```ruby
class Foo
include Mongoid::Document
field :somefield
embedded_in :bar
end
class Bar
include Mongoid::Document

field :str
validates_presence_of :str

embeds_one :foo
validates_presence_of :foo
end

>> Bar.create.errors
=> {:str=>["can't be blank"], :foo=>["can't be blank"]}

>> Bar.create({:str => ""}).errors
=> {:str=>["can't be blank"], :foo=>["can't be blank"]}

>> Bar.create({:str => "", :foo => "" }).errors
NoMethodError: undefined method `metadata' for "":String
from /Users/gorkunov/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.9/lib/mongoid/relations/proxy.rb:115:in `characterize_one'

```