Skip to content
Open
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
34 changes: 29 additions & 5 deletions spec/commentable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,51 @@
Commentable.new.comment_threads.respond_to?(:each).should be_true
end


describe "when is destroyed" do
def create_comment(props={})
Comment.create! props.reverse_merge(:user => @user, :commentable => @commentable, :body => 'blargh')
end

def create_reply_to(parent, props={})
child = Comment.new props.reverse_merge(:body => "This is a child", :commentable => @commentable, :user => @user)
child.save!
child.move_to_child_of(parent)
end

before :each do
@user = User.create!
@commentable = Commentable.create!
@comment = Comment.create!(:user => @user, :commentable => @commentable, :body => 'blargh')
@comment = create_comment
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)
it "also destroys its child comments" do
child = create_reply_to @comment

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

it "also destroys its nested comments" do
c2 = create_comment :body => "Two"
c21 = create_reply_to c2, :body => "Two-one"
c211 = create_reply_to c21, :body => "Two-one-one"
c3 = create_comment :body => "Three"

expect { @commentable.destroy }.to change { Comment.count }.by(-5)
Comment.all.should_not include(@comment)
Comment.all.should_not include(c2)
Comment.all.should_not include(c21)
Comment.all.should_not include(c211)
Comment.all.should_not include(c3)
end
end

describe "special class finders" do
Expand Down