database_cleaner 1.99.0.beta → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_cleaner.rb +1 -47
- metadata +11 -481
- data/CONTRIBUTE.markdown +0 -27
- data/Gemfile.lock +0 -324
- data/History.rdoc +0 -514
- data/LICENSE +0 -20
- data/README.markdown +0 -389
- data/Rakefile +0 -44
- data/TODO +0 -3
- data/adapters/database_cleaner-active_record/lib/database_cleaner-active_record.rb +0 -1
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record.rb +0 -6
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/base.rb +0 -101
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/deletion.rb +0 -108
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/transaction.rb +0 -59
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb +0 -288
- data/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/version.rb +0 -5
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb +0 -1
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb +0 -13
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/base.rb +0 -7
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/truncation.rb +0 -28
- data/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb +0 -5
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb +0 -1
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb +0 -6
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/base.rb +0 -25
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/transaction.rb +0 -28
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/truncation.rb +0 -173
- data/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb +0 -5
- data/adapters/database_cleaner-mongo/lib/database_cleaner-mongo.rb +0 -1
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo.rb +0 -11
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/base.rb +0 -16
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/deletion.rb +0 -8
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation.rb +0 -74
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
- data/adapters/database_cleaner-mongo/lib/database_cleaner/mongo/version.rb +0 -5
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner-mongo_mapper.rb +0 -1
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper.rb +0 -5
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/base.rb +0 -24
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/truncation.rb +0 -35
- data/adapters/database_cleaner-mongo_mapper/lib/database_cleaner/mongo_mapper/version.rb +0 -5
- data/adapters/database_cleaner-mongoid/lib/database_cleaner-mongoid.rb +0 -1
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid.rb +0 -11
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/base.rb +0 -20
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/deletion.rb +0 -10
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo1_truncation_mixin.rb +0 -26
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongo2_truncation_mixin.rb +0 -38
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/mongoid_truncation_mixin.rb +0 -65
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/truncation.rb +0 -49
- data/adapters/database_cleaner-mongoid/lib/database_cleaner/mongoid/version.rb +0 -5
- data/adapters/database_cleaner-moped/lib/database_cleaner-moped.rb +0 -1
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped.rb +0 -12
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/base.rb +0 -39
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation.rb +0 -9
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/truncation_base.rb +0 -44
- data/adapters/database_cleaner-moped/lib/database_cleaner/moped/version.rb +0 -5
- data/adapters/database_cleaner-neo4j/lib/database_cleaner-neo4j.rb +0 -1
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j.rb +0 -7
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/base.rb +0 -66
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/deletion.rb +0 -16
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/transaction.rb +0 -35
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/truncation.rb +0 -9
- data/adapters/database_cleaner-neo4j/lib/database_cleaner/neo4j/version.rb +0 -5
- data/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb +0 -1
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb +0 -12
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb +0 -24
- data/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb +0 -5
- data/adapters/database_cleaner-redis/lib/database_cleaner-redis.rb +0 -1
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis.rb +0 -5
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/base.rb +0 -45
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/deletion.rb +0 -9
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/truncation.rb +0 -26
- data/adapters/database_cleaner-redis/lib/database_cleaner/redis/version.rb +0 -5
- data/adapters/database_cleaner-sequel/lib/database_cleaner-sequel.rb +0 -1
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel.rb +0 -6
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/base.rb +0 -26
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/deletion.rb +0 -47
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb +0 -40
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/truncation.rb +0 -79
- data/adapters/database_cleaner-sequel/lib/database_cleaner/sequel/version.rb +0 -5
- data/cucumber.yml +0 -1
- data/lib/database_cleaner/base.rb +0 -169
- data/lib/database_cleaner/configuration.rb +0 -136
- data/lib/database_cleaner/cucumber.rb +0 -3
- data/lib/database_cleaner/deprecation.rb +0 -26
- data/lib/database_cleaner/generic/base.rb +0 -29
- data/lib/database_cleaner/generic/transaction.rb +0 -11
- data/lib/database_cleaner/generic/truncation.rb +0 -40
- data/lib/database_cleaner/null_strategy.rb +0 -20
- data/lib/database_cleaner/orm_autodetector.rb +0 -41
- data/lib/database_cleaner/safeguard.rb +0 -107
- data/lib/database_cleaner/spec.rb +0 -2
- data/lib/database_cleaner/spec/database_helper.rb +0 -82
- data/lib/database_cleaner/spec/shared_examples.rb +0 -15
- data/lib/database_cleaner/version.rb +0 -3
@@ -1,41 +0,0 @@
|
|
1
|
-
module DatabaseCleaner
|
2
|
-
class ORMAutodetector
|
3
|
-
ORMS = {
|
4
|
-
active_record: "ActiveRecord",
|
5
|
-
data_mapper: "DataMapper",
|
6
|
-
mongo_mapper: "MongoMapper",
|
7
|
-
mongoid: "Mongoid",
|
8
|
-
mongo: "Mongo",
|
9
|
-
couch_potato: "CouchPotato",
|
10
|
-
sequel: "Sequel",
|
11
|
-
moped: "Moped",
|
12
|
-
ohm: "Ohm",
|
13
|
-
redis: "Redis",
|
14
|
-
neo4j: "Neo4j",
|
15
|
-
}
|
16
|
-
|
17
|
-
def orm
|
18
|
-
@autodetected = true
|
19
|
-
autodetected_orm or raise no_orm_detected_error
|
20
|
-
ORMS.key(autodetected_orm.to_s)
|
21
|
-
end
|
22
|
-
|
23
|
-
def autodetected?
|
24
|
-
!!@autodetected
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def autodetected_orm
|
30
|
-
ORMS.values.find do |orm|
|
31
|
-
Kernel.const_get(orm) rescue next
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def no_orm_detected_error
|
36
|
-
orm_list = ORMS.values.join(", ").sub(ORMS.values.last, "or #{ORMS.values.last}")
|
37
|
-
NoORMDetected.new("No known ORM was detected! Is #{orm_list} loaded?")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
private_constant :ORMAutodetector
|
41
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module DatabaseCleaner
|
2
|
-
class Safeguard
|
3
|
-
class Error < Exception
|
4
|
-
class RemoteDatabaseUrl < Error
|
5
|
-
def initialize
|
6
|
-
super("ENV['DATABASE_URL'] is set to a remote URL. Please refer to https://github.com/DatabaseCleaner/database_cleaner#safeguards")
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class ProductionEnv < Error
|
11
|
-
def initialize(env)
|
12
|
-
super("ENV['#{env}'] is set to production. Please refer to https://github.com/DatabaseCleaner/database_cleaner#safeguards")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class NotWhitelistedUrl < Error
|
17
|
-
def initialize
|
18
|
-
super("ENV['DATABASE_URL'] is set to a URL that is not on the whitelist. Please refer to https://github.com/DatabaseCleaner/database_cleaner#safeguards")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class WhitelistedUrl
|
24
|
-
def run
|
25
|
-
return if skip?
|
26
|
-
raise Error::NotWhitelistedUrl if database_url_not_whitelisted?
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def database_url_not_whitelisted?
|
32
|
-
!DatabaseCleaner.url_whitelist.include?(ENV['DATABASE_URL'])
|
33
|
-
end
|
34
|
-
|
35
|
-
def skip?
|
36
|
-
!DatabaseCleaner.url_whitelist
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
class RemoteDatabaseUrl
|
42
|
-
LOCAL = %w(localhost 127.0.0.1)
|
43
|
-
|
44
|
-
def run
|
45
|
-
raise Error::RemoteDatabaseUrl if !skip? && given?
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def given?
|
51
|
-
remote?(ENV['DATABASE_URL'])
|
52
|
-
end
|
53
|
-
|
54
|
-
def remote?(url)
|
55
|
-
return false unless url
|
56
|
-
|
57
|
-
parsed = URI.parse(url)
|
58
|
-
return false if parsed.scheme == 'sqlite3:'
|
59
|
-
|
60
|
-
host = parsed.host
|
61
|
-
return false unless host
|
62
|
-
return false if LOCAL.include?(host)
|
63
|
-
return false if host.end_with? '.local'
|
64
|
-
true
|
65
|
-
end
|
66
|
-
|
67
|
-
def skip?
|
68
|
-
ENV['DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL'] ||
|
69
|
-
DatabaseCleaner.allow_remote_database_url ||
|
70
|
-
DatabaseCleaner.url_whitelist
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class Production
|
75
|
-
KEYS = %w(ENV RACK_ENV RAILS_ENV)
|
76
|
-
|
77
|
-
def run
|
78
|
-
raise Error::ProductionEnv.new(key) if !skip? && given?
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
def given?
|
84
|
-
!!key
|
85
|
-
end
|
86
|
-
|
87
|
-
def key
|
88
|
-
@key ||= KEYS.detect { |key| ENV[key] == 'production' }
|
89
|
-
end
|
90
|
-
|
91
|
-
def skip?
|
92
|
-
ENV['DATABASE_CLEANER_ALLOW_PRODUCTION'] ||
|
93
|
-
DatabaseCleaner.allow_production
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
CHECKS = [
|
98
|
-
RemoteDatabaseUrl,
|
99
|
-
Production,
|
100
|
-
WhitelistedUrl
|
101
|
-
]
|
102
|
-
|
103
|
-
def run
|
104
|
-
CHECKS.each { |const| const.new.run }
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module DatabaseCleaner
|
4
|
-
module Spec
|
5
|
-
class DatabaseHelper < Struct.new(:db)
|
6
|
-
def self.with_all_dbs &block
|
7
|
-
%w[mysql mysql2 sqlite3 postgres].map(&:to_sym).each do |db|
|
8
|
-
yield new(db)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def setup
|
13
|
-
create_db
|
14
|
-
establish_connection
|
15
|
-
load_schema
|
16
|
-
end
|
17
|
-
|
18
|
-
attr_reader :connection
|
19
|
-
|
20
|
-
def teardown
|
21
|
-
drop_db
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def establish_connection(config = default_config)
|
27
|
-
raise NotImplementedError
|
28
|
-
end
|
29
|
-
|
30
|
-
def create_db
|
31
|
-
if db == :sqlite3
|
32
|
-
# NO-OP
|
33
|
-
elsif db == :postgres
|
34
|
-
establish_connection default_config.merge('database' => 'postgres')
|
35
|
-
connection.execute "CREATE DATABASE #{default_config['database']}" rescue nil
|
36
|
-
else
|
37
|
-
establish_connection default_config.merge("database" => nil)
|
38
|
-
connection.execute "CREATE DATABASE IF NOT EXISTS #{default_config['database']}"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def load_schema
|
43
|
-
connection.execute <<-SQL
|
44
|
-
CREATE TABLE IF NOT EXISTS users (
|
45
|
-
id SERIAL PRIMARY KEY,
|
46
|
-
name INTEGER
|
47
|
-
);
|
48
|
-
SQL
|
49
|
-
|
50
|
-
connection.execute <<-SQL
|
51
|
-
CREATE TABLE IF NOT EXISTS agents (
|
52
|
-
name INTEGER
|
53
|
-
);
|
54
|
-
SQL
|
55
|
-
end
|
56
|
-
|
57
|
-
def drop_db
|
58
|
-
if db == :sqlite3
|
59
|
-
begin
|
60
|
-
File.unlink(db_config['sqlite3']['database'])
|
61
|
-
rescue Errno::ENOENT
|
62
|
-
end
|
63
|
-
elsif db == :postgres
|
64
|
-
# FIXME
|
65
|
-
connection.execute "DROP TABLE IF EXISTS users"
|
66
|
-
connection.execute "DROP TABLE IF EXISTS agents"
|
67
|
-
else
|
68
|
-
connection.execute "DROP DATABASE IF EXISTS #{default_config['database']}"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def db_config
|
73
|
-
config_path = 'spec/support/config.yml'
|
74
|
-
@db_config ||= YAML.load(IO.read(config_path))
|
75
|
-
end
|
76
|
-
|
77
|
-
def default_config
|
78
|
-
db_config[db.to_s]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
RSpec.shared_examples_for "a generic strategy" do
|
2
|
-
it { is_expected.to respond_to(:db) }
|
3
|
-
end
|
4
|
-
|
5
|
-
RSpec.shared_examples_for "a generic truncation strategy" do
|
6
|
-
it { is_expected.to respond_to(:start) }
|
7
|
-
it { is_expected.to respond_to(:clean) }
|
8
|
-
it { is_expected.to respond_to(:cleaning) }
|
9
|
-
end
|
10
|
-
|
11
|
-
RSpec.shared_examples_for "a generic transaction strategy" do
|
12
|
-
it { is_expected.to respond_to(:start) }
|
13
|
-
it { is_expected.to respond_to(:clean) }
|
14
|
-
it { is_expected.to respond_to(:cleaning) }
|
15
|
-
end
|