ruby on rails - Factory Girl not destroying objects properly -


i creating object several has_many associations. regards tob building object works fine, when try test deletion of 1 of children or parent, not reflect in test.

for example:

 base_article = factory(:base_article, :articles => [factory(:article)])  p base_article.articles.size  base_article.articles.first.destroy  p base_article.articles.size  base_article.destroyed?.should == true 

this prints out:

1

1

i testing callback after destroy on article deletes base when there no more children. why size of articles association not being reduced one?

thanks!

you need reload articles collection rails' database caching stale:

base_article = factory(:base_article, :articles => [factory(:article)]) base_article.articles.size # => 1  base_article.articles.first.destroy base_article.articles.size # => 1 base_article.articles.reload.size # => 0  base_article.destroyed?.should == true  

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -