From 17f82853ffd16fd202037530092da0eaf57e1370 Mon Sep 17 00:00:00 2001 From: Dieter Pisarewski Date: Mon, 8 Dec 2014 14:48:07 +0100 Subject: [PATCH] added some specs, removed neo4j from multiple_dbs feature --- .travis.yml | 1 + .../features/step_definitions/neo4j_steps.rb | 8 ----- examples/features/support/env.rb | 3 -- examples/lib/neo4j_models.rb | 3 +- features/cleaning_multiple_dbs.feature | 3 -- lib/database_cleaner/neo4j/base.rb | 2 +- spec/database_cleaner/base_spec.rb | 35 +++++++++++++++--- spec/database_cleaner/configuration_spec.rb | 5 +++ spec/database_cleaner/neo4j/base_spec.rb | 36 +++++++++++++++++++ .../neo4j/transaction_spec.rb | 26 ++++++++++++++ 10 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 spec/database_cleaner/neo4j/base_spec.rb create mode 100644 spec/database_cleaner/neo4j/transaction_spec.rb diff --git a/.travis.yml b/.travis.yml index 4ab0296..38766c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,3 +14,4 @@ before_script: services: - redis-server - mongodb + - neo4j \ No newline at end of file diff --git a/examples/features/step_definitions/neo4j_steps.rb b/examples/features/step_definitions/neo4j_steps.rb index bbf8bd2..e74bbc2 100644 --- a/examples/features/step_definitions/neo4j_steps.rb +++ b/examples/features/step_definitions/neo4j_steps.rb @@ -1,11 +1,3 @@ -Given /^I have setup database cleaner to clean multiple databases using neo4j$/ do - #DatabaseCleaner - # require "#{File.dirname(__FILE__)}/../../../lib/neo4j_models" - # - # DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7475'} ] - # DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7476'} ] -end - When /^I create a widget using neo4j$/ do Neo4jWidget.create! end diff --git a/examples/features/support/env.rb b/examples/features/support/env.rb index b5986db..fad0cf1 100644 --- a/examples/features/support/env.rb +++ b/examples/features/support/env.rb @@ -47,9 +47,6 @@ if orm && strategy when :active_record DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseOne} ].strategy = strategy.to_sym DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseTwo} ].strategy = strategy.to_sym - when :neo4j - DatabaseCleaner[:neo4j, {:connection => {:type => :server_db, :path => 'http://localhost:7475/'}} ].strategy = strategy.to_sym - DatabaseCleaner[:neo4j, {:connection => {:type => :server_db, :path => 'http://localhost:7476/'}} ].strategy = strategy.to_sym else DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym diff --git a/examples/lib/neo4j_models.rb b/examples/lib/neo4j_models.rb index 496017d..968dad3 100644 --- a/examples/lib/neo4j_models.rb +++ b/examples/lib/neo4j_models.rb @@ -1,4 +1,5 @@ require 'neo4j-core' +DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7474'}] class Neo4jWidget < Neo4j::Node def self.create!(*args) @@ -14,4 +15,4 @@ class Neo4jWidgetUsingDatabaseOne < Neo4jWidget end class Neo4jWidgetUsingDatabaseTwo < Neo4jWidget -end \ No newline at end of file +end diff --git a/features/cleaning_multiple_dbs.feature b/features/cleaning_multiple_dbs.feature index 992f3d2..a426b5c 100644 --- a/features/cleaning_multiple_dbs.feature +++ b/features/cleaning_multiple_dbs.feature @@ -18,6 +18,3 @@ Feature: multiple database cleaning | MongoMapper | truncation | | DataMapper | transaction | | ActiveRecord | transaction | - | Neo4j | deletion | - | Neo4j | truncation | - | Neo4j | transaction | diff --git a/lib/database_cleaner/neo4j/base.rb b/lib/database_cleaner/neo4j/base.rb index e2db2f3..a789dc1 100644 --- a/lib/database_cleaner/neo4j/base.rb +++ b/lib/database_cleaner/neo4j/base.rb @@ -31,7 +31,7 @@ module DatabaseCleaner private def default_db - {type: default_db_type, path: default_db_path} + {:type => default_db_type, :path => default_db_path} end def default_db_type diff --git a/spec/database_cleaner/base_spec.rb b/spec/database_cleaner/base_spec.rb index 31a2166..f750120 100644 --- a/spec/database_cleaner/base_spec.rb +++ b/spec/database_cleaner/base_spec.rb @@ -4,6 +4,7 @@ require 'database_cleaner/data_mapper/transaction' require 'database_cleaner/mongo_mapper/truncation' require 'database_cleaner/mongoid/truncation' require 'database_cleaner/couch_potato/truncation' +require 'database_cleaner/neo4j/transaction' module DatabaseCleaner describe Base do @@ -21,6 +22,7 @@ module DatabaseCleaner Temp_MP = ::Moped if defined?(::Moped) and not defined?(Temp_MP) Temp_RS = ::Redis if defined?(::Redis) and not defined?(Temp_RS) Temp_OH = ::Ohm if defined?(::Ohm) and not defined?(Temp_OH) + Temp_NJ = ::Neo4j if defined?(::Neo4j) and not defined?(Temp_NJ) end #Remove all ORM mocks and restore from cache @@ -34,6 +36,7 @@ module DatabaseCleaner Object.send(:remove_const, 'Moped') if defined?(::Moped) Object.send(:remove_const, 'Ohm') if defined?(::Ohm) Object.send(:remove_const, 'Redis') if defined?(::Redis) + Object.send(:remove_const, 'Neo4j') if defined?(::Neo4j) # Restore ORMs @@ -46,6 +49,7 @@ module DatabaseCleaner ::Moped = Temp_MP if defined? Temp_MP ::Ohm = Temp_OH if defined? Temp_OH ::Redis = Temp_RS if defined? Temp_RS + ::Neo4j = Temp_NJ if defined? Temp_NJ end #reset the orm mocks @@ -59,6 +63,7 @@ module DatabaseCleaner Object.send(:remove_const, 'Moped') if defined?(::Moped) Object.send(:remove_const, 'Ohm') if defined?(::Ohm) Object.send(:remove_const, 'Redis') if defined?(::Redis) + Object.send(:remove_const, 'Neo4j') if defined?(::Neo4j) end let(:cleaner) { DatabaseCleaner::Base.new :autodetect } @@ -77,6 +82,7 @@ module DatabaseCleaner Object.const_set('Moped', 'Moped mock') Object.const_set('Ohm', 'Ohm mock') Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :active_record cleaner.should be_auto_detected @@ -91,6 +97,7 @@ module DatabaseCleaner Object.const_set('Moped', 'Moped mock') Object.const_set('Ohm', 'Ohm mock') Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :data_mapper cleaner.should be_auto_detected @@ -104,6 +111,7 @@ module DatabaseCleaner Object.const_set('Moped', 'Moped mock') Object.const_set('Ohm', 'Ohm mock') Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :mongo_mapper cleaner.should be_auto_detected @@ -116,6 +124,7 @@ module DatabaseCleaner Object.const_set('Moped', 'Moped mock') Object.const_set('Ohm', 'Ohm mock') Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :mongoid cleaner.should be_auto_detected @@ -127,6 +136,7 @@ module DatabaseCleaner Object.const_set('Moped', 'Moped mock') Object.const_set('Ohm', 'Ohm mock') Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :couch_potato cleaner.should be_auto_detected @@ -137,27 +147,37 @@ module DatabaseCleaner Object.const_set('Moped', 'Moped mock') Object.const_set('Ohm', 'Ohm mock') Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :sequel cleaner.should be_auto_detected end it 'detects Ohm seventh' do - Object.const_set('Ohm', 'Ohm mock') - Object.const_set('Redis', 'Redis mock') + Object.const_set('Ohm', 'Ohm mock') + Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :ohm cleaner.should be_auto_detected end - it 'detects Redis last' do - Object.const_set('Redis', 'Redis mock') + it 'detects Redis eighth' do + Object.const_set('Redis', 'Redis mock') + Object.const_set('Neo4j', 'Neo4j mock') cleaner.orm.should eq :redis cleaner.should be_auto_detected end - it 'detects Moped seventh' do + it 'detects Neo4j ninth' do + Object.const_set('Neo4j', 'Neo4j mock') + + cleaner.orm.should eq :neo4j + cleaner.should be_auto_detected + end + + it 'detects Moped seventh' do #FIXME Object.const_set('Moped', 'Moped mock') cleaner.orm.should eq :moped @@ -573,6 +593,11 @@ module DatabaseCleaner cleaner = DatabaseCleaner::Base.new(:redis) cleaner.strategy.should be_instance_of DatabaseCleaner::Redis::Truncation end + + it 'sets strategy to :transaction for Neo4j' do + cleaner = DatabaseCleaner::Base.new(:neo4j) + cleaner.strategy.should be_instance_of DatabaseCleaner::Neo4j::Transaction + end end end diff --git a/spec/database_cleaner/configuration_spec.rb b/spec/database_cleaner/configuration_spec.rb index 57f3d4d..8b7f501 100644 --- a/spec/database_cleaner/configuration_spec.rb +++ b/spec/database_cleaner/configuration_spec.rb @@ -336,5 +336,10 @@ describe ::DatabaseCleaner do subject.orm_module(:couch_potato).should eq DatabaseCleaner::CouchPotato end + it "should return DatabaseCleaner::Neo4j for :neo4j" do + ::DatabaseCleaner::Neo4j = double("nj module") unless defined? ::DatabaseCleaner::Neo4j + subject.orm_module(:neo4j).should eq DatabaseCleaner::Neo4j + end + end end diff --git a/spec/database_cleaner/neo4j/base_spec.rb b/spec/database_cleaner/neo4j/base_spec.rb new file mode 100644 index 0000000..ffd7f2a --- /dev/null +++ b/spec/database_cleaner/neo4j/base_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' +require 'database_cleaner/neo4j/base' +require 'database_cleaner/shared_strategy' + +module DatabaseCleaner + describe Neo4j do + it { should respond_to(:available_strategies) } + end + + module Neo4j + class ExampleStrategy + include ::DatabaseCleaner::Neo4j::Base + end + + describe ExampleStrategy do + + it_should_behave_like "a generic strategy" + it { should respond_to(:db) } + it { should respond_to(:db=) } + + it "should store my describe db" do + db_conf = {:connection => {:type => :server_db, :path => 'http://localhost:7474'}} + subject.db = db_conf + subject.db.should eq db_conf + end + + it "should default to nil" do + subject.db.should be_nil + end + + it "should return default configuration" do + subject.database.should eq(:type => :server_db, :path => 'http://localhost:7475/') + end + end + end +end diff --git a/spec/database_cleaner/neo4j/transaction_spec.rb b/spec/database_cleaner/neo4j/transaction_spec.rb new file mode 100644 index 0000000..e7a308c --- /dev/null +++ b/spec/database_cleaner/neo4j/transaction_spec.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require 'neo4j-core' +require 'database_cleaner/neo4j/transaction' + + +module DatabaseCleaner + module Neo4j + + describe Transaction do + before(:all) do + DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7474'}] + end + + it_should_behave_like "a generic strategy" + it_should_behave_like "a generic transaction strategy" + + describe "start" do + it "should start a transaction" + end + + describe "clean" do + it "should finish a transaction" + end + end + end +end