jgaskins/perpetuity-mongodb — pull request #7 by XescuGC (2014-10-30 16:26:52+00:00)
Title: Added a .to_s when adding the __metadat__ of an embedded element class

I've found this issue when using embedded in a mapper. I've tried the example you posted in your Youtube video (Mailbox and Messages) and works perfectly, but for me didn't work. You will find below the LOGs of the error, but the change i've made solves the issue.

I've tryied in Moped2 and Moped1:
Logs for Moped1:
```
NoMethodError:
undefined method `__bson_dump__' for WifiPrice:Class
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:15:in `block in __bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `__bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:15:in `block in __bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `__bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:15:in `block in __bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `__bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:15:in `block in __bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/extensions/hash.rb:14:in `__bson_dump__'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/bson/document.rb:36:in `serialize'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/protocol/message.rb:136:in `serialize_update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/protocol/message.rb:289:in `serialize'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/connection.rb:153:in `block in write'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/connection.rb:151:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/connection.rb:151:in `write'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/node.rb:585:in `block (2 levels) in flush'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/node.rb:150:in `ensure_connected'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/node.rb:584:in `block in flush'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/node.rb:599:in `logging'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/node.rb:583:in `flush'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/node.rb:315:in `pipeline'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/session/context.rb:71:in `block in update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/session/context.rb:109:in `block in with_node'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/cluster.rb:209:in `block in with_primary'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/node.rb:197:in `ensure_primary'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/cluster.rb:208:in `with_primary'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/session/context.rb:108:in `with_node'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/session/context.rb:69:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/query.rb:373:in `block in update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/session.rb:324:in `with'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-1.5.2/lib/moped/query.rb:372:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/perpetuity-mongodb-1.0.0.beta2/lib/perpetuity/mongodb.rb:157:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/perpetuity-1.0.0/lib/perpetuity/mapper.rb:216:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/perpetuity-1.0.0/lib/perpetuity/mapper.rb:224:in `save'
```

Logs for Moped2:
```
undefined method `bson_type' for WifiPrice:Class
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:44:in `block (2 levels) in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `block in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/encodable.rb:57:in `encode_with_placeholder_and_null'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:42:in `to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:46:in `block (2 levels) in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `block in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/encodable.rb:57:in `encode_with_placeholder_and_null'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:42:in `to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:46:in `block (2 levels) in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `block in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/encodable.rb:57:in `encode_with_placeholder_and_null'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:42:in `to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:46:in `block (2 levels) in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:43:in `block in to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/encodable.rb:57:in `encode_with_placeholder_and_null'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/bson-2.3.0/lib/bson/hash.rb:42:in `to_bson'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/protocol/message.rb:171:in `serialize_update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/protocol/message.rb:323:in `serialize'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/connection.rb:170:in `block in write'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/connection.rb:168:in `each'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/connection.rb:168:in `write'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:590:in `block (2 levels) in flush'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:181:in `block in ensure_connected'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:115:in `block in connection'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/connection_pool-2.0.0/lib/connection_pool.rb:58:in `with'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:114:in `connection'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:177:in `ensure_connected'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:589:in `block in flush'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:617:in `block in logging'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/instrumentable/log.rb:26:in `instrument'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/instrumentable.rb:31:in `instrument'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:616:in `logging'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:587:in `flush'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:358:in `pipeline'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/operation/write.rb:47:in `execute'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:665:in `write'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:502:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/query.rb:427:in `block in update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/cluster.rb:249:in `block in with_primary'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:204:in `block in ensure_primary'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/executable.rb:25:in `execute'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/node.rb:203:in `ensure_primary'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/cluster.rb:248:in `with_primary'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/moped-2.0.1/lib/moped/query.rb:426:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/bundler/gems/perpetuity-mongodb-4fe2b4b08ed3/lib/perpetuity/mongodb.rb:163:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/perpetuity-1.0.0/lib/perpetuity/mapper.rb:216:in `update'
# /Users/francescgil/.rvm/gems/ruby-2.1-head@sbt-domine/gems/perpetuity-1.0.0/lib/perpetuity/mapper.rb:224:in `save'
# ./repositories/plan_repository.rb:58:in `save'
# ./interactors/middleware/plan/create_plan.rb:21:in `exec'
# ./spec/helpers/factories/plan.rb:15:in `new_created_request'
# ./spec/interactors/backoffice/plan/show_plan_spec.rb:14:in `block (4 levels) in '
# ./spec/interactors/backoffice/plan/show_plan_spec.rb:16:in `block (4 levels) in '
```

When Moped tries to add an element that is not of his types (because was not an String, was a name: WifiPrice) breaks down.