Skip to content

Commit

Permalink
Fixed RSpecs which had sideeffects [#90 state:resolved]
Browse files Browse the repository at this point in the history
Fixed bug on property aggregates - cascade delete did not work together with property aggregates.
Changed so rakefile also runs all aggregates extension specs
  • Loading branch information
andreas committed Nov 23, 2009
1 parent 8c32c93 commit 4fbb012
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Expand Up @@ -66,14 +66,14 @@ There are also some complete examples in the example folder

To install it:

gem install neo4j
jruby -S gem install neo4j

To install from the latest source:
git clone git://github.com/andreasronge/neo4j.git
cd neo4j
rake gem:install

This has been verified to work on JRuby 1.3.0
This has been verified to work on JRuby 1.4.0

==== Running all RSpecs

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -44,7 +44,7 @@ Spec::Rake::SpecTask.new do |t|
# t.rcov = true
# rest specs requires some other gems - see the rest_spec.rb file
t.spec_files = FileList['test/lucene/*_spec.rb'] + FileList['test/neo4j/*_spec.rb'] +
FileList['test/extensions/*_spec.rb'] # FileList['test/**/*_spec.rb']
FileList['test/extensions/**/*_spec.rb'] # FileList['test/**/*_spec.rb']
t.spec_opts = ['--format specdoc', '--color']
# t.spec_opts = ['--format html:../doc/output/report.html'] #,'--backtrace']
end
Expand Down
5 changes: 5 additions & 0 deletions lib/neo4j/event_handler.rb
Expand Up @@ -20,6 +20,11 @@ def remove_all
@listeners = []
end

def print
puts "Listeners #{@listeners.size}"
@listeners.each {|li| puts " Listener '#{li}'"}
end

def add_filter(filter_class)
@filter_classes << filter_class unless @filter_classes.include?(filter_class)
end
Expand Down
5 changes: 2 additions & 3 deletions lib/neo4j/extensions/aggregate/prop_group.rb
Expand Up @@ -3,7 +3,6 @@ module Neo4j::Aggregate
class PropGroup
include Neo4j::NodeMixin
include Enumerable
# alias :original_ignore_incoming_cascade_delete? :ignore_incoming_cascade_delete?

has_one :aggregate, :cascade_delete => :incoming
property :aggregate_group, :aggregate_size, :group_by
Expand All @@ -23,8 +22,8 @@ def get_property(key)
end

def ignore_incoming_cascade_delete? (relationship)
return true if super(relationship) #original_ignore_incoming_cascade_delete?(node,relationship)
return true if relationship.start_node.kind_of?(Neo4j::Aggregate::PropsAggregate)
return true if super #original_ignore_incoming_cascade_delete?(node,relationship)
relationship.start_node.kind_of?(Neo4j::Aggregate::PropsAggregate)
end

end
Expand Down
22 changes: 9 additions & 13 deletions lib/neo4j/extensions/aggregate/props_aggregator.rb
Expand Up @@ -46,15 +46,8 @@ def on_property_changed(node, prop_key, old_value, new_value) # :nodoc:
return if node.class != @filter
return unless @group_by.include?(prop_key.to_sym)

# for each aggregate the node belongs to delete it
# we have to first create it and then deleted, otherwise cascade delete will kick in
group = node.aggregate_groups(@agg_id)

# recreate the aggregate group
execute([node])

# delete this aggregate group if it exists
group.delete if group
end


Expand All @@ -66,12 +59,15 @@ def with(prop_key, &proc)
def execute(nodes = @nodes)
return unless nodes
nodes.each do |node|
group_node = PropGroup.new
group_node.group_by = @group_by.join(',')
group_node.aggregate = node
rel = group_node.relationships.outgoing(:aggregate)[node]
rel[:aggregate_group] = @agg_id
@root_node.groups << group_node
group_node = node.aggregate_groups(@agg_id)
if group_node.nil?
group_node = PropGroup.new
group_node.group_by = @group_by.join(',')
group_node.aggregate = node
rel = group_node.relationships.outgoing(:aggregate)[node]
rel[:aggregate_group] = @agg_id
@root_node.groups << group_node
end
if @with_proc
val = group_node.inject(0) {|sum, val| next sum if val.nil?; @with_proc.call(sum, val, 0)}
group_node[@prop_key.to_s] = val
Expand Down
18 changes: 12 additions & 6 deletions lib/neo4j/extensions/reindexer.rb
@@ -1,13 +1,9 @@
module Neo4j

module NodeMixin
alias :old_ignore_incoming_cascade_delete? :ignore_incoming_cascade_delete?

def ignore_incoming_cascade_delete? (node, relationship)
return true if old_ignore_incoming_cascade_delete?(node,relationship)

def ignore_incoming_cascade_delete? (relationship)
# if it's an index node relationship then it should be allowed to cascade delete the node
return relationship.other_node(node) == IndexNode.instance
return relationship.other_node(self) == IndexNode.instance
end

module ClassMethods
Expand Down Expand Up @@ -88,6 +84,10 @@ def self.instance
@index_node
end

def self.instance?
!@index_node.nil?
end

transactional :connect
end

Expand All @@ -99,5 +99,11 @@ def self.load_reindexer
Neo4j::Transaction.run { IndexNode.on_neo_started(Neo4j.instance) } if Neo4j.running?
end

def self.unload_reindexer
Neo4j.event_handler.remove(IndexNode)
Neo4j.event_handler.remove(IndexNode.instance) if IndexNode.instance?
end


load_reindexer
end
3 changes: 1 addition & 2 deletions test/neo4j/node_lucene_spec.rb
Expand Up @@ -12,7 +12,7 @@

after(:all) do
stop
Neo4j.event_handler.remove_all
Neo4j.unload_reindexer
end

describe "Neo4j.start" do
Expand Down Expand Up @@ -386,7 +386,6 @@ class PersonNode
before(:each) do
undefine_class :PersonNode
start
Neo4j.load_reindexer
class PersonNode
include Neo4j::NodeMixin
property :name
Expand Down
18 changes: 8 additions & 10 deletions test/neo4j/reindexer_spec.rb
Expand Up @@ -19,9 +19,7 @@ class ReindexerTestNode2

before(:each) do
start
Neo4j.load_reindexer
Neo4j::Transaction.new

Neo4j::IndexNode.instance.relationships.each {|r| r.delete unless r.start_node == Neo4j.ref_node}
undefine_class :TestNode # must undefine this since each spec defines it
end
Expand All @@ -33,11 +31,11 @@ class ReindexerTestNode2

before(:all) do
require 'neo4j/extensions/reindexer'
Neo4j.event_handler.add(Neo4j::IndexNode) # in case it has been disabled by an RSpec
Neo4j.load_reindexer
end

after(:all) do
Neo4j.event_handler.remove_all
Neo4j.unload_reindexer
end


Expand Down Expand Up @@ -160,16 +158,17 @@ class B < A

describe "Reindex" do
before(:all) do
start
require 'neo4j/extensions/reindexer'
Neo4j.load_reindexer # since a previous test might have unloaded this extension
end

after(:all) do
Neo4j.event_handler.remove_all
Neo4j.unload_reindexer # since a previous test might have unloaded this extension
stop
end

it "should reindex nodes after the neo4j has restarted (lighthouse ticket #53)" do
Neo4j.load_reindexer # since a previous test might have unloaded this extension

undefine_class :TestNode
class TestNode
include Neo4j::NodeMixin
Expand Down Expand Up @@ -205,7 +204,6 @@ class TestNode
Neo4j::Transaction.new
[*TestNode.all.nodes].should include(t2)
Neo4j::Transaction.finish

end
end

Expand Down
2 changes: 0 additions & 2 deletions test/neo4j/relation_traverser_spec.rb
Expand Up @@ -5,8 +5,6 @@
require 'spec_helper'




describe Neo4j::Relationships::RelationshipTraverser do
before(:all) do
start
Expand Down

0 comments on commit 4fbb012

Please sign in to comment.