Using OpenStruct as mock for ActiveRecord
As you may have noticed OpenStruct#id
always returns the object id of the OpenStruct instance, even when you set id.
Fortunately there is a simple way around this.
Now OpenStruct behaves like we want.
Note that hash
and object_id
still work fine. You probably want to keep in mind that we’ve redefined the default OpenStruct behaviour and it might cause problems elsewhere.