I have been having a problem when I try to compare two Rails models. They should evaluate as the same, but the way ActiveRecord implements == is causing it to fail. What's even stranger is the unit tests are passing.
Suppose a User has many Posts, and Posts has many Comments. User also has_many comments.
(and this is comparing two objects, which should be the same)
User.first.comments.first == Post.forst.comments.first
When I write out the object_ids to Rails.logger, they are not equal. After digging through the source code, I've found this condition makes it fail.
I expect:
User.first.comments.class.object_id == Post.first.comments.class.object_id
But this is not the case.
The model includes a module, which does the following inside self.included(base)
base.send :include, InstanceMethods
base.send :extend, ClassMethods
When I take the include out of the models, everything works fine.
Is there something with the include/extend pattern that is causing the models to reload or not be cached correctly within the same request?
Any ideas here would be great!!!