database_rewinder 0.9.4 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +111 -0
- data/Gemfile +28 -0
- data/README.md +4 -4
- data/database_rewinder.gemspec +2 -5
- data/lib/database_rewinder/active_record_monkey.rb +57 -15
- data/lib/database_rewinder/cleaner.rb +2 -0
- data/lib/database_rewinder.rb +34 -3
- data/test/config/database.yml +14 -6
- data/test/database_rewinder_test.rb +51 -3
- data/test/fake_app.rb +19 -2
- metadata +8 -58
- data/.travis.yml +0 -64
- data/gemfiles/rails_40.gemfile +0 -9
- data/gemfiles/rails_41.gemfile +0 -9
- data/gemfiles/rails_42.gemfile +0 -9
- data/gemfiles/rails_50.gemfile +0 -7
- data/gemfiles/rails_51.gemfile +0 -8
- data/gemfiles/rails_52.gemfile +0 -6
- data/gemfiles/rails_60.gemfile +0 -6
- data/gemfiles/rails_edge.gemfile +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33fb09096b416644a0a992422fd4bd0b1f8b8957d447f96e6c825f61d0c1246a
|
4
|
+
data.tar.gz: 7f01e681757326b0ef190d046bc9620151b18736036b4529ccafbc57b261f2dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc22e635b796d03d57828b0bfae32ad0c611f1596cf2a945f91408285149b8ab151469ce696c4b359a592861611e7731e5bbad21f95b36b7ff0af074be4a4cee
|
7
|
+
data.tar.gz: b4f10e3069e8141bab9537a85ac48bfadf93b5cc029bfddfe35f9ce0c60c045a131c205a7587ca0e7fae19d1ccbc8912c4bdceeda1ab0bae6011d29572ada129
|
@@ -0,0 +1,111 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
services:
|
8
|
+
postgres:
|
9
|
+
image: postgres:10
|
10
|
+
env:
|
11
|
+
POSTGRES_USER: postgres
|
12
|
+
POSTGRES_PASSWORD: postgres
|
13
|
+
ports:
|
14
|
+
- 5432:5432
|
15
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
16
|
+
mysql:
|
17
|
+
image: mysql:5.7
|
18
|
+
env:
|
19
|
+
MYSQL_ROOT_PASSWORD:
|
20
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
|
21
|
+
ports:
|
22
|
+
- 3306:3306
|
23
|
+
options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10
|
24
|
+
|
25
|
+
strategy:
|
26
|
+
fail-fast: false
|
27
|
+
|
28
|
+
matrix:
|
29
|
+
db: [sqlite3, postgresql, mysql]
|
30
|
+
ruby_version: [ruby-head, '3.0', '2.7', '2.6']
|
31
|
+
rails_version: [edge, '7.0', '6.1', '6.0', '5.2']
|
32
|
+
|
33
|
+
exclude:
|
34
|
+
- ruby_version: '2.6'
|
35
|
+
rails_version: edge
|
36
|
+
|
37
|
+
- ruby_version: '2.6'
|
38
|
+
rails_version: '7.0'
|
39
|
+
|
40
|
+
- ruby_version: ruby-head
|
41
|
+
rails_version: '6.1'
|
42
|
+
|
43
|
+
- ruby_version: ruby-head
|
44
|
+
rails_version: '6.0'
|
45
|
+
- ruby_version: '3.0'
|
46
|
+
rails_version: '6.0'
|
47
|
+
|
48
|
+
- ruby_version: ruby-head
|
49
|
+
rails_version: '5.2'
|
50
|
+
- ruby_version: '3.0'
|
51
|
+
rails_version: '5.2'
|
52
|
+
|
53
|
+
include:
|
54
|
+
- ruby_version: '2.4'
|
55
|
+
rails_version: '5.2'
|
56
|
+
db: sqlite3
|
57
|
+
- ruby_version: '2.4'
|
58
|
+
rails_version: '5.2'
|
59
|
+
db: postgresql
|
60
|
+
- ruby_version: '2.4'
|
61
|
+
rails_version: '5.2'
|
62
|
+
db: mysql
|
63
|
+
|
64
|
+
- ruby_version: '2.6'
|
65
|
+
rails_version: '5.1'
|
66
|
+
db: sqlite3
|
67
|
+
- ruby_version: '2.6'
|
68
|
+
rails_version: '5.1'
|
69
|
+
db: postgresql
|
70
|
+
- ruby_version: '2.6'
|
71
|
+
rails_version: '5.1'
|
72
|
+
db: mysql
|
73
|
+
|
74
|
+
- ruby_version: '2.5'
|
75
|
+
rails_version: '5.0'
|
76
|
+
db: sqlite3
|
77
|
+
- ruby_version: '2.5'
|
78
|
+
rails_version: '5.0'
|
79
|
+
db: postgresql
|
80
|
+
- ruby_version: '2.5'
|
81
|
+
rails_version: '5.0'
|
82
|
+
db: mysql
|
83
|
+
|
84
|
+
- ruby_version: '2.4'
|
85
|
+
rails_version: '4.2'
|
86
|
+
db: sqlite3
|
87
|
+
- ruby_version: '2.4'
|
88
|
+
rails_version: '4.2'
|
89
|
+
db: postgresql
|
90
|
+
- ruby_version: '2.4'
|
91
|
+
rails_version: '4.2'
|
92
|
+
db: mysql
|
93
|
+
|
94
|
+
runs-on: ubuntu-18.04
|
95
|
+
|
96
|
+
env:
|
97
|
+
RAILS_VERSION: ${{ matrix.rails_version }}
|
98
|
+
DB: ${{ matrix.db }}
|
99
|
+
|
100
|
+
steps:
|
101
|
+
- uses: actions/checkout@v2
|
102
|
+
|
103
|
+
- uses: ruby/setup-ruby@v1
|
104
|
+
with:
|
105
|
+
ruby-version: ${{ matrix.ruby_version }}
|
106
|
+
bundler: ${{ startsWith(matrix.rails_version, '4.') && '1' || 'latest' }}
|
107
|
+
bundler-cache: true
|
108
|
+
continue-on-error: ${{ (matrix.ruby_version == 'ruby-head') || (matrix.allow_failures == 'true') }}
|
109
|
+
|
110
|
+
- run: bundle exec rake
|
111
|
+
continue-on-error: ${{ (matrix.ruby_version == 'ruby-head') || (matrix.rails_version == 'edge') || (matrix.allow_failures == 'true') }}
|
data/Gemfile
CHANGED
@@ -4,3 +4,31 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in database_rewinder.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
if ENV['RAILS_VERSION'] == 'edge'
|
9
|
+
gem 'rails', git: 'https://github.com/rails/rails.git'
|
10
|
+
elsif ENV['RAILS_VERSION']
|
11
|
+
gem 'rails', "~> #{ENV['RAILS_VERSION']}.0"
|
12
|
+
else
|
13
|
+
gem 'rails'
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
|
17
|
+
gem 'selenium-webdriver'
|
18
|
+
|
19
|
+
rails_version = ENV['RAILS_VERSION'] || '∞'
|
20
|
+
|
21
|
+
case ENV['DB']
|
22
|
+
when 'postgresql'
|
23
|
+
gem 'pg', rails_version <= '5.2' ? '~> 0.21' : '>= 1'
|
24
|
+
when 'mysql'
|
25
|
+
if rails_version <= '4.1'
|
26
|
+
gem 'mysql2', '~> 0.3.13'
|
27
|
+
elsif rails_version <= '4.2'
|
28
|
+
gem 'mysql2', '~> 0.4.0'
|
29
|
+
else
|
30
|
+
gem 'mysql2'
|
31
|
+
end
|
32
|
+
else
|
33
|
+
gem 'sqlite3', rails_version <= '5.0' ? '< 1.4' : '>= 1.4'
|
34
|
+
end
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# DatabaseRewinder
|
2
2
|
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://github.com/amatsuda/database_rewinder/actions/workflows/main.yml/badge.svg)](https://github.com/amatsuda/database_rewinder/actions)
|
4
4
|
|
5
5
|
database\_rewinder is a minimalist's tiny and ultra-fast database cleaner.
|
6
6
|
|
@@ -23,9 +23,9 @@ This strategy was originally devised and implemented by Shingo Morita (@eudoxa)
|
|
23
23
|
|
24
24
|
## Supported versions
|
25
25
|
|
26
|
-
* ActiveRecord 4.
|
26
|
+
* ActiveRecord 4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0 (edge)
|
27
27
|
|
28
|
-
* Ruby 2.
|
28
|
+
* Ruby 2.4, 2.5, 2.6, 2.7, 3.0, 3.1 (trunk)
|
29
29
|
|
30
30
|
## Installation
|
31
31
|
|
@@ -98,7 +98,7 @@ In cases of this situation, bundle database\_rewinder and add the following conf
|
|
98
98
|
|
99
99
|
```ruby
|
100
100
|
RSpec.configure do |config|
|
101
|
-
config.
|
101
|
+
config.use_transactional_tests = false
|
102
102
|
|
103
103
|
...
|
104
104
|
end
|
data/database_rewinder.gemspec
CHANGED
@@ -6,10 +6,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "database_rewinder"
|
9
|
-
spec.version = '0.9.
|
9
|
+
spec.version = '0.9.8'
|
10
10
|
spec.authors = ["Akira Matsuda"]
|
11
11
|
spec.email = ["ronnie@dio.jp"]
|
12
|
-
spec.description = "A minimalist's tiny and ultra-fast database cleaner"
|
12
|
+
spec.description = "A minimalist's tiny and ultra-fast database cleaner for Active Record"
|
13
13
|
spec.summary = "A minimalist's tiny and ultra-fast database cleaner"
|
14
14
|
spec.homepage = 'https://github.com/amatsuda/database_rewinder'
|
15
15
|
spec.license = "MIT"
|
@@ -23,8 +23,5 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency 'test-unit-rails'
|
25
25
|
spec.add_development_dependency 'rails'
|
26
|
-
spec.add_development_dependency 'sqlite3'
|
27
|
-
spec.add_development_dependency 'mysql2'
|
28
|
-
spec.add_development_dependency 'pg'
|
29
26
|
spec.required_ruby_version = '>= 2.0.0'
|
30
27
|
end
|
@@ -2,29 +2,71 @@
|
|
2
2
|
|
3
3
|
module DatabaseRewinder
|
4
4
|
module InsertRecorder
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Execute
|
6
|
+
module NoKwargs
|
7
|
+
def execute(sql, *)
|
8
|
+
DatabaseRewinder.record_inserted_table self, sql
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module WithKwargs
|
14
|
+
def execute(sql, *, **)
|
15
|
+
DatabaseRewinder.record_inserted_table self, sql
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def raw_execute(sql, *, **)
|
20
|
+
DatabaseRewinder.record_inserted_table self, sql
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
8
24
|
end
|
9
25
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
26
|
+
module ExecQuery
|
27
|
+
module NoKwargs
|
28
|
+
def exec_query(sql, *)
|
29
|
+
DatabaseRewinder.record_inserted_table self, sql
|
30
|
+
super
|
31
|
+
end
|
14
32
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
33
|
+
|
34
|
+
module WithKwargs
|
35
|
+
def exec_query(sql, *, **)
|
36
|
+
DatabaseRewinder.record_inserted_table self, sql
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# This method actually no longer has to be a `prepended` hook because InsertRecorder is a module without a direct method now, but still doing this just for compatibility
|
43
|
+
def self.prepended(mod)
|
44
|
+
if meth = mod.instance_method(:execute)
|
45
|
+
if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
|
46
|
+
mod.send :prepend, Execute::WithKwargs
|
47
|
+
else
|
48
|
+
mod.send :prepend, Execute::NoKwargs
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if meth = mod.instance_method(:exec_query)
|
52
|
+
if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
|
53
|
+
mod.send :prepend, ExecQuery::WithKwargs
|
54
|
+
else
|
55
|
+
mod.send :prepend, ExecQuery::NoKwargs
|
56
|
+
end
|
19
57
|
end
|
20
58
|
end
|
21
59
|
end
|
22
60
|
end
|
23
61
|
|
24
|
-
::ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
25
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
26
|
-
::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
|
27
62
|
|
63
|
+
# Already loaded adapters (SQLite3Adapter, PostgreSQLAdapter, AbstractMysqlAdapter, and possibly another third party adapter)
|
64
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.descendants.each do |adapter|
|
65
|
+
# Note: this would only prepend on AbstractMysqlAdapter and not on Mysql2Adapter because ```Mysql2Adapter < InsertRecorder``` becomes true immediately after AbstractMysqlAdapter prepends InsertRecorder
|
66
|
+
adapter.send :prepend, DatabaseRewinder::InsertRecorder unless adapter < DatabaseRewinder::InsertRecorder
|
67
|
+
end
|
68
|
+
|
69
|
+
# Third party adapters that might be loaded in the future
|
28
70
|
def (::ActiveRecord::ConnectionAdapters::AbstractAdapter).inherited(adapter)
|
29
|
-
adapter.prepend DatabaseRewinder::InsertRecorder
|
71
|
+
adapter.send :prepend, DatabaseRewinder::InsertRecorder
|
30
72
|
end
|
@@ -48,6 +48,8 @@ module DatabaseRewinder
|
|
48
48
|
def delete_all(ar_conn, tables, multiple: true)
|
49
49
|
tables = tables & @only if @only.any?
|
50
50
|
tables -= @except if @except.any?
|
51
|
+
# in order to avoid referential integrity error as much as possible
|
52
|
+
tables.reverse!
|
51
53
|
return if tables.empty?
|
52
54
|
|
53
55
|
if multiple && tables.many? && ar_conn.supports_multiple_statements?
|
data/lib/database_rewinder.rb
CHANGED
@@ -16,7 +16,7 @@ module DatabaseRewinder
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def create_cleaner(connection_name)
|
19
|
-
config =
|
19
|
+
config = configuration_hash_for(connection_name) or raise %Q[Database configuration named "#{connection_name}" is not configured.]
|
20
20
|
|
21
21
|
Cleaner.new(config: config, connection_name: connection_name, only: @only, except: @except).tap {|c| @cleaners << c}
|
22
22
|
end
|
@@ -84,14 +84,45 @@ module DatabaseRewinder
|
|
84
84
|
|
85
85
|
def get_cache_key(connection_pool)
|
86
86
|
if connection_pool.respond_to?(:db_config) # ActiveRecord >= 6.1
|
87
|
-
connection_pool.db_config.
|
87
|
+
connection_pool.db_config.configuration_hash
|
88
88
|
else
|
89
89
|
connection_pool.spec.config
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
def configuration_hash_for(connection_name)
|
94
|
+
if database_configuration.respond_to?(:configs_for)
|
95
|
+
hash_config = database_configuration_for(connection_name)
|
96
|
+
if hash_config
|
97
|
+
if hash_config.respond_to?(:configuration_hash)
|
98
|
+
hash_config.configuration_hash.stringify_keys
|
99
|
+
else
|
100
|
+
hash_config.config
|
101
|
+
end
|
102
|
+
end
|
103
|
+
else
|
104
|
+
database_configuration[connection_name]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def database_configuration_for(connection_name)
|
109
|
+
traditional_configuration_for(connection_name) || multiple_database_configuration_for(connection_name)
|
110
|
+
end
|
111
|
+
|
112
|
+
def traditional_configuration_for(connection_name)
|
113
|
+
database_configuration.configs_for(env_name: connection_name).first
|
114
|
+
end
|
115
|
+
|
116
|
+
def multiple_database_configuration_for(connection_name)
|
117
|
+
if (ActiveRecord::VERSION::MAJOR >= 7) || ((ActiveRecord::VERSION::MAJOR >= 6) && (ActiveRecord::VERSION::MINOR >= 1))
|
118
|
+
database_configuration.configs_for(name: connection_name)
|
119
|
+
else
|
120
|
+
database_configuration.configs_for(spec_name: connection_name)
|
121
|
+
end
|
122
|
+
end
|
92
123
|
end
|
93
124
|
|
94
|
-
private_class_method :get_cache_key
|
125
|
+
private_class_method :configuration_hash_for, :get_cache_key
|
95
126
|
end
|
96
127
|
|
97
128
|
begin
|
data/test/config/database.yml
CHANGED
@@ -15,30 +15,38 @@ test2:
|
|
15
15
|
<% when 'mysql' %>
|
16
16
|
test:
|
17
17
|
adapter: mysql2
|
18
|
-
host:
|
18
|
+
host: 127.0.0.1
|
19
19
|
username: root
|
20
20
|
password:
|
21
21
|
database: database_rewinder_test
|
22
22
|
|
23
23
|
test2:
|
24
24
|
adapter: mysql2
|
25
|
-
host:
|
25
|
+
host: 127.0.0.1
|
26
26
|
username: root
|
27
27
|
password:
|
28
28
|
database: database_rewinder_test2
|
29
29
|
|
30
30
|
<% when 'postgresql' %>
|
31
|
-
|
31
|
+
superuser_connection:
|
32
32
|
adapter: postgresql
|
33
33
|
host: localhost
|
34
|
+
# this user has to be a superuser for the tests to pass
|
34
35
|
username: postgres
|
35
|
-
password:
|
36
|
+
password: postgres
|
37
|
+
database: postgres
|
38
|
+
|
39
|
+
test:
|
40
|
+
adapter: postgresql
|
41
|
+
host: localhost
|
42
|
+
username: database_rewinder_user
|
43
|
+
password: postgres
|
36
44
|
database: database_rewinder_test
|
37
45
|
|
38
46
|
test2:
|
39
47
|
adapter: postgresql
|
40
48
|
host: localhost
|
41
|
-
username:
|
42
|
-
password:
|
49
|
+
username: database_rewinder_user
|
50
|
+
password: postgres
|
43
51
|
database: database_rewinder_test2
|
44
52
|
<% end %>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
|
6
|
-
if ActiveRecord::VERSION::
|
6
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
7
7
|
self.use_transactional_tests = false
|
8
8
|
else
|
9
9
|
self.use_transactional_fixtures = false
|
@@ -44,6 +44,54 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
|
|
44
44
|
DatabaseRewinder[:aho, connection: 'ccc']
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
if ActiveRecord::VERSION::MAJOR >= 6
|
49
|
+
sub_test_case 'with traditional configurations' do
|
50
|
+
test 'simply giving a connection name only' do
|
51
|
+
assert_cleaners_added ['aaa'] do
|
52
|
+
DatabaseRewinder.database_configuration = ActiveRecord::DatabaseConfigurations.new({'aaa' => {'adapter' => 'sqlite3', 'database' => ':memory:'}})
|
53
|
+
DatabaseRewinder['aaa']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'giving a connection name via Hash with :connection key' do
|
58
|
+
assert_cleaners_added ['bbb'] do
|
59
|
+
DatabaseRewinder.database_configuration = ActiveRecord::DatabaseConfigurations.new({'bbb' => {'adapter' => 'sqlite3', 'database' => ':memory:'}})
|
60
|
+
DatabaseRewinder[connection: 'bbb']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'the Cleaner compatible syntax' do
|
65
|
+
assert_cleaners_added ['ccc'] do
|
66
|
+
DatabaseRewinder.database_configuration = ActiveRecord::DatabaseConfigurations.new({'ccc' => {'adapter' => 'sqlite3', 'database' => ':memory:'}})
|
67
|
+
DatabaseRewinder[:aho, connection: 'ccc']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
sub_test_case 'with multiple database configurations' do
|
73
|
+
test 'simply giving a connection name only' do
|
74
|
+
assert_cleaners_added ['aaa'] do
|
75
|
+
DatabaseRewinder.database_configuration = ActiveRecord::DatabaseConfigurations.new({'test' => {'aaa' => {'adapter' => 'sqlite3', 'database' => ':memory:'}}})
|
76
|
+
DatabaseRewinder['aaa']
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'giving a connection name via Hash with :connection key' do
|
81
|
+
assert_cleaners_added ['bbb'] do
|
82
|
+
DatabaseRewinder.database_configuration = ActiveRecord::DatabaseConfigurations.new({'test' => {'bbb' => {'adapter' => 'sqlite3', 'database' => ':memory:'}}})
|
83
|
+
DatabaseRewinder[connection: 'bbb']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'the Cleaner compatible syntax' do
|
88
|
+
assert_cleaners_added ['ccc'] do
|
89
|
+
DatabaseRewinder.database_configuration = ActiveRecord::DatabaseConfigurations.new({'test' => {'ccc' => {'adapter' => 'sqlite3', 'database' => ':memory:'}}})
|
90
|
+
DatabaseRewinder[:aho, connection: 'ccc']
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
47
95
|
end
|
48
96
|
|
49
97
|
test 'for connecting to multiple databases' do
|
@@ -87,7 +135,7 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
|
|
87
135
|
assert_equal ['bars'], @cleaner.inserted_tables
|
88
136
|
end
|
89
137
|
|
90
|
-
if ActiveRecord::VERSION::
|
138
|
+
if ActiveRecord::VERSION::MAJOR >= 6
|
91
139
|
test 'insert_all' do
|
92
140
|
Bar.insert_all! [{name: 'bar1'}]
|
93
141
|
assert_equal ['bars'], @cleaner.inserted_tables
|
@@ -159,7 +207,7 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
|
|
159
207
|
assert_equal 0, Bar.count
|
160
208
|
end
|
161
209
|
|
162
|
-
if ActiveRecord::VERSION::
|
210
|
+
if ActiveRecord::VERSION::MAJOR >= 4
|
163
211
|
sub_test_case 'migrations' do
|
164
212
|
test '.clean_all should not touch AR::SchemaMigration' do
|
165
213
|
begin
|
data/test/fake_app.rb
CHANGED
@@ -10,12 +10,29 @@ module DatabaseRewinderTestApp
|
|
10
10
|
|
11
11
|
config.eager_load = false
|
12
12
|
config.active_support.deprecation = :log
|
13
|
+
|
14
|
+
rake_tasks do
|
15
|
+
load 'active_record/railties/databases.rake'
|
16
|
+
end
|
13
17
|
end.initialize!
|
14
18
|
end
|
15
19
|
|
16
|
-
load 'active_record/railties/databases.rake'
|
17
|
-
|
18
20
|
require 'active_record/base'
|
21
|
+
|
22
|
+
if ENV['DB'] == 'postgresql'
|
23
|
+
ActiveRecord::Base.establish_connection(:superuser_connection).connection.execute(<<-CREATE_ROLE_SQL)
|
24
|
+
DO
|
25
|
+
$do$
|
26
|
+
BEGIN
|
27
|
+
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'database_rewinder_user') THEN
|
28
|
+
CREATE ROLE database_rewinder_user LOGIN PASSWORD 'postgres' createdb;
|
29
|
+
END IF;
|
30
|
+
END
|
31
|
+
$do$
|
32
|
+
CREATE_ROLE_SQL
|
33
|
+
ActiveRecord::Base.remove_connection
|
34
|
+
end
|
35
|
+
|
19
36
|
ActiveRecord::Tasks::DatabaseTasks.root ||= Rails.root
|
20
37
|
ActiveRecord::Tasks::DatabaseTasks.drop_current 'test'
|
21
38
|
ActiveRecord::Tasks::DatabaseTasks.drop_current 'test2'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_rewinder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,70 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
-
|
70
|
-
name: sqlite3
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: mysql2
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: pg
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
description: A minimalist's tiny and ultra-fast database cleaner
|
69
|
+
description: A minimalist's tiny and ultra-fast database cleaner for Active Record
|
112
70
|
email:
|
113
71
|
- ronnie@dio.jp
|
114
72
|
executables: []
|
115
73
|
extensions: []
|
116
74
|
extra_rdoc_files: []
|
117
75
|
files:
|
76
|
+
- ".github/workflows/main.yml"
|
118
77
|
- ".gitignore"
|
119
|
-
- ".travis.yml"
|
120
78
|
- Gemfile
|
121
79
|
- MIT_LICENSE
|
122
80
|
- README.md
|
123
81
|
- Rakefile
|
124
82
|
- database_rewinder.gemspec
|
125
|
-
- gemfiles/rails_40.gemfile
|
126
|
-
- gemfiles/rails_41.gemfile
|
127
|
-
- gemfiles/rails_42.gemfile
|
128
|
-
- gemfiles/rails_50.gemfile
|
129
|
-
- gemfiles/rails_51.gemfile
|
130
|
-
- gemfiles/rails_52.gemfile
|
131
|
-
- gemfiles/rails_60.gemfile
|
132
|
-
- gemfiles/rails_edge.gemfile
|
133
83
|
- lib/database_rewinder.rb
|
134
84
|
- lib/database_rewinder/active_record_monkey.rb
|
135
85
|
- lib/database_rewinder/cleaner.rb
|
@@ -148,7 +98,7 @@ homepage: https://github.com/amatsuda/database_rewinder
|
|
148
98
|
licenses:
|
149
99
|
- MIT
|
150
100
|
metadata: {}
|
151
|
-
post_install_message:
|
101
|
+
post_install_message:
|
152
102
|
rdoc_options: []
|
153
103
|
require_paths:
|
154
104
|
- lib
|
@@ -163,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
113
|
- !ruby/object:Gem::Version
|
164
114
|
version: '0'
|
165
115
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
167
|
-
signing_key:
|
116
|
+
rubygems_version: 3.4.0.dev
|
117
|
+
signing_key:
|
168
118
|
specification_version: 4
|
169
119
|
summary: A minimalist's tiny and ultra-fast database cleaner
|
170
120
|
test_files:
|
data/.travis.yml
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
addons:
|
4
|
-
postgresql: '9.4'
|
5
|
-
mysql: '5.7'
|
6
|
-
|
7
|
-
before_install:
|
8
|
-
# install older versions of rubygems and bundler only on Ruby < 2.7
|
9
|
-
- if [ `echo "${TRAVIS_RUBY_VERSION:0:3} < 2.7" | bc` == 1 ]; then gem i rubygems-update -v '<3' && update_rubygems; fi;
|
10
|
-
- if [ `echo "${TRAVIS_RUBY_VERSION:0:3} < 2.7" | bc` == 1 ]; then gem i bundler -v '<2'; fi;
|
11
|
-
- sudo service mysql restart
|
12
|
-
|
13
|
-
|
14
|
-
cache: bundler
|
15
|
-
|
16
|
-
env:
|
17
|
-
matrix:
|
18
|
-
- DB=sqlite3
|
19
|
-
- DB=mysql
|
20
|
-
- DB=postgresql
|
21
|
-
|
22
|
-
rvm:
|
23
|
-
- 2.6.3
|
24
|
-
|
25
|
-
gemfile:
|
26
|
-
- gemfiles/rails_52.gemfile
|
27
|
-
- gemfiles/rails_60.gemfile
|
28
|
-
|
29
|
-
sudo: false
|
30
|
-
|
31
|
-
dist: xenial
|
32
|
-
|
33
|
-
matrix:
|
34
|
-
include:
|
35
|
-
- rvm: 2.7.1
|
36
|
-
gemfile: gemfiles/rails_60.gemfile
|
37
|
-
env: DB=postgresql
|
38
|
-
- rvm: 2.6.3
|
39
|
-
gemfile: gemfiles/rails_edge.gemfile
|
40
|
-
env: DB=postgresql
|
41
|
-
- rvm: 2.5.5
|
42
|
-
gemfile: gemfiles/rails_51.gemfile
|
43
|
-
env: DB=postgresql
|
44
|
-
- rvm: 2.4.6
|
45
|
-
gemfile: gemfiles/rails_50.gemfile
|
46
|
-
env: DB=postgresql
|
47
|
-
- rvm: 2.3.8
|
48
|
-
gemfile: gemfiles/rails_41.gemfile
|
49
|
-
env: DB=postgresql
|
50
|
-
- rvm: 2.3.8
|
51
|
-
gemfile: gemfiles/rails_40.gemfile
|
52
|
-
env: DB=postgresql
|
53
|
-
- rvm: 2.2.10
|
54
|
-
gemfile: gemfiles/rails_52.gemfile
|
55
|
-
env: DB=postgresql
|
56
|
-
- rvm: 2.1.10
|
57
|
-
gemfile: gemfiles/rails_42.gemfile
|
58
|
-
env: DB=postgresql
|
59
|
-
- rvm: 2.0.0
|
60
|
-
gemfile: gemfiles/rails_42.gemfile
|
61
|
-
env: DB=postgresql
|
62
|
-
|
63
|
-
allow_failures:
|
64
|
-
- gemfile: gemfiles/rails_edge.gemfile
|
data/gemfiles/rails_40.gemfile
DELETED
data/gemfiles/rails_41.gemfile
DELETED
data/gemfiles/rails_42.gemfile
DELETED
data/gemfiles/rails_50.gemfile
DELETED
data/gemfiles/rails_51.gemfile
DELETED
data/gemfiles/rails_52.gemfile
DELETED
data/gemfiles/rails_60.gemfile
DELETED
data/gemfiles/rails_edge.gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
git_source(:github) do |repo_name|
|
3
|
-
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
4
|
-
"https://github.com/#{repo_name}.git"
|
5
|
-
end
|
6
|
-
|
7
|
-
gem 'rails', github: 'rails/rails'
|
8
|
-
gem 'selenium-webdriver'
|
9
|
-
|
10
|
-
gemspec path: '../'
|