database_cleaner 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTE.markdown +28 -0
- data/Gemfile.lock +182 -116
- data/History.rdoc +18 -1
- data/README.markdown +41 -4
- data/Rakefile +1 -17
- data/VERSION.yml +2 -3
- data/examples/Gemfile +17 -15
- data/examples/Gemfile.lock +182 -116
- data/examples/features/step_definitions/neo4j_steps.rb +23 -0
- data/examples/features/support/env.rb +0 -3
- data/examples/lib/mongoid_models.rb +1 -6
- data/examples/lib/neo4j_models.rb +17 -0
- data/examples/lib/sequel_models.rb +9 -0
- data/features/cleaning.feature +6 -0
- data/features/cleaning_default_strategy.feature +2 -0
- data/features/cleaning_multiple_dbs.feature +2 -0
- data/features/cleaning_multiple_orms.feature +19 -0
- data/features/step_definitions/database_cleaner_steps.rb +1 -1
- data/lib/database_cleaner/active_record/deletion.rb +30 -0
- data/lib/database_cleaner/active_record/truncation.rb +29 -1
- data/lib/database_cleaner/base.rb +4 -0
- data/lib/database_cleaner/configuration.rb +2 -0
- data/lib/database_cleaner/data_mapper/truncation.rb +5 -42
- data/lib/database_cleaner/mongo/base.rb +2 -0
- data/lib/database_cleaner/mongo/truncation.rb +40 -0
- data/lib/database_cleaner/mongoid/truncation.rb +8 -1
- data/lib/database_cleaner/moped/truncation_base.rb +1 -1
- data/lib/database_cleaner/neo4j/base.rb +58 -0
- data/lib/database_cleaner/neo4j/deletion.rb +16 -0
- data/lib/database_cleaner/neo4j/transaction.rb +35 -0
- data/lib/database_cleaner/neo4j/truncation.rb +9 -0
- data/lib/database_cleaner/sequel/base.rb +2 -2
- data/lib/database_cleaner/sequel/deletion.rb +47 -0
- data/lib/database_cleaner/sequel/transaction.rb +5 -5
- data/lib/database_cleaner/sequel/truncation.rb +41 -13
- data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +1 -3
- data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +2 -4
- data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +13 -4
- data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -2
- data/spec/database_cleaner/base_spec.rb +48 -12
- data/spec/database_cleaner/configuration_spec.rb +5 -0
- data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +41 -0
- data/spec/database_cleaner/moped/moped_examples.rb +6 -0
- data/spec/database_cleaner/moped/truncation_spec.rb +7 -2
- data/spec/database_cleaner/neo4j/base_spec.rb +36 -0
- data/spec/database_cleaner/neo4j/transaction_spec.rb +25 -0
- data/spec/database_cleaner/sequel/deletion_spec.rb +58 -0
- data/spec/database_cleaner/sequel/truncation_spec.rb +38 -0
- data/spec/support/active_record/mysql2_setup.rb +1 -2
- data/spec/support/active_record/mysql_setup.rb +1 -1
- data/spec/support/active_record/postgresql_setup.rb +1 -1
- data/spec/support/active_record/schema_setup.rb +8 -1
- data/spec/support/active_record/sqlite3_setup.rb +1 -1
- data/spec/support/data_mapper/schema_setup.rb +15 -0
- data/spec/support/data_mapper/sqlite3_setup.rb +39 -0
- metadata +136 -111
@@ -2,6 +2,7 @@ require 'database_cleaner/mongoid/base'
|
|
2
2
|
require 'database_cleaner/generic/truncation'
|
3
3
|
require 'database_cleaner/mongo/truncation_mixin'
|
4
4
|
require 'database_cleaner/moped/truncation_base'
|
5
|
+
require 'mongoid/tree'
|
5
6
|
require 'mongoid/version'
|
6
7
|
|
7
8
|
module DatabaseCleaner
|
@@ -30,8 +31,14 @@ module DatabaseCleaner
|
|
30
31
|
::Mongoid.default_session
|
31
32
|
end
|
32
33
|
|
34
|
+
def database
|
35
|
+
if not(@db.nil? or @db == :default)
|
36
|
+
::Mongoid.databases[@db]
|
37
|
+
else
|
38
|
+
::Mongoid.database
|
39
|
+
end
|
40
|
+
end
|
33
41
|
end
|
34
|
-
|
35
42
|
end
|
36
43
|
end
|
37
44
|
end
|
@@ -23,7 +23,7 @@ module DatabaseCleaner
|
|
23
23
|
session.use(db)
|
24
24
|
end
|
25
25
|
|
26
|
-
session['system.namespaces'].find(:name => { '$not' =>
|
26
|
+
session['system.namespaces'].find(:name => { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
|
27
27
|
_, name = collection['name'].split('.', 2)
|
28
28
|
name
|
29
29
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'database_cleaner/generic/base'
|
2
|
+
module DatabaseCleaner
|
3
|
+
module Neo4j
|
4
|
+
def self.available_strategies
|
5
|
+
%w[transaction truncation deletion]
|
6
|
+
end
|
7
|
+
|
8
|
+
module Base
|
9
|
+
include ::DatabaseCleaner::Generic::Base
|
10
|
+
|
11
|
+
def db=(desired_db)
|
12
|
+
@db = desired_db == :default ? nil : desired_db
|
13
|
+
end
|
14
|
+
|
15
|
+
def db
|
16
|
+
@db ||= nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
if db_type == :embedded_db and not session.running?
|
21
|
+
session.start
|
22
|
+
else
|
23
|
+
session
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def database
|
28
|
+
db && default_db.merge(db) || default_db
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def default_db
|
34
|
+
{:type => default_db_type, :path => default_db_path}
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_db_type
|
38
|
+
:server_db
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_db_path(type = default_db_type)
|
42
|
+
type == :server_db ? 'http://localhost:7475/' : './db/test'
|
43
|
+
end
|
44
|
+
|
45
|
+
def db_type
|
46
|
+
database[:type]
|
47
|
+
end
|
48
|
+
|
49
|
+
def db_path
|
50
|
+
database[:path]
|
51
|
+
end
|
52
|
+
|
53
|
+
def session
|
54
|
+
@session ||= ::Neo4j::Session.open(db_type, db_path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'database_cleaner/neo4j/base'
|
2
|
+
require 'neo4j-core'
|
3
|
+
|
4
|
+
module DatabaseCleaner
|
5
|
+
module Neo4j
|
6
|
+
class Deletion
|
7
|
+
include ::DatabaseCleaner::Neo4j::Base
|
8
|
+
|
9
|
+
def clean
|
10
|
+
::Neo4j::Transaction.run do
|
11
|
+
session._query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'database_cleaner/neo4j/base'
|
2
|
+
require 'database_cleaner/generic/transaction'
|
3
|
+
require 'neo4j-core'
|
4
|
+
|
5
|
+
module DatabaseCleaner
|
6
|
+
module Neo4j
|
7
|
+
class Transaction
|
8
|
+
include ::DatabaseCleaner::Generic::Transaction
|
9
|
+
include ::DatabaseCleaner::Neo4j::Base
|
10
|
+
|
11
|
+
attr_accessor :tx
|
12
|
+
|
13
|
+
def start
|
14
|
+
super
|
15
|
+
rollback
|
16
|
+
self.tx = ::Neo4j::Transaction.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def clean
|
20
|
+
rollback
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def rollback
|
26
|
+
if tx
|
27
|
+
tx.failure
|
28
|
+
tx.close
|
29
|
+
end
|
30
|
+
ensure
|
31
|
+
self.tx = nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,7 +2,7 @@ require 'database_cleaner/generic/base'
|
|
2
2
|
module DatabaseCleaner
|
3
3
|
module Sequel
|
4
4
|
def self.available_strategies
|
5
|
-
%w
|
5
|
+
%w(truncation transaction deletion)
|
6
6
|
end
|
7
7
|
|
8
8
|
module Base
|
@@ -14,7 +14,7 @@ module DatabaseCleaner
|
|
14
14
|
|
15
15
|
def db
|
16
16
|
return @db if @db && @db != :default
|
17
|
-
raise "As you have more than one active sequel database you have to specify the one to use manually!" if ::Sequel::DATABASES.count > 1
|
17
|
+
raise "As you have more than one active sequel database you have to specify the one to use manually!" if ::Sequel::DATABASES.count > 1
|
18
18
|
::Sequel::DATABASES.first || :default
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'database_cleaner/sequel/base'
|
2
|
+
require 'database_cleaner/generic/truncation'
|
3
|
+
require 'database_cleaner/sequel/truncation'
|
4
|
+
|
5
|
+
module DatabaseCleaner::Sequel
|
6
|
+
class Deletion < Truncation
|
7
|
+
def disable_referential_integrity(tables)
|
8
|
+
case db.database_type
|
9
|
+
when :postgres
|
10
|
+
db.run('SET CONSTRAINTS ALL DEFERRED')
|
11
|
+
tables_to_truncate(db).each do |table|
|
12
|
+
db.run("ALTER TABLE \"#{table}\" DISABLE TRIGGER ALL")
|
13
|
+
end
|
14
|
+
when :mysql
|
15
|
+
old = db.fetch('SELECT @@FOREIGN_KEY_CHECKS').first[:@@FOREIGN_KEY_CHECKS]
|
16
|
+
db.run('SET FOREIGN_KEY_CHECKS = 0')
|
17
|
+
end
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
case db.database_type
|
21
|
+
when :postgres
|
22
|
+
tables.each do |table|
|
23
|
+
db.run("ALTER TABLE \"#{table}\" ENABLE TRIGGER ALL")
|
24
|
+
end
|
25
|
+
when :mysql
|
26
|
+
db.run("SET FOREIGN_KEY_CHECKS = #{old}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete_tables(db, tables)
|
31
|
+
tables.each do |table|
|
32
|
+
db[table.to_sym].delete
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def clean
|
37
|
+
return unless dirty?
|
38
|
+
|
39
|
+
tables = tables_to_truncate(db)
|
40
|
+
db.transaction do
|
41
|
+
disable_referential_integrity(tables) do
|
42
|
+
delete_tables(db, tables)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -16,19 +16,19 @@ module DatabaseCleaner
|
|
16
16
|
def start
|
17
17
|
self.class.check_fiber_brokenness
|
18
18
|
|
19
|
-
@fibers||= []
|
20
|
-
db= self.db
|
21
|
-
f= Fiber.new do
|
19
|
+
@fibers ||= []
|
20
|
+
db = self.db
|
21
|
+
f = Fiber.new do
|
22
22
|
db.transaction(:rollback => :always, :savepoint => true) do
|
23
23
|
Fiber.yield
|
24
24
|
end
|
25
25
|
end
|
26
26
|
f.resume
|
27
|
-
@fibers<< f
|
27
|
+
@fibers << f
|
28
28
|
end
|
29
29
|
|
30
30
|
def clean
|
31
|
-
f= @fibers.pop
|
31
|
+
f = @fibers.pop
|
32
32
|
f.resume
|
33
33
|
end
|
34
34
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'database_cleaner/generic/truncation'
|
2
2
|
require 'database_cleaner/sequel/base'
|
3
3
|
|
4
4
|
module DatabaseCleaner
|
@@ -7,32 +7,59 @@ module DatabaseCleaner
|
|
7
7
|
include ::DatabaseCleaner::Sequel::Base
|
8
8
|
include ::DatabaseCleaner::Generic::Truncation
|
9
9
|
|
10
|
+
def start
|
11
|
+
@last_txid = txid
|
12
|
+
end
|
13
|
+
|
10
14
|
def clean
|
15
|
+
return unless dirty?
|
16
|
+
|
11
17
|
case db.database_type
|
12
18
|
when :postgres
|
13
19
|
# PostgreSQL requires all tables with FKs to be truncates in the same command, or have the CASCADE keyword
|
14
20
|
# appended. Bulk truncation without CASCADE is:
|
15
21
|
# * Safer. Tables outside of tables_to_truncate won't be affected.
|
16
22
|
# * Faster. Less roundtrips to the db.
|
17
|
-
unless (tables= tables_to_truncate(db)).empty?
|
18
|
-
all_tables= tables.map{|t| %
|
23
|
+
unless (tables = tables_to_truncate(db)).empty?
|
24
|
+
all_tables = tables.map { |t| %("#{t}") }.join(',')
|
19
25
|
db.run "TRUNCATE TABLE #{all_tables};"
|
20
26
|
end
|
21
27
|
else
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
tables = tables_to_truncate(db)
|
29
|
+
|
30
|
+
if pre_count?
|
31
|
+
# Count rows before truncating
|
32
|
+
pre_count_truncate_tables(db, tables)
|
33
|
+
else
|
34
|
+
# Truncate each table normally
|
35
|
+
truncate_tables(db, tables)
|
25
36
|
end
|
26
37
|
end
|
27
38
|
end
|
28
39
|
|
29
|
-
|
30
|
-
|
31
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def pre_count_truncate_tables(db, tables)
|
43
|
+
tables = tables.reject { |table| db[table.to_sym].count == 0 }
|
44
|
+
truncate_tables(db, tables)
|
45
|
+
end
|
46
|
+
|
47
|
+
def truncate_tables(db, tables)
|
48
|
+
tables.each do |table|
|
49
|
+
db[table.to_sym].truncate
|
32
50
|
end
|
33
51
|
end
|
34
52
|
|
35
|
-
|
53
|
+
def dirty?
|
54
|
+
@last_txid != txid || @last_txid.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
def txid
|
58
|
+
case db.database_type
|
59
|
+
when :postgres
|
60
|
+
db.fetch('SELECT txid_snapshot_xmax(txid_current_snapshot()) AS txid').first[:txid]
|
61
|
+
end
|
62
|
+
end
|
36
63
|
|
37
64
|
def tables_to_truncate(db)
|
38
65
|
(@only || db.tables.map(&:to_s)) - @tables_to_exclude
|
@@ -40,11 +67,12 @@ module DatabaseCleaner
|
|
40
67
|
|
41
68
|
# overwritten
|
42
69
|
def migration_storage_names
|
43
|
-
%w
|
70
|
+
%w(schema_info schema_migrations)
|
44
71
|
end
|
45
72
|
|
73
|
+
def pre_count?
|
74
|
+
@pre_count == true
|
75
|
+
end
|
46
76
|
end
|
47
77
|
end
|
48
78
|
end
|
49
|
-
|
50
|
-
|
@@ -6,10 +6,9 @@ require 'database_cleaner/active_record/truncation/shared_fast_truncation'
|
|
6
6
|
|
7
7
|
module ActiveRecord
|
8
8
|
module ConnectionAdapters
|
9
|
-
describe do
|
9
|
+
describe do
|
10
10
|
before(:all) { active_record_mysql2_setup }
|
11
11
|
|
12
|
-
let(:adapter) { Mysql2Adapter }
|
13
12
|
let(:connection) { active_record_mysql2_connection }
|
14
13
|
|
15
14
|
describe "#truncate_table" do
|
@@ -31,7 +30,6 @@ module ActiveRecord
|
|
31
30
|
end
|
32
31
|
|
33
32
|
it_behaves_like "an adapter with pre-count truncation" do
|
34
|
-
let(:adapter) { Mysql2Adapter }
|
35
33
|
let(:connection) { active_record_mysql2_connection }
|
36
34
|
end
|
37
35
|
end
|
@@ -6,10 +6,9 @@ require 'database_cleaner/active_record/truncation/shared_fast_truncation'
|
|
6
6
|
|
7
7
|
module ActiveRecord
|
8
8
|
module ConnectionAdapters
|
9
|
-
describe do
|
9
|
+
describe do
|
10
10
|
before(:all) { active_record_mysql_setup }
|
11
11
|
|
12
|
-
let(:adapter) { MysqlAdapter }
|
13
12
|
let(:connection) { active_record_mysql_connection }
|
14
13
|
|
15
14
|
describe "#truncate_table" do
|
@@ -29,9 +28,8 @@ module ActiveRecord
|
|
29
28
|
User.create.id.should eq 1
|
30
29
|
end
|
31
30
|
end
|
32
|
-
|
31
|
+
|
33
32
|
it_behaves_like "an adapter with pre-count truncation" do
|
34
|
-
let(:adapter) { MysqlAdapter }
|
35
33
|
let(:connection) { active_record_mysql_connection }
|
36
34
|
end
|
37
35
|
end
|
@@ -9,8 +9,6 @@ module ActiveRecord
|
|
9
9
|
describe do
|
10
10
|
before(:all) { active_record_pg_setup }
|
11
11
|
|
12
|
-
let(:adapter) { PostgreSQLAdapter }
|
13
|
-
|
14
12
|
let(:connection) do
|
15
13
|
active_record_pg_connection
|
16
14
|
end
|
@@ -27,6 +25,13 @@ module ActiveRecord
|
|
27
25
|
User.count.should eq 0
|
28
26
|
end
|
29
27
|
|
28
|
+
it "truncates the table without id sequence" do
|
29
|
+
2.times { Agent.create }
|
30
|
+
|
31
|
+
connection.truncate_table('agents')
|
32
|
+
Agent.count.should eq 0
|
33
|
+
end
|
34
|
+
|
30
35
|
it "resets AUTO_INCREMENT index of table" do
|
31
36
|
2.times { User.create }
|
32
37
|
User.delete_all
|
@@ -37,12 +42,16 @@ module ActiveRecord
|
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
45
|
+
describe '#database_cleaner_table_cache' do
|
46
|
+
it 'should default to the list of tables with their schema' do
|
47
|
+
connection.database_cleaner_table_cache.first.should match(/^public\./)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
40
51
|
it_behaves_like "an adapter with pre-count truncation" do
|
41
|
-
let(:adapter) { PostgreSQLAdapter }
|
42
52
|
let(:connection) { active_record_pg_connection }
|
43
53
|
end
|
44
54
|
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
48
|
-
|
@@ -4,6 +4,7 @@ require 'database_cleaner/data_mapper/transaction'
|
|
4
4
|
require 'database_cleaner/mongo_mapper/truncation'
|
5
5
|
require 'database_cleaner/mongoid/truncation'
|
6
6
|
require 'database_cleaner/couch_potato/truncation'
|
7
|
+
require 'database_cleaner/neo4j/transaction'
|
7
8
|
|
8
9
|
module DatabaseCleaner
|
9
10
|
describe Base do
|
@@ -21,6 +22,7 @@ module DatabaseCleaner
|
|
21
22
|
Temp_MP = ::Moped if defined?(::Moped) and not defined?(Temp_MP)
|
22
23
|
Temp_RS = ::Redis if defined?(::Redis) and not defined?(Temp_RS)
|
23
24
|
Temp_OH = ::Ohm if defined?(::Ohm) and not defined?(Temp_OH)
|
25
|
+
Temp_NJ = ::Neo4j if defined?(::Neo4j) and not defined?(Temp_NJ)
|
24
26
|
end
|
25
27
|
|
26
28
|
#Remove all ORM mocks and restore from cache
|
@@ -34,6 +36,7 @@ module DatabaseCleaner
|
|
34
36
|
Object.send(:remove_const, 'Moped') if defined?(::Moped)
|
35
37
|
Object.send(:remove_const, 'Ohm') if defined?(::Ohm)
|
36
38
|
Object.send(:remove_const, 'Redis') if defined?(::Redis)
|
39
|
+
Object.send(:remove_const, 'Neo4j') if defined?(::Neo4j)
|
37
40
|
|
38
41
|
|
39
42
|
# Restore ORMs
|
@@ -46,6 +49,7 @@ module DatabaseCleaner
|
|
46
49
|
::Moped = Temp_MP if defined? Temp_MP
|
47
50
|
::Ohm = Temp_OH if defined? Temp_OH
|
48
51
|
::Redis = Temp_RS if defined? Temp_RS
|
52
|
+
::Neo4j = Temp_NJ if defined? Temp_NJ
|
49
53
|
end
|
50
54
|
|
51
55
|
#reset the orm mocks
|
@@ -59,6 +63,7 @@ module DatabaseCleaner
|
|
59
63
|
Object.send(:remove_const, 'Moped') if defined?(::Moped)
|
60
64
|
Object.send(:remove_const, 'Ohm') if defined?(::Ohm)
|
61
65
|
Object.send(:remove_const, 'Redis') if defined?(::Redis)
|
66
|
+
Object.send(:remove_const, 'Neo4j') if defined?(::Neo4j)
|
62
67
|
end
|
63
68
|
|
64
69
|
let(:cleaner) { DatabaseCleaner::Base.new :autodetect }
|
@@ -77,6 +82,7 @@ module DatabaseCleaner
|
|
77
82
|
Object.const_set('Moped', 'Moped mock')
|
78
83
|
Object.const_set('Ohm', 'Ohm mock')
|
79
84
|
Object.const_set('Redis', 'Redis mock')
|
85
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
80
86
|
|
81
87
|
cleaner.orm.should eq :active_record
|
82
88
|
cleaner.should be_auto_detected
|
@@ -91,6 +97,7 @@ module DatabaseCleaner
|
|
91
97
|
Object.const_set('Moped', 'Moped mock')
|
92
98
|
Object.const_set('Ohm', 'Ohm mock')
|
93
99
|
Object.const_set('Redis', 'Redis mock')
|
100
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
94
101
|
|
95
102
|
cleaner.orm.should eq :data_mapper
|
96
103
|
cleaner.should be_auto_detected
|
@@ -104,6 +111,7 @@ module DatabaseCleaner
|
|
104
111
|
Object.const_set('Moped', 'Moped mock')
|
105
112
|
Object.const_set('Ohm', 'Ohm mock')
|
106
113
|
Object.const_set('Redis', 'Redis mock')
|
114
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
107
115
|
|
108
116
|
cleaner.orm.should eq :mongo_mapper
|
109
117
|
cleaner.should be_auto_detected
|
@@ -116,6 +124,7 @@ module DatabaseCleaner
|
|
116
124
|
Object.const_set('Moped', 'Moped mock')
|
117
125
|
Object.const_set('Ohm', 'Ohm mock')
|
118
126
|
Object.const_set('Redis', 'Redis mock')
|
127
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
119
128
|
|
120
129
|
cleaner.orm.should eq :mongoid
|
121
130
|
cleaner.should be_auto_detected
|
@@ -127,6 +136,7 @@ module DatabaseCleaner
|
|
127
136
|
Object.const_set('Moped', 'Moped mock')
|
128
137
|
Object.const_set('Ohm', 'Ohm mock')
|
129
138
|
Object.const_set('Redis', 'Redis mock')
|
139
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
130
140
|
|
131
141
|
cleaner.orm.should eq :couch_potato
|
132
142
|
cleaner.should be_auto_detected
|
@@ -137,30 +147,40 @@ module DatabaseCleaner
|
|
137
147
|
Object.const_set('Moped', 'Moped mock')
|
138
148
|
Object.const_set('Ohm', 'Ohm mock')
|
139
149
|
Object.const_set('Redis', 'Redis mock')
|
150
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
140
151
|
|
141
152
|
cleaner.orm.should eq :sequel
|
142
153
|
cleaner.should be_auto_detected
|
143
154
|
end
|
144
155
|
|
145
|
-
it 'detects
|
146
|
-
Object.const_set('
|
147
|
-
|
156
|
+
it 'detects Moped seventh' do
|
157
|
+
Object.const_set('Moped', 'Moped mock')
|
158
|
+
|
159
|
+
cleaner.orm.should eq :moped
|
160
|
+
cleaner.should be_auto_detected
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'detects Ohm eighth' do
|
164
|
+
Object.const_set('Ohm', 'Ohm mock')
|
165
|
+
Object.const_set('Redis', 'Redis mock')
|
166
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
148
167
|
|
149
168
|
cleaner.orm.should eq :ohm
|
150
169
|
cleaner.should be_auto_detected
|
151
170
|
end
|
152
171
|
|
153
|
-
it 'detects Redis
|
154
|
-
Object.const_set('Redis',
|
172
|
+
it 'detects Redis ninth' do
|
173
|
+
Object.const_set('Redis', 'Redis mock')
|
174
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
155
175
|
|
156
176
|
cleaner.orm.should eq :redis
|
157
177
|
cleaner.should be_auto_detected
|
158
178
|
end
|
159
179
|
|
160
|
-
it 'detects
|
161
|
-
Object.const_set('
|
180
|
+
it 'detects Neo4j tenth' do
|
181
|
+
Object.const_set('Neo4j', 'Neo4j mock')
|
162
182
|
|
163
|
-
cleaner.orm.should eq :
|
183
|
+
cleaner.orm.should eq :neo4j
|
164
184
|
cleaner.should be_auto_detected
|
165
185
|
end
|
166
186
|
end
|
@@ -181,7 +201,8 @@ module DatabaseCleaner
|
|
181
201
|
|
182
202
|
describe "comparison" do
|
183
203
|
it "should be equal if orm, connection and strategy are the same" do
|
184
|
-
strategy =
|
204
|
+
strategy = mock("strategy")
|
205
|
+
strategy.stub!(:to_ary => [strategy])
|
185
206
|
|
186
207
|
one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
187
208
|
one.strategy = strategy
|
@@ -248,7 +269,11 @@ module DatabaseCleaner
|
|
248
269
|
end
|
249
270
|
|
250
271
|
describe "strategy_db=" do
|
251
|
-
let(:strategy) {
|
272
|
+
let(:strategy) {
|
273
|
+
mock("strategy").tap{|strategy|
|
274
|
+
strategy.stub!(:to_ary => [strategy])
|
275
|
+
}
|
276
|
+
}
|
252
277
|
|
253
278
|
before(:each) do
|
254
279
|
subject.strategy = strategy
|
@@ -348,7 +373,11 @@ module DatabaseCleaner
|
|
348
373
|
end
|
349
374
|
|
350
375
|
describe "strategy=" do
|
351
|
-
let(:mock_strategy) {
|
376
|
+
let(:mock_strategy) {
|
377
|
+
mock("strategy").tap{|strategy|
|
378
|
+
strategy.stub!(:to_ary => [strategy])
|
379
|
+
}
|
380
|
+
}
|
352
381
|
|
353
382
|
it "should proxy symbolised strategies to create_strategy" do
|
354
383
|
subject.should_receive(:create_strategy).with(:symbol)
|
@@ -388,7 +417,9 @@ module DatabaseCleaner
|
|
388
417
|
end
|
389
418
|
|
390
419
|
it "returns the set strategy" do
|
391
|
-
strategum =
|
420
|
+
strategum = mock("strategy").tap{|strategy|
|
421
|
+
strategy.stub!(:to_ary => [strategy])
|
422
|
+
}
|
392
423
|
subject.strategy = strategum
|
393
424
|
subject.strategy.should eq strategum
|
394
425
|
end
|
@@ -562,6 +593,11 @@ module DatabaseCleaner
|
|
562
593
|
cleaner = DatabaseCleaner::Base.new(:redis)
|
563
594
|
cleaner.strategy.should be_instance_of DatabaseCleaner::Redis::Truncation
|
564
595
|
end
|
596
|
+
|
597
|
+
it 'sets strategy to :transaction for Neo4j' do
|
598
|
+
cleaner = DatabaseCleaner::Base.new(:neo4j)
|
599
|
+
cleaner.strategy.should be_instance_of DatabaseCleaner::Neo4j::Transaction
|
600
|
+
end
|
565
601
|
end
|
566
602
|
|
567
603
|
end
|