make sure discussion subentry is deleted with parent

Change-Id: I5de4bb1a5527e6c7dc73205c1f6f8c329e74ad68
fixes: #6081
Reviewed-on: https://gerrit.instructure.com/6502
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Ryan Shaw 2011-10-26 13:45:07 -06:00
parent bd3dc5b820
commit 8dd5ad8c2b
3 changed files with 26 additions and 0 deletions

View File

@ -157,6 +157,7 @@ class DiscussionEntry < ActiveRecord::Base
alias_method :destroy!, :destroy
def destroy
discussion_subentries.each &:destroy
self.workflow_state = 'deleted'
self.deleted_at = Time.now
save!

View File

@ -0,0 +1,10 @@
class DeleteSubEntriesOfDeletedDiscussionEntries < ActiveRecord::Migration
def self.up
DiscussionEntry.find_each(:conditions => {:workflow_state => 'deleted'}) do |entry|
entry.discussion_subentries.each &:destroy
end
end
def self.down
end
end

View File

@ -35,6 +35,21 @@ describe DiscussionEntry do
sub_entry.save!
sub_entry.parent_id.should eql(0)
end
it "should be marked as deleted when parent is deleted" do
topic = course.discussion_topics.create!
entry = topic.discussion_entries.create!
sub_entry = topic.discussion_entries.build
sub_entry.parent_id = entry.id
sub_entry.save!
topic.discussion_entries.active.length.should == 2
entry.destroy
sub_entry.reload
sub_entry.should be_deleted
topic.discussion_entries.active.length.should == 0
end
it "should only allow one level of nesting" do
course