Skip to content

Commit

Permalink
node subclasses get relationship of self and ancestors [#64]
Browse files Browse the repository at this point in the history
  • Loading branch information
jho406 committed Oct 5, 2009
1 parent 97313c6 commit 039bef6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/neo4j/extensions/reindexer.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions test/neo4j/reindexer_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 039bef6

Please sign in to comment.