solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Virtus::Attribute.coerce does not apply to EmbeddedValue #163

Closed ahawkins closed 11 years ago

ahawkins commented 11 years ago

Title says it all. I'm setting my EmbeddedValue associations to mocha Mock classes. My virtus classes look like this:

class Todo
  include Virtus
  attribute :user, User
end

Then some where in a test:

todo = Todo.new
todo.user = mock

This causes errors because coerce is still set and the Mock objects are being coerced via to_hash. Which is of course is an undefined method / unstubbed message blowing things up.

The documentation says you can set Virtus::Attribute.coerce false to disable this. This not entirely the case. The flag must also be set of on Virtus::Attribute::EmbeddedValue.

This makes my test suite work as expected:

Virtus::Attribute.coerce false
Virtus::Attribute::EmbeddedValue.coerce false
solnic commented 11 years ago

This seems to be working in current master