Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails :dependent => :destroy in testing

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.

like image 378
Steven Avatar asked Aug 30 '25 16:08

Steven


1 Answers

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

like image 70
marcgg Avatar answered Sep 02 '25 16:09

marcgg