mongoid/mongoid — pull request #3063 by a-ross-cohen (2013-05-21 04:17:01+00:00)
Title: Document#becomes doesn't properly set the reference to @base in the errors object.

I ran into this problem when using Document#becomes to create a subclass and then validate it. Super simplified reproduction below. Just a rails 3.2.13 app with two models, one inheriting from the other.

``` ruby
class Klass
include Mongoid::Document
end

class SubKlass < Klass
field :attr, type: String
validates :attr, presence: true
end
```

``` irb
Loading development environment (Rails 3.2.13)
1.9.3p392 :001 > k = Klass.new
=> #
1.9.3p392 :002 > k.errors.inspect
=> "#, @messages={}>"
1.9.3p392 :003 > sk = k.becomes SubKlass
=> #
1.9.3p392 :004 > sk.errors.inspect
=> "#, @messages={}>"
1.9.3p392 :005 > sk.valid?
NoMethodError: undefined method `attr' for #
1.9.3p392 :007 > sk.instance_variable_set(:@errors, ActiveModel::Errors.new(sk))
=> #, @messages={}>
1.9.3p392 :008 > sk.valid?
=> false
```

I added one spec to test against the issue, and made the appropriate changes to Document#becomes.