11175
(-- --)
1
Hi there
I wanted to know what's a good way to test whether dependent objects are
really destroyed when destroying the parent object?
I have a Blog model which has_many Comment model children. These
comments are set to :dependent => :destroy.
What's a good way to check this functionality in a unit test?
Thanks a lot
Josh
11175
(-- --)
2
Fernando Perez wrote:
NoMethodError: undefined method `+' for #<Class:0x22cb198>
Somewhere in your Blog or Comment code, there is a + hanging around that
is trying to add an apple to a car engine.
No idea what you mean... Here's the code:
class Blog < ActiveRecord::Base
validates_presence_of :user_id, :title, :content
belongs_to :user
has_many :comments,
:as => :commentable,
:dependent => :destroy
end
class Comment < ActiveRecord::Base
validates_presence_of :commentable,
:subject,
:body
belongs_to :user
belongs_to :article
belongs_to :commentable, :polymorphic => true # Kann sowohl einem
Article als auch einem Blog zugehörig sein
def html_anchor
"comment-#{id}"
end
end
Dr_Gavin1
(Dr_Gavin)
3
have you tried:
assert_difference "Comment.count", blog.comments.count do
  blog(:with_comments).destroy
end
might need to put a minus before the blog.comments.count too.