That''s because ''b'' is already a stale object. You can
rewrite your test
to check if ''b'' has really been destroyed/deleted on the DB
this way:
assert B.find_by_id(b.id).nil?
HTH
On 10/13/10 10:27 PM, Georg M. wrote:> Hi alls,
>
> I have a model like this:
>
> <code>
> class A < ActiveRecord::Base
> has_many :bs, :dependent => :destroy
> end
> </code>
>
> and I have test code like this:
>
> <code>
> a = create_a
> b = create_b(a)
> a.save
> b.save
> assert_difference ''B.count'', -1 do # WORKS
> a.destroy
> end
> assert a.destroyed? # WORKS
> assert b.destroyed? # FAILS - why?
> </code>
>
> b is deleted from the database but the destroyed method returns false.
> Why ist the test failing and what can I do to make the last assert pass?
>
> Thanks, Georg
>
--
Erol Fornoles
http://github.com/Erol
http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.