Skip to content

Commit

Permalink
Merge pull request #52 from vivekprahlad/master
Browse files Browse the repository at this point in the history
Speeded up tests
  • Loading branch information
andreasronge committed Oct 4, 2011
2 parents c8c5839 + 7661438 commit d37ddb6
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 9 deletions.
5 changes: 5 additions & 0 deletions spec/batch/indexer_spec.rb
Expand Up @@ -2,6 +2,10 @@


describe Neo4j::Batch::Indexer do
before(:each) do
Neo4j.threadlocal_ref_node = nil
end

def setup_index_provider(index_provider, exact_indexes, fulltext_indexes = {})
indexes = {}
exact_indexes.each_pair { |k, v| indexes["#{k}-exact"] = v }
Expand Down Expand Up @@ -164,6 +168,7 @@ def setup_index_provider(index_provider, exact_indexes, fulltext_indexes = {})
end

describe "#index_node_via_rel" do

it "does not index anything unless the index is decalred with an :via=>" do
clazz = create_node_mixin do
index :name
Expand Down
1 change: 1 addition & 0 deletions spec/batch/inserter_spec.rb
Expand Up @@ -8,6 +8,7 @@
rm_db_storage
@storage_path = File.expand_path(File.join(Dir.tmpdir, 'neo4j-batch-inserter'))
FileUtils.rm_rf @storage_path
Neo4j.threadlocal_ref_node = nil
end

after(:each) do
Expand Down
1 change: 1 addition & 0 deletions spec/batch/lucene_inserter_spec.rb
Expand Up @@ -12,6 +12,7 @@
Neo4j::Node.index(:description, :type => :fulltext)

@inserter = Neo4j::Batch::Inserter.new
Neo4j.threadlocal_ref_node = nil
end

after(:each) do
Expand Down
4 changes: 3 additions & 1 deletion spec/batch/rule_inserter_spec.rb
Expand Up @@ -2,7 +2,9 @@


describe Neo4j::Batch::RuleInserter do

before(:each) do
Neo4j.threadlocal_ref_node = nil
end

class TestInserter
attr_reader :created_nodes, :created_rels
Expand Down
3 changes: 2 additions & 1 deletion spec/index/index_spec.rb
Expand Up @@ -14,7 +14,8 @@ class TestIndex


describe Neo4j::Node, "index_names", :type => :transactional do
before(:all) do
before(:each) do
Neo4j.threadlocal_ref_node = nil
end

it "can be used to configure where the index is stored on the filesystem" do
Expand Down
4 changes: 4 additions & 0 deletions spec/migrations/global_migration_spec.rb
@@ -1,6 +1,10 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe "Neo4j#migration", :type => :transactional do
before(:each) do
Neo4j.threadlocal_ref_node = nil
end

after(:each) do
Neo4j::Migrations::RefNodeWrapper.reset_migrations!
Neo4j.db_version.should == 0
Expand Down
3 changes: 3 additions & 0 deletions spec/migrations/lazy_node_mixin_spec.rb
@@ -1,6 +1,9 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Neo4j::Migrations::LazyNodeMixin do
before(:each) do
Neo4j.threadlocal_ref_node = nil
end

def create_lazy_migration(clazz)
clazz.migration 1, :split_name do
Expand Down
5 changes: 4 additions & 1 deletion spec/rails/active_record_style_relationships_spec.rb
Expand Up @@ -7,6 +7,9 @@ class ModelRelationship1 < Neo4j::Rails::Relationship
end

before(:each) do
Neo4j::Transaction.run do
Neo4j::Index::IndexerRegistry.delete_all_indexes
end
@actor_class = create_model(Neo4j::Model)
@actor_class.property :name
@actor_class.property :description
Expand Down Expand Up @@ -134,7 +137,7 @@ class ModelRelationship1 < Neo4j::Rails::Relationship
it "find rels for a node, by node" do
@actor.acted_in_rels.find(@movie_1).should_not be_nil
end

it "find rels by id" do
relid = @actor.acted_in_rels.find(@movie_1).id
@actor.acted_in_rels.find(relid).should_not be_nil
Expand Down
4 changes: 4 additions & 0 deletions spec/rails/finders_spec.rb
Expand Up @@ -131,6 +131,10 @@ def nonexistant_id
Neo4j.threadlocal_ref_node = ref_1
@node_from_ref_1 = FindableModel.create!(:name => 'foo')
end

after(:each) do
Neo4j.threadlocal_ref_node = nil
end

context "when node reachable from ref node" do
it "should return node" do
Expand Down
9 changes: 9 additions & 0 deletions spec/rails/model_spec.rb
Expand Up @@ -3,6 +3,11 @@
# Specs written by Nick Sieger and modified by Andreas Ronge

describe Neo4j::Model do
before(:each) do
Neo4j::Transaction.run do
Neo4j::Index::IndexerRegistry.delete_all_indexes
end
end

describe "new" do
before :each do
Expand Down Expand Up @@ -641,6 +646,10 @@ def to_s
Neo4j.threadlocal_ref_node = ref_1
@node_from_ref_1 = IceCream.create!(:flavour => 'Vanilla')
end

after(:each) do
Neo4j.threadlocal_ref_node = nil
end

context "when node is created under current threadlocal ref_node" do
it "should be true" do
Expand Down
7 changes: 7 additions & 0 deletions spec/rails/relationship_spec.rb
Expand Up @@ -620,6 +620,10 @@ def reject_posts(attributed)

context "when there's lots of them" do
before(:each) do
Neo4j::Transaction.run do
Neo4j::Index::IndexerRegistry.delete_all_indexes
end

subject.class.create!(:foo, @start_node, @end_node)
subject.class.create!(:foo, @start_node, @end_node)
subject.class.create!(:foo, @start_node, @end_node)
Expand Down Expand Up @@ -667,6 +671,9 @@ def mark_saved

describe RelationshipWithProperty do
before(:each) do
Neo4j::Transaction.run do
Neo4j::Index::IndexerRegistry.delete_all_indexes
end
@start_node = Neo4j::Model.new
@end_node = Neo4j::Model.new
end
Expand Down
9 changes: 3 additions & 6 deletions spec/spec_helper.rb
Expand Up @@ -50,7 +50,7 @@ def new_tx
Neo4j::Config[:storage_path] = File.join(Dir.tmpdir, 'neo4j-rspec-tests')

RSpec.configure do |c|

$name_counter = 0
#c.filter = { :type => :problem}
c.before(:each, :type => :transactional) do
new_tx
Expand All @@ -59,9 +59,6 @@ def new_tx
c.after(:each, :type => :transactional) do
finish_tx
Neo4j::Rails::Model.close_lucene_connections
Neo4j::Transaction.run do
Neo4j._all_nodes.each { |n| n.del unless n.neo_id == 0 }
end
Neo4j::Transaction.run do
Neo4j::Index::IndexerRegistry.delete_all_indexes
end
Expand All @@ -70,9 +67,9 @@ def new_tx
c.after(:each) do
finish_tx
Neo4j::Rails::Model.close_lucene_connections
Neo4j.threadlocal_ref_node = nil
Neo4j::Transaction.run do
Neo4j._all_nodes.each { |n| n.del unless n.neo_id == 0 }
Neo4j.threadlocal_ref_node = Neo4j::Node.new :name => "ref_#{$name_counter}"
$name_counter += 1
end
end

Expand Down

0 comments on commit d37ddb6

Please sign in to comment.