make Attachment#make_childless safe to call more often

i.e. if it's already a child, or it has no children, and you don't
want to check those beforehand

Change-Id: Ie0568c980f888b1e39f64aa0108033222887b2b6
Reviewed-on: https://gerrit.instructure.com/97612
Tested-by: Jenkins
Reviewed-by: Rob Orton <rob@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2016-12-14 12:38:36 -07:00
parent 0e18d33f2d
commit cf3159e445
1 changed files with 2 additions and 0 deletions

View File

@ -1213,7 +1213,9 @@ class Attachment < ActiveRecord::Base
end end
def make_childless(preferred_child = nil) def make_childless(preferred_child = nil)
return if root_attachment_id
child = preferred_child || children.take child = preferred_child || children.take
return unless child
raise "must be a child" unless child.root_attachment_id == id raise "must be a child" unless child.root_attachment_id == id
child.root_attachment_id = nil child.root_attachment_id = nil
child.filename = filename if filename child.filename = filename if filename