rails/rails — pull request #9264 by NiDi (2013-02-12 16:28:31+00:00)
Title: AR::Base#becomes should change errors base to new object

The current implementation of AR::Base#becomes throws an exception, whenever the new class validates something, the super class doesn't 'know' e.g. the presence of an associated object.

```ruby
class Company < ActiveRecord::Base
end

class Client < Company
belongs_to :account
validates_presence_of :account
end

company = Company.new
client = company.becomes(Client)
client.valid?

=> NoMethodError: undefined method `account' for #

```
This happens because since https://github.com/rails/rails/pull/3438 AR::Base#becomes copies the errors information, but doesn't change the base instance variable of the related ActiveModel::Errors object to the transformed object.

In my opinion, there are two alternatives:
1. Fix the bug: I attached a pull request with a failing test and bugfix
2. Revert https://github.com/rails/rails/pull/3438 . The whole behaviour could be misleading, because your errors object could contain messages of validations, which were overwritten by the new class.