database_cleaner 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/History.rdoc +19 -8
- data/VERSION.yml +1 -1
- data/examples/Gemfile +1 -1
- data/examples/Gemfile.lock +2 -2
- data/features/support/env.rb +0 -3
- data/lib/database_cleaner/active_record/base.rb +10 -1
- data/lib/database_cleaner/active_record/transaction.rb +1 -1
- data/lib/database_cleaner/active_record/truncation.rb +14 -4
- data/lib/database_cleaner/mongo/base.rb +0 -2
- data/lib/database_cleaner/mongo/truncation.rb +1 -1
- data/lib/database_cleaner/mongoid/truncation.rb +0 -1
- data/spec/database_cleaner/active_record/base_spec.rb +28 -0
- data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +18 -0
- data/spec/database_cleaner/sequel/deletion_spec.rb +2 -2
- data/spec/support/active_record/mysql2_setup.rb +5 -5
- data/spec/support/active_record/mysql_setup.rb +5 -5
- data/spec/support/active_record/postgresql_setup.rb +13 -6
- data/spec/support/active_record/sqlite3_setup.rb +5 -5
- data/spec/support/data_mapper/sqlite3_setup.rb +5 -5
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35bb176b3479b670a9d789e0b6115590fe84aeee
|
4
|
+
data.tar.gz: 30b5dbd03d0b8ac5249712fbe2b1e9ec44809f99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e70863bb6c44d9fea1364be4d5308a7221c1b2babd6bc4d4fbbc5515eaee929d54b5bf655d8816ad7f1085f34136dcf7d471437c6c2ed535985e3fe421c3f63
|
7
|
+
data.tar.gz: b93b8e8de63d8d5c7602b6e7ab219ebb4bfa9cfc9013e30f723879538aa1d0ef1943ca1652892836de8cd633a689af083ab639b24dc8370036e360ced9608cfb
|
data/Gemfile.lock
CHANGED
@@ -162,7 +162,7 @@ GEM
|
|
162
162
|
multi_json (1.2.0)
|
163
163
|
multi_xml (0.5.5)
|
164
164
|
multipart-post (2.0.0)
|
165
|
-
mysql (2.
|
165
|
+
mysql (2.9.1)
|
166
166
|
mysql2 (0.3.16)
|
167
167
|
neo4j-community (2.1.5)
|
168
168
|
neo4j-core (3.0.8)
|
@@ -279,7 +279,7 @@ DEPENDENCIES
|
|
279
279
|
mongoid
|
280
280
|
mongoid-tree
|
281
281
|
moped
|
282
|
-
mysql (~> 2.
|
282
|
+
mysql (~> 2.9.1)
|
283
283
|
mysql2
|
284
284
|
neo4j-core
|
285
285
|
ohm (~> 0.1.3)
|
data/History.rdoc
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
== Development (master)
|
2
2
|
|
3
|
+
== 1.4.1 2015-03-09
|
4
|
+
* Support for deletion with Sequel. (@cyberdelia)
|
5
|
+
* Use ActiveRecord::Base configuration when different from config file. (@wendy0402)
|
6
|
+
* Removed dependency of Mongo. (@codegourmet)
|
7
|
+
* Fixed issue with tables schema prefix in Postgres. (@phoenixek12)
|
8
|
+
* Use ruby 1.8 syntax. (@daniel-g)
|
9
|
+
* Added license to gemspec. (@chrismar035)
|
10
|
+
* Improved coverage for migrations table. (@jonallured)
|
11
|
+
|
12
|
+
== 1.4.0 2014-12-17
|
13
|
+
|
3
14
|
=== New Features/Changes
|
4
|
-
*
|
5
|
-
|
6
|
-
|
7
|
-
|
15
|
+
* Support for Neo4j. (@dpisarewski)
|
16
|
+
* Support for multiple connections on Mongoid. (@nyarly)
|
17
|
+
|
18
|
+
=== Better Performance
|
19
|
+
* Using the deletion strategy with Mysql now only deletes those tables which have had records added to them. (@MadRabbit)
|
20
|
+
* Add support for pre_count on Sequel with Mysql. (@vrinek)
|
8
21
|
* Cache collection names in mongo's truncation strategy. (@nyarly)
|
9
|
-
* Support for mongoid multiple connections. (@nyarly)
|
10
|
-
* Support for deletion with Sequel. (@cyberdelia)
|
11
22
|
|
12
23
|
=== Bug Fixes
|
13
|
-
* Fix
|
24
|
+
* Fix undefined method error with DataMapper SQLite adaptor. (@lanej)
|
14
25
|
* Fully define Mysql2 adaptor constant. (@jgonera)
|
15
26
|
* Don't truncate schema tables in Postgres. (@billywatson)
|
16
|
-
* Fix issue
|
27
|
+
* Fix issue where Moped cleaner was missing collections with 'system' in their name. (@MartinNowak)
|
17
28
|
|
18
29
|
== 1.3.0 2014-05-23
|
19
30
|
|
data/VERSION.yml
CHANGED
data/examples/Gemfile
CHANGED
@@ -28,7 +28,7 @@ group :development, :test do
|
|
28
28
|
|
29
29
|
gem "sequel", "~> 3.21.0"
|
30
30
|
#gem "ibm_db" # I don't want to add this dependency, even as a dev one since it requires DB2 to be installed
|
31
|
-
gem 'mysql', '~> 2.
|
31
|
+
gem 'mysql', '~> 2.9.1'
|
32
32
|
gem 'mysql2'
|
33
33
|
gem 'pg'
|
34
34
|
gem 'ohm', '~> 0.1.3'
|
data/examples/Gemfile.lock
CHANGED
@@ -162,7 +162,7 @@ GEM
|
|
162
162
|
multi_json (1.2.0)
|
163
163
|
multi_xml (0.5.5)
|
164
164
|
multipart-post (2.0.0)
|
165
|
-
mysql (2.
|
165
|
+
mysql (2.9.1)
|
166
166
|
mysql2 (0.3.16)
|
167
167
|
neo4j-community (2.1.5)
|
168
168
|
neo4j-core (3.0.8)
|
@@ -279,7 +279,7 @@ DEPENDENCIES
|
|
279
279
|
mongoid
|
280
280
|
mongoid-tree
|
281
281
|
moped
|
282
|
-
mysql (~> 2.
|
282
|
+
mysql (~> 2.9.1)
|
283
283
|
mysql2
|
284
284
|
neo4j-core
|
285
285
|
ohm (~> 0.1.3)
|
data/features/support/env.rb
CHANGED
@@ -34,10 +34,19 @@ module DatabaseCleaner
|
|
34
34
|
def load_config
|
35
35
|
if self.db != :default && self.db.is_a?(Symbol) && File.file?(ActiveRecord.config_file_location)
|
36
36
|
connection_details = YAML::load(ERB.new(IO.read(ActiveRecord.config_file_location)).result)
|
37
|
-
@connection_hash = connection_details[self.db.to_s]
|
37
|
+
@connection_hash = valid_config(connection_details)[self.db.to_s]
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def valid_config(connection_file)
|
42
|
+
if !::ActiveRecord::Base.configurations.nil? && !::ActiveRecord::Base.configurations.empty?
|
43
|
+
if connection_file != ::ActiveRecord::Base.configurations
|
44
|
+
return ::ActiveRecord::Base.configurations
|
45
|
+
end
|
46
|
+
end
|
47
|
+
connection_file
|
48
|
+
end
|
49
|
+
|
41
50
|
def connection_class
|
42
51
|
@connection_class ||= if db && !db.is_a?(Symbol)
|
43
52
|
db
|
@@ -19,7 +19,7 @@ module DatabaseCleaner::ActiveRecord
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
if connection_class.connection.respond_to?(:begin_transaction)
|
22
|
-
connection_class.connection.begin_transaction joinable
|
22
|
+
connection_class.connection.begin_transaction :joinable => false
|
23
23
|
else
|
24
24
|
connection_class.connection.begin_db_transaction
|
25
25
|
end
|
@@ -24,7 +24,7 @@ module DatabaseCleaner
|
|
24
24
|
def database_cleaner_view_cache
|
25
25
|
@views ||= select_values("select table_name from information_schema.views where table_schema = '#{current_database}'") rescue []
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def database_cleaner_table_cache
|
29
29
|
# the adapters don't do caching (#130) but we make the assumption that the list stays the same in tests
|
30
30
|
@database_cleaner_tables ||= tables
|
@@ -177,7 +177,7 @@ module DatabaseCleaner
|
|
177
177
|
cur_val = select_value("SELECT currval('#{table}_id_seq');").to_i rescue 0
|
178
178
|
cur_val > 0
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
def has_sequence?(table)
|
182
182
|
select_value("SELECT true FROM pg_class WHERE relname = '#{table}_id_seq';")
|
183
183
|
end
|
@@ -190,7 +190,10 @@ module DatabaseCleaner
|
|
190
190
|
rows = select_rows <<-_SQL
|
191
191
|
SELECT schemaname || '.' || tablename
|
192
192
|
FROM pg_tables
|
193
|
-
WHERE
|
193
|
+
WHERE
|
194
|
+
tablename !~ '_prt_' AND
|
195
|
+
tablename <> '#{::ActiveRecord::Migrator.schema_migrations_table_name}' AND
|
196
|
+
schemaname = ANY (current_schemas(false))
|
194
197
|
_SQL
|
195
198
|
rows.collect { |result| result.first }
|
196
199
|
end
|
@@ -242,7 +245,14 @@ module DatabaseCleaner::ActiveRecord
|
|
242
245
|
|
243
246
|
def tables_to_truncate(connection)
|
244
247
|
tables_in_db = cache_tables? ? connection.database_cleaner_table_cache : connection.tables
|
245
|
-
|
248
|
+
to_reject = (@tables_to_exclude + connection.database_cleaner_view_cache)
|
249
|
+
(@only || tables_in_db).reject do |table|
|
250
|
+
if ( m = table.match(/([^.]+)$/) )
|
251
|
+
to_reject.include?(m[1])
|
252
|
+
else
|
253
|
+
false
|
254
|
+
end
|
255
|
+
end
|
246
256
|
end
|
247
257
|
|
248
258
|
# overwritten
|
@@ -20,7 +20,7 @@ module DatabaseCleaner
|
|
20
20
|
def mongoid_collection_names
|
21
21
|
@@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
|
22
22
|
ObjectSpace.each_object(Class) do |klass|
|
23
|
-
next unless klass.ancestors.include?(
|
23
|
+
next unless klass.ancestors.map(&:to_s).include?('Mongoid::Document')
|
24
24
|
next if klass.embedded
|
25
25
|
next if klass.collection_name.empty?
|
26
26
|
names[klass.db.name] << klass.collection_name
|
@@ -2,7 +2,6 @@ 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'
|
6
5
|
require 'mongoid/version'
|
7
6
|
|
8
7
|
module DatabaseCleaner
|
@@ -84,6 +84,34 @@ my_db:
|
|
84
84
|
subject.load_config
|
85
85
|
end
|
86
86
|
|
87
|
+
context 'use ActiveRecord::Base.configuration' do
|
88
|
+
it 'when config file different with it' do
|
89
|
+
::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "two"} })
|
90
|
+
subject.load_config
|
91
|
+
subject.connection_hash.should eq({ "database" => "two"})
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'use config file' do
|
96
|
+
it 'when config file same with it' do
|
97
|
+
::ActiveRecord::Base.stub(:configurations).and_return({ "my_db" =>{ "database" => "one"} })
|
98
|
+
subject.load_config
|
99
|
+
subject.connection_hash.should eq({ "database" => "one"})
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'when ::ActiveRecord::Base.configurations nil' do
|
103
|
+
::ActiveRecord::Base.stub(:configurations).and_return(nil)
|
104
|
+
subject.load_config
|
105
|
+
subject.connection_hash.should eq({ "database" => "one"})
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'when ::ActiveRecord::Base.configurations empty' do
|
109
|
+
::ActiveRecord::Base.stub(:configurations).and_return({})
|
110
|
+
subject.load_config
|
111
|
+
subject.connection_hash.should eq({ "database" => "one"})
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
87
115
|
it "should store the relevant config in connection_hash" do
|
88
116
|
subject.load_config
|
89
117
|
subject.connection_hash.should eq( "database" => "one" )
|
@@ -6,6 +6,15 @@ require 'database_cleaner/active_record/truncation/shared_fast_truncation'
|
|
6
6
|
|
7
7
|
module ActiveRecord
|
8
8
|
module ConnectionAdapters
|
9
|
+
describe "schema_migrations table" do
|
10
|
+
it "is not truncated" do
|
11
|
+
active_record_pg_migrate
|
12
|
+
DatabaseCleaner::ActiveRecord::Truncation.new.clean
|
13
|
+
result = active_record_pg_connection.execute("select count(*) from schema_migrations;")
|
14
|
+
result.values.first.should eq ["2"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
9
18
|
describe do
|
10
19
|
before(:all) { active_record_pg_setup }
|
11
20
|
|
@@ -42,6 +51,15 @@ module ActiveRecord
|
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
54
|
+
describe ":except option cleanup" do
|
55
|
+
it "should not truncate the tables specified in the :except option" do
|
56
|
+
2.times { User.create }
|
57
|
+
|
58
|
+
::DatabaseCleaner::ActiveRecord::Truncation.new(:except => ['users']).clean
|
59
|
+
expect( User.count ).to eq 2
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
45
63
|
describe '#database_cleaner_table_cache' do
|
46
64
|
it 'should default to the list of tables with their schema' do
|
47
65
|
connection.database_cleaner_table_cache.first.should match(/^public\./)
|
@@ -43,8 +43,8 @@ module DatabaseCleaner
|
|
43
43
|
end
|
44
44
|
|
45
45
|
supported_configurations = [
|
46
|
-
{ url
|
47
|
-
{ url
|
46
|
+
{ :url => 'mysql:///', :connection_options => db_config['mysql'] },
|
47
|
+
{ :url => 'postgres:///', :connection_options => db_config['postgres'] }
|
48
48
|
]
|
49
49
|
|
50
50
|
supported_configurations.each do |config|
|
@@ -8,18 +8,18 @@ module MySQL2Helper
|
|
8
8
|
# require 'logger'
|
9
9
|
# ActiveRecord::Base.logger = Logger.new(STDERR)
|
10
10
|
|
11
|
-
def
|
11
|
+
def default_config
|
12
12
|
db_config['mysql2']
|
13
13
|
end
|
14
14
|
|
15
15
|
def create_db
|
16
|
-
establish_connection(
|
16
|
+
establish_connection(default_config.merge(:database => nil))
|
17
17
|
|
18
|
-
ActiveRecord::Base.connection.drop_database
|
19
|
-
ActiveRecord::Base.connection.create_database
|
18
|
+
ActiveRecord::Base.connection.drop_database default_config['database'] rescue nil
|
19
|
+
ActiveRecord::Base.connection.create_database default_config['database']
|
20
20
|
end
|
21
21
|
|
22
|
-
def establish_connection
|
22
|
+
def establish_connection(config = default_config)
|
23
23
|
ActiveRecord::Base.establish_connection config
|
24
24
|
end
|
25
25
|
|
@@ -7,18 +7,18 @@ module MySQLHelper
|
|
7
7
|
# require 'logger'
|
8
8
|
# ActiveRecord::Base.logger = Logger.new(STDERR)
|
9
9
|
|
10
|
-
def
|
10
|
+
def default_config
|
11
11
|
db_config['mysql']
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_db
|
15
|
-
establish_connection(
|
15
|
+
establish_connection(default_config.merge(:database => nil))
|
16
16
|
|
17
|
-
ActiveRecord::Base.connection.drop_database
|
18
|
-
ActiveRecord::Base.connection.create_database
|
17
|
+
ActiveRecord::Base.connection.drop_database default_config['database'] rescue nil
|
18
|
+
ActiveRecord::Base.connection.create_database default_config['database']
|
19
19
|
end
|
20
20
|
|
21
|
-
def establish_connection
|
21
|
+
def establish_connection(config = default_config)
|
22
22
|
ActiveRecord::Base.establish_connection config
|
23
23
|
end
|
24
24
|
|
@@ -6,22 +6,22 @@ module PostgreSQLHelper
|
|
6
6
|
|
7
7
|
# ActiveRecord::Base.logger = Logger.new(STDERR)
|
8
8
|
|
9
|
-
def
|
9
|
+
def default_config
|
10
10
|
db_config['postgres']
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_db
|
14
|
-
@encoding =
|
14
|
+
@encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
|
15
15
|
begin
|
16
|
-
establish_connection(
|
17
|
-
ActiveRecord::Base.connection.create_database(
|
16
|
+
establish_connection(default_config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
17
|
+
ActiveRecord::Base.connection.create_database(default_config['database'], default_config.merge('encoding' => @encoding))
|
18
18
|
rescue Exception => e
|
19
19
|
$stderr.puts e, *(e.backtrace)
|
20
|
-
$stderr.puts "Couldn't create database for #{
|
20
|
+
$stderr.puts "Couldn't create database for #{default_config.inspect}"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def establish_connection
|
24
|
+
def establish_connection(config = default_config)
|
25
25
|
ActiveRecord::Base.establish_connection(config)
|
26
26
|
end
|
27
27
|
|
@@ -31,6 +31,13 @@ module PostgreSQLHelper
|
|
31
31
|
active_record_load_schema
|
32
32
|
end
|
33
33
|
|
34
|
+
def active_record_pg_migrate
|
35
|
+
`dropdb #{default_config['database']}`
|
36
|
+
create_db
|
37
|
+
establish_connection
|
38
|
+
ActiveRecord::Migrator.migrate 'spec/support/active_record/migrations'
|
39
|
+
end
|
40
|
+
|
34
41
|
def active_record_pg_connection
|
35
42
|
ActiveRecord::Base.connection
|
36
43
|
end
|
@@ -6,21 +6,21 @@ module SQLite3Helper
|
|
6
6
|
|
7
7
|
# ActiveRecord::Base.logger = Logger.new(STDERR)
|
8
8
|
|
9
|
-
def
|
9
|
+
def default_config
|
10
10
|
db_config['sqlite3']
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_db
|
14
|
-
@encoding =
|
14
|
+
@encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
|
15
15
|
begin
|
16
|
-
establish_connection(
|
16
|
+
establish_connection(default_config.merge('database' => 'sqlite3', 'schema_search_path' => 'public'))
|
17
17
|
rescue Exception => e
|
18
18
|
$stderr.puts e, *(e.backtrace)
|
19
|
-
$stderr.puts "Couldn't create database for #{
|
19
|
+
$stderr.puts "Couldn't create database for #{default_config.inspect}"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def establish_connection
|
23
|
+
def establish_connection(config = default_config)
|
24
24
|
ActiveRecord::Base.establish_connection(config)
|
25
25
|
end
|
26
26
|
|
@@ -5,21 +5,21 @@ module DataMapperSQLite3Helper
|
|
5
5
|
|
6
6
|
puts "DataMapper #{DataMapper::VERSION}, sqlite3"
|
7
7
|
|
8
|
-
def
|
8
|
+
def default_config
|
9
9
|
db_config['sqlite3']
|
10
10
|
end
|
11
11
|
|
12
12
|
def create_db
|
13
|
-
@encoding =
|
13
|
+
@encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
|
14
14
|
begin
|
15
|
-
establish_connection(
|
15
|
+
establish_connection(default_config.merge('database' => 'sqlite3', 'schema_search_path' => 'public'))
|
16
16
|
rescue Exception => e
|
17
17
|
$stderr.puts e, *(e.backtrace)
|
18
|
-
$stderr.puts "Couldn't create database for #{
|
18
|
+
$stderr.puts "Couldn't create database for #{default_config.inspect}"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def establish_connection(config =
|
22
|
+
def establish_connection(config = default_config)
|
23
23
|
DataMapper.setup(:default, config)
|
24
24
|
end
|
25
25
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Mabey
|
@@ -360,7 +360,7 @@ dependencies:
|
|
360
360
|
- - ">="
|
361
361
|
- !ruby/object:Gem::Version
|
362
362
|
version: '0'
|
363
|
-
description: Strategies for cleaning databases.
|
363
|
+
description: Strategies for cleaning databases. Can be used to ensure a clean state
|
364
364
|
for testing.
|
365
365
|
email: ben@benmabey.com
|
366
366
|
executables: []
|
@@ -496,8 +496,9 @@ files:
|
|
496
496
|
- spec/support/active_record/sqlite3_setup.rb
|
497
497
|
- spec/support/data_mapper/schema_setup.rb
|
498
498
|
- spec/support/data_mapper/sqlite3_setup.rb
|
499
|
-
homepage: http://github.com/
|
500
|
-
licenses:
|
499
|
+
homepage: http://github.com/DatabaseCleaner/database_cleaner
|
500
|
+
licenses:
|
501
|
+
- MIT
|
501
502
|
metadata: {}
|
502
503
|
post_install_message:
|
503
504
|
rdoc_options: []
|