mongoid/mongoid — pull request #3682 by johnny-miyake (2014-06-04 18:34:12+00:00)
Title: Added an error for persisting with non-existing subclass type.

I got an error when creating a new document with non-existing subclass type.
Here is an example. `Boy` and `Girl` are subclass of `Kid`, and `Dog` is not existing class.
```ruby
$ rails c
Loading development environment (Rails 4.0.0)
2.0.0-p451 :001 > Boy
=> Boy
2.0.0-p451 :002 > Kid.create _type: "Boy"
=> #
2.0.0-p451 :003 > Girl
=> Girl
2.0.0-p451 :004 > Kid.create _type: "Girl"
=> #
2.0.0-p451 :005 > Kid.last
=> #
2.0.0-p451 :006 > Kid.create _type: "Dog"
=> #
2.0.0-p451 :007 > Kid.last
NameError: uninitialized constant Dog
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in `const_get'
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in `block in constantize'
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `inject'
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `constantize'
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/factory.rb:44:in `from_db'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/relations/eager.rb:16:in `with_eager_loading'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/contextual/mongo.rb:282:in `block (2 levels) in last'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/contextual/mongo.rb:556:in `with_inverse_sorting'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/contextual/mongo.rb:281:in `block in last'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/contextual/mongo.rb:447:in `try_cache'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/contextual/mongo.rb:280:in `last'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/contextual.rb:20:in `last'
from /usr/local/rvm/gems/ruby-2.0.0-p451/bundler/gems/mongoid-fdd963e15bfd/lib/mongoid/findable.rb:133:in `last'
from (irb):7
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.0/lib/rails/commands.rb:64:in `'
from bin/rails:4:in `require'
from bin/rails:4:in `

'2.0.0-p451 :008 >
```
It is not so easy to find out the cause of the problem when that error message was shown. Moreover, the case below can be occurred.
```ruby
[1] pry(main)> Kid.destroy_all
NameError: uninitialized constant Dog
from /usr/local/rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in `const_get'
[2] pry(main)>
```

In this pull-req, I added an error that is raised when creating a new document with non-existing subclass type.
Although many other ways to handle that problem might be there, anyway, defining the behavior for this case should be needed.

Thank you.