views:

15

answers:

1

I have in project.rb:

has_many :items, :dependent => :destroy

And in item.rb:

belongs_to :project

My projects fixture:

b1_s_first_project:
  title: B1's first project

And my items fixture:

b1_s_first_project_s_first_item:
  title: B1's first project's first item
  project: b1_s_first_project

In my unit test, I set local variables item = items(:b1_s_first_project_s_first_item) and project = projects(:b1_s_first_project). When I call project.destroy, project.destroyed? returns true, but item.destroyed? returns nil, as if it hadn't been destroyed. What am I missing? Thanks in advance.

+1  A: 

It looks like you might need to add item.reload before testing if it's destroyed or not

marcgg
Very good. Essentially correct. `item.reload` raised the Object not found exception, so I just changed the assertion to `assert !Item.exists?(item)`. Funny though, I thought the whole point of the ActiveRecord was to update the objects automatically so you wouldn't have to re-find each time. It seems as though the .destroyed? flag would be one of the things that would update itself.
Steven Xu
@steven: The thing is once the object is loaded it's cached somehow and then there is now broadcast process to let the object know that it's deleted ^^ Glad I could help
marcgg