Skip to content

Commit

Permalink
Fix Relationship#grandchildren
Browse files Browse the repository at this point in the history
grandchild_conditions did not properly building sql.
The sql would never return any rows

Now it returns the correct nodes
  • Loading branch information
kbrock committed Nov 28, 2018
1 parent 3ef8fd5 commit c6d3285
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def self.stringify_resource_pairs(resource_pairs, options = {})
def grandchild_conditions
t = self.class.arel_table
t.grouping(t[:ancestry].matches("#{child_ancestry}/%", nil, true).and(
t[:ancestry].does_not_match("#{child_ancestry}/%", nil, true)))
t[:ancestry].does_not_match("#{child_ancestry}/%/%", nil, true)))
end

def child_and_grandchild_conditions
Expand Down
20 changes: 19 additions & 1 deletion spec/models/mixins/relationship_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@
end
end

describe "#parent_rel_ids" do
describe "#parent_rels" do
it "works with relationships" do
pars = vms[8].with_relationship_type(test_rel_type, &:parent_rels)
pars_vms = pars.map(&:resource)
Expand All @@ -839,6 +839,24 @@
end
end

describe "#grandchild_rels" do
it "works with relationships" do
vms[0].with_relationship_type(test_rel_type) do
rels = vms[0].grandchild_rels
expect(rels.map(&:resource)).to match_array([vms[3], vms[4], vms[5], vms[6], vms[7]])
end
end
end

describe "#child_and_grandchild_rels" do
it "works with relationships" do
vms[0].with_relationship_type(test_rel_type) do
rels = vms[0].child_and_grandchild_rels
expect(rels.map(&:resource)).to match_array([vms[1], vms[2], vms[3], vms[4], vms[5], vms[6], vms[7]])
end
end
end

protected

def build_relationship_tree(tree, rel_type = test_rel_type, base_factory = :vm_vmware)
Expand Down

0 comments on commit c6d3285

Please sign in to comment.