On Wed, Aug 27, 2008 at 3:34 AM, Matt Wynne <[EMAIL PROTECTED]> wrote:
>> Here's the basic deal:
>>
>> Model.find(1).equal?(Model.find(1))
>> => false
>>
>> AR does not cache objects, so when you ask it for what you *think*
>> might the same object twice, you get different ones.
>
> I thought as much... So does AR just cache the object's attributes instead
> and construct them on the fly as and when you ask for them?


It caches the SQL statements and their results. It uses the cached
results to build an instance of your model. Although the identify of
the objects are different, they are equal.

    f = Foo.create :name => "blah"
    f.equal?(Foo.last) # false
    f == Foo.last       # true

I don't know your ultimate goal, but you could rely on object equality
(and not identify equality) in your test:

   @target_comment.should == @target_comments.first

And then rely on @target_comments.first to set up your expectation for
:merge_in.

-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to