From 039bef660f8134e538b583e1b9b6a69da5df55a4 Mon Sep 17 00:00:00 2001 From: jho406 Date: Mon, 5 Oct 2009 14:08:52 -0400 Subject: [PATCH] node subclasses get relationship of self and ancestors [#64] --- lib/neo4j/extensions/reindexer.rb | 6 ++++-- test/neo4j/reindexer_spec.rb | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/neo4j/extensions/reindexer.rb b/lib/neo4j/extensions/reindexer.rb index 07d93fc09..872497285 100644 --- a/lib/neo4j/extensions/reindexer.rb +++ b/lib/neo4j/extensions/reindexer.rb @@ -19,7 +19,7 @@ def update_index # :api: public def all index_node = IndexNode.instance - index_node.relationships.outgoing(root_class) + index_node.relationships.outgoing(self) end end @@ -53,7 +53,9 @@ def connect(node, type = node.class.root_class) def on_node_created(node) # we have to avoid connecting to our self - connect(node) unless self == node + unless self == node + node.class.ancestors.grep(Class).each{|p| connect(node, p) if p.respond_to?(:all)} + end end def self.on_neo_started(neo_instance) diff --git a/test/neo4j/reindexer_spec.rb b/test/neo4j/reindexer_spec.rb index 9713f7728..da0bd7257 100644 --- a/test/neo4j/reindexer_spec.rb +++ b/test/neo4j/reindexer_spec.rb @@ -135,7 +135,7 @@ class TestNode TestNode.all.nodes.to_a.should include(t2) end - it "should return subclasses instances as well" do + it "should return subclasses instances if subclassed" do class A include Neo4j::NodeMixin end @@ -149,7 +149,9 @@ class B < A # then A.all.to_a.size.should == 2 - B.all.nodes.to_a.should include(a, b) + A.all.nodes.to_a.should include(a, b) + B.all.to_a.size.should == 1 + B.all.nodes.to_a.should include(b) end end