[rspec-users] Q: object.id is deprecated. How to mock?

Nick Hoffman nick at deadorange.com
Tue Nov 25 15:37:41 EST 2008


On 2008-11-25, at 14:04, s.ross wrote:
> In Rails, the primary key, by default 'id', is used all over the
> place. However, Ruby now deprecates the use of constructs like:
>
> @post = Post.find(:first)
> @post_id = @post.id
>
> ..snip..
>
> Thanks,
>
> Steve

Hi Steve. Ruby deprecated Object#id in favour of Object#object_id .  
Now it's possible to obtain the ActiveRecord "id" and Object "id" for  
an ActiveRecord object:
   @foo = Foo.find :first
   @foo.id               # => 3
   @foo.object_id  # => 20613620

I hope that clears up your question. Cheers,
Nick


More information about the rspec-users mailing list