drapergem/draper — pull request #417 by haines (2013-01-12 18:42:47+00:00)
Title: Pretend to be instance_of?(source.class)

We pretend to be a `kind_of?` the source class, so I think it also makes sense to pretend to be an `instance_of?` the same.

I only had to tweak the `handle_multiple_decoration` stuff, otherwise no changes were necessary (although the specs will fail on Travis until #416 goes in).

As a nice bonus, this would make [this spec](https://github.com/haines/draper/blob/d528fffe78df140dc7c94681afbb4bffedd8ce80/spec/dummy/spec/models/post_spec.rb#L8) pass on Rails 3.0 - it doesn't at the moment because in 3.0 `ActiveRecord::Base#==` doesn't call `super`, so it doesn't hit `Decoratable#==`:

```ruby
# activerecord/lib/active_record/base.rb#L1629
def ==(comparison_object)
comparison_object.equal?(self) ||
(comparison_object.instance_of?(self.class) &&
comparison_object.id == id && !comparison_object.new_record?)
end
```

Compared to, on 3.2 (and similarly on 3.1),

```ruby
# activerecord/lib/active_record/base.rb#L593
def ==(comparison_object)
super ||
comparison_object.instance_of?(self.class) &&
id.present? &&
comparison_object.id == id
end
```