From d456dec81c3d0dfd962a3325cddcab2c7566e23a Mon Sep 17 00:00:00 2001 From: James Wong Date: Thu, 22 Feb 2018 22:33:01 -0500 Subject: [PATCH] removal of nil before remove_children Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1511214 --- app/models/mixins/relationship_mixin.rb | 2 +- spec/models/mixins/relationship_mixin_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/mixins/relationship_mixin.rb b/app/models/mixins/relationship_mixin.rb index 9383993a1ee..8f4ddce0f8c 100644 --- a/app/models/mixins/relationship_mixin.rb +++ b/app/models/mixins/relationship_mixin.rb @@ -612,7 +612,7 @@ def remove_parent(parent) end def remove_children(*child_objs) - child_objs = child_objs.flatten + child_objs = child_objs.flatten.compact return child_objs if child_objs.empty? child_rels = self.child_rels diff --git a/spec/models/mixins/relationship_mixin_spec.rb b/spec/models/mixins/relationship_mixin_spec.rb index 0c3e2a5351d..99407a112ae 100644 --- a/spec/models/mixins/relationship_mixin_spec.rb +++ b/spec/models/mixins/relationship_mixin_spec.rb @@ -9,6 +9,12 @@ # host with no tree let(:host) { FactoryGirl.create(:host) } + describe "#remove_children" do + it "handles [nil]" do + expect { vms[3].remove_children(nil) }.to_not raise_error + end + end + context "tree with relationship" do it "#with_relationship_type and #relationship_type" do expect(vms[0].relationship_type).not_to eq(test_rel_type)