Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/acts_as_commentable_with_threading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module CommentableWithThreading #:nodoc:

module ClassMethods
def acts_as_commentable
has_many :comment_threads, :class_name => "Comment", :as => :commentable, :dependent => :destroy
has_many :comment_threads, :class_name => "Comment", :as => :commentable
before_destroy { |record| record.root_comments.destroy_all }
include Acts::CommentableWithThreading::LocalInstanceMethods
extend Acts::CommentableWithThreading::SingletonMethods
end
Expand Down
23 changes: 23 additions & 0 deletions spec/commentable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
Commentable.new.comment_threads.should be_a_kind_of(Enumerable)
end

describe "when is destroyed" do
before :each do
@user = User.create!
@commentable = Commentable.create!
@comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'blargh')
end

it "also destroys its root comments" do
@commentable.destroy
Comment.all.should_not include(@comment)
end

it "also destroys its nested comments" do
child = Comment.new(:body => "This is a child", :commentable => @commentable, :user => @user)
child.save!
child.move_to_child_of(@comment)

@commentable.destroy
Comment.all.should_not include(@comment)
Comment.all.should_not include(child)
end
end

describe "special class finders" do
before :each do
@user = User.create!
Expand Down