database_rewinder 0.9.1 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b65d98970a4cf3742c0ea0254aedb60cc3d64260f9b3bbca199bad7880a178aa
4
- data.tar.gz: 131690c4430bc96b9fb06d00eaf6474bbe23f9bb038e44f18c00240f5ff9372d
3
+ metadata.gz: cdfa4a22f839cc429f7334f0c175a8f51a1c398e67cb10ebe831f9ba18761fed
4
+ data.tar.gz: f7bc66b8f216587fdc6af220a5033d973c6da09c2035a0c63c8a5741b31c5fd4
5
5
  SHA512:
6
- metadata.gz: 02cdab1001bce6f92944c765d696ee94e6ea2cdddb4ffe9b438a184d62fd0adb8ba9cb2521d1c3a655cfbe52a653ab62f56f3259244cc55ea5f420240aa814be
7
- data.tar.gz: 11a8155b683374275680fbb16c03b2d6f5f8af4fa51310e6e05e49b1330f6dbf5ba8793643617085cb6d2765372c61d5ef7a0887639e351554b52492c68e0417
6
+ metadata.gz: 83b2df863231cef40e644e8a6e567862842bb630cbebd965769a19e365c23dd1877675c548e81150e797b95e8f069bc5b45119c3f7186944d44cd9f889c42ed8
7
+ data.tar.gz: 34aa414d520248f0989087acb94d1e2c01f861c84baceb6cfa89c8bbb424018374fc75e261d52e18d651e994a25ae62e2ed447215f8cbd81b19ae729e7de301d
data/.travis.yml CHANGED
@@ -1,47 +1,90 @@
1
1
  language: ruby
2
2
 
3
+ addons:
4
+ postgresql: '9.4'
5
+ mysql: '5.7'
6
+
3
7
  before_install:
4
- - gem update --system
5
- - gem install bundler
8
+ # install older versions of rubygems and bundler only on Ruby < 2.7
9
+ - if [ "${TRAVIS_RUBY_VERSION}" != "ruby-head" ] && [ `echo "${TRAVIS_RUBY_VERSION:0:3} < 2.7" | bc` == 1 ]; then gem i rubygems-update -v '<3' && update_rubygems; fi;
10
+ - if [ "${TRAVIS_RUBY_VERSION}" != "ruby-head" ] && [ `echo "${TRAVIS_RUBY_VERSION:0:3} < 2.7" | bc` == 1 ]; then gem i bundler -v '<2'; fi;
11
+ - sudo service mysql restart
12
+
6
13
 
7
14
  cache: bundler
8
15
 
9
16
  env:
10
- - DB=sqlite3
11
- - DB=mysql
12
- - DB=postgresql
17
+ matrix:
18
+ - DB=sqlite3
19
+ - DB=mysql
20
+ - DB=postgresql
13
21
 
14
22
  rvm:
15
- - 2.5.1
16
- - 2.4.4
17
- - 2.3.7
18
- - 2.2.10
23
+ - 2.7.3
19
24
 
20
25
  gemfile:
21
26
  - gemfiles/rails_52.gemfile
22
- - gemfiles/rails_51.gemfile
23
- - gemfiles/rails_50.gemfile
24
- - gemfiles/rails_42.gemfile
27
+ - gemfiles/rails_60.gemfile
28
+ - gemfiles/rails_61.gemfile
25
29
 
26
30
  sudo: false
27
31
 
32
+ dist: xenial
33
+
28
34
  matrix:
29
35
  include:
30
- - rvm: 2.5.1
36
+ - rvm: ruby-head
37
+ gemfile: gemfiles/rails_edge.gemfile
38
+ env: DB=postgresql
39
+ - rvm: ruby-head
40
+ gemfile: gemfiles/rails_61.gemfile
41
+ env: DB=postgresql
42
+ - rvm: 3.0.1
43
+ gemfile: gemfiles/rails_edge.gemfile
44
+ env: DB=postgresql
45
+ - rvm: 3.0.1
46
+ gemfile: gemfiles/rails_edge.gemfile
47
+ env: DB=mysql
48
+ - rvm: 3.0.1
31
49
  gemfile: gemfiles/rails_edge.gemfile
32
50
  env: DB=sqlite3
33
- - rvm: 2.3.7
34
- gemfile: gemfiles/rails_41.gemfile
51
+ - rvm: 3.0.1
52
+ gemfile: gemfiles/rails_61.gemfile
53
+ env: DB=postgresql
54
+ - rvm: 3.0.1
55
+ gemfile: gemfiles/rails_61.gemfile
56
+ env: DB=mysql
57
+ - rvm: 3.0.1
58
+ gemfile: gemfiles/rails_61.gemfile
35
59
  env: DB=sqlite3
36
- - rvm: 2.3.7
60
+ - rvm: 2.6.7
61
+ gemfile: gemfiles/rails_60.gemfile
62
+ env: DB=postgresql
63
+ - rvm: 2.6.7
64
+ gemfile: gemfiles/rails_52.gemfile
65
+ env: DB=postgresql
66
+ - rvm: 2.5.9
67
+ gemfile: gemfiles/rails_51.gemfile
68
+ env: DB=postgresql
69
+ - rvm: 2.4.10
70
+ gemfile: gemfiles/rails_50.gemfile
71
+ env: DB=postgresql
72
+ - rvm: 2.3.8
73
+ gemfile: gemfiles/rails_41.gemfile
74
+ env: DB=postgresql
75
+ - rvm: 2.3.8
37
76
  gemfile: gemfiles/rails_40.gemfile
38
- env: DB=sqlite3
77
+ env: DB=postgresql
78
+ - rvm: 2.2.10
79
+ gemfile: gemfiles/rails_52.gemfile
80
+ env: DB=postgresql
39
81
  - rvm: 2.1.10
40
82
  gemfile: gemfiles/rails_42.gemfile
41
- env: DB=sqlite3
83
+ env: DB=postgresql
42
84
  - rvm: 2.0.0
43
85
  gemfile: gemfiles/rails_42.gemfile
44
- env: DB=sqlite3
86
+ env: DB=postgresql
45
87
 
46
88
  allow_failures:
89
+ - rvm: ruby-head
47
90
  - gemfile: gemfiles/rails_edge.gemfile
data/README.md CHANGED
@@ -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.0, 4.1, 4.2, 5.0, 5.1, 5.2, 6.0 (edge)
26
+ * ActiveRecord 4.0, 4.1, 4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0 (edge)
27
27
 
28
- * Ruby 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 (trunk)
28
+ * Ruby 2.0, 2.1, 2.2, 2.3, 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.use_transactional_examples = false
101
+ config.use_transactional_tests = false
102
102
 
103
103
  ...
104
104
  end
@@ -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.1'
9
+ spec.version = '0.9.6'
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"
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency 'bundler'
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency 'test-unit-rails'
25
25
  spec.add_development_dependency 'rails'
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 4.0.0'
4
4
  gem 'pg', '~> 0.21'
5
5
  gem 'mysql2', '~> 0.3.10'
6
+ gem 'sqlite3', '< 1.4'
6
7
  gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
7
8
 
8
9
  gemspec path: '../'
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 4.1.0'
4
4
  gem 'pg', '~> 0.21'
5
5
  gem 'mysql2', '~> 0.3.13'
6
+ gem 'sqlite3', '< 1.4'
6
7
  gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
7
8
 
8
9
  gemspec path: '../'
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 4.2.0'
4
4
  gem 'pg', '~> 0.21'
5
5
  gem 'mysql2', '~> 0.4.0'
6
+ gem 'sqlite3', '< 1.4'
6
7
  gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
7
8
 
8
9
  gemspec path: '../'
@@ -2,5 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 5.0.0'
4
4
  gem 'pg', '~> 0.21'
5
+ gem 'sqlite3', '< 1.4'
5
6
 
6
7
  gemspec path: '../'
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 5.2.0'
3
+ gem 'rails', '~> 5.2.0', git: 'https://github.com/rails/rails', branch: '5-2-stable'
4
4
  gem 'pg', '~> 0.21'
5
5
 
6
6
  gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 6.0.0'
4
+ gem 'selenium-webdriver'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 6.1.0'
4
+ gem 'selenium-webdriver'
5
+
6
+ gemspec path: '../'
@@ -4,6 +4,7 @@ git_source(:github) do |repo_name|
4
4
  "https://github.com/#{repo_name}.git"
5
5
  end
6
6
 
7
- gem 'rails', github: 'rails/rails'
7
+ gem 'rails', github: 'rails/rails', branch: 'main'
8
+ gem 'selenium-webdriver'
8
9
 
9
10
  gemspec path: '../'
@@ -16,7 +16,7 @@ module DatabaseRewinder
16
16
  end
17
17
 
18
18
  def create_cleaner(connection_name)
19
- config = database_configuration[connection_name] or raise %Q[Database configuration named "#{connection_name}" is not configured.]
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
@@ -48,7 +48,7 @@ module DatabaseRewinder
48
48
  end or return
49
49
 
50
50
  sql.split(';').each do |statement|
51
- match = statement.match(/\A\s*INSERT(?:\s+IGNORE)?(?:\s+INTO)?\s+(?:\.*[`"]?([^.\s`"]+)[`"]?)*/i)
51
+ match = statement.match(/\A\s*INSERT(?:\s+IGNORE)?(?:\s+INTO)?\s+(?:\.*[`"]?([^.\s`"(]+)[`"]?)*/i)
52
52
  next unless match
53
53
 
54
54
  table = match[1]
@@ -73,7 +73,7 @@ module DatabaseRewinder
73
73
 
74
74
  # cache AR connection.tables
75
75
  def all_table_names(connection)
76
- cache_key = connection.pool.spec.config
76
+ cache_key = get_cache_key(connection.pool)
77
77
  #NOTE connection.tables warns on AR 5 with some adapters
78
78
  tables = ActiveSupport::Deprecation.silence { connection.tables }
79
79
  @table_names_cache[cache_key] ||= tables.reject do |t|
@@ -81,7 +81,48 @@ module DatabaseRewinder
81
81
  (ActiveRecord::Base.respond_to?(:internal_metadata_table_name) && (t == ActiveRecord::Base.internal_metadata_table_name))
82
82
  end
83
83
  end
84
+
85
+ def get_cache_key(connection_pool)
86
+ if connection_pool.respond_to?(:db_config) # ActiveRecord >= 6.1
87
+ connection_pool.db_config.configuration_hash
88
+ else
89
+ connection_pool.spec.config
90
+ end
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 >= 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
84
123
  end
124
+
125
+ private_class_method :configuration_hash_for, :get_cache_key
85
126
  end
86
127
 
87
128
  begin
@@ -2,22 +2,66 @@
2
2
 
3
3
  module DatabaseRewinder
4
4
  module InsertRecorder
5
- def execute(sql, *)
6
- DatabaseRewinder.record_inserted_table self, sql
7
- super
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
+ end
19
+ end
20
+
21
+ module ExecQuery
22
+ module NoKwargs
23
+ def exec_query(sql, *)
24
+ DatabaseRewinder.record_inserted_table self, sql
25
+ super
26
+ end
27
+ end
28
+
29
+ module WithKwargs
30
+ def exec_query(sql, *, **)
31
+ DatabaseRewinder.record_inserted_table self, sql
32
+ super
33
+ end
34
+ end
8
35
  end
9
36
 
10
- def exec_query(sql, *)
11
- DatabaseRewinder.record_inserted_table self, sql
12
- super
37
+ # 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
38
+ def self.prepended(mod)
39
+ if meth = mod.instance_method(:execute)
40
+ if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
41
+ mod.send :prepend, Execute::WithKwargs
42
+ else
43
+ mod.send :prepend, Execute::NoKwargs
44
+ end
45
+ end
46
+ if meth = mod.instance_method(:exec_query)
47
+ if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
48
+ mod.send :prepend, ExecQuery::WithKwargs
49
+ else
50
+ mod.send :prepend, ExecQuery::NoKwargs
51
+ end
52
+ end
13
53
  end
14
54
  end
15
55
  end
16
56
 
17
- ::ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::SQLite3Adapter
18
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
19
- ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
20
57
 
58
+ # Already loaded adapters (SQLite3Adapter, PostgreSQLAdapter, AbstractMysqlAdapter, and possibly another third party adapter)
59
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.descendants.each do |adapter|
60
+ # Note: this would only prepend on AbstractMysqlAdapter and not on Mysql2Adapter because ```Mysql2Adapter < InsertRecorder``` becomes true immediately after AbstractMysqlAdapter prepends InsertRecorder
61
+ adapter.send :prepend, DatabaseRewinder::InsertRecorder unless adapter < DatabaseRewinder::InsertRecorder
62
+ end
63
+
64
+ # Third party adapters that might be loaded in the future
21
65
  def (::ActiveRecord::ConnectionAdapters::AbstractAdapter).inherited(adapter)
22
- adapter.prepend DatabaseRewinder::InsertRecorder
66
+ adapter.send :prepend, DatabaseRewinder::InsertRecorder
23
67
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DatabaseRewinder
4
4
  module Compatibility
5
- def clean_with(*args)
6
- cleaners.each {|c| c.clean_with(*args)}
5
+ def clean_with(*args, **opts)
6
+ cleaners.each {|c| c.clean_with(*args, **opts)}
7
7
  end
8
8
 
9
9
  def cleaning
@@ -36,7 +36,7 @@ module DatabaseRewinder
36
36
  # DatabaseRewinder[:active_record, connection: 'the_db_name']
37
37
  #
38
38
  # You can cleanup multiple databases for each test using this configuration.
39
- def [](orm, connection: nil, **)
39
+ def [](orm = nil, connection: nil, **)
40
40
  if connection.nil?
41
41
  if orm.is_a? String
42
42
  connection = orm
@@ -1,45 +1,44 @@
1
- sqlite3: &sqlite3
1
+ <% case ENV['DB']
2
+ when 'sqlite3' %>
3
+ test:
2
4
  adapter: sqlite3
3
5
  database: db/database_rewinder_test.sqlite3
4
6
  pool: 5
5
7
  timeout: 5000
6
8
 
7
- sqlite3_2: &sqlite3_2
9
+ test2:
8
10
  adapter: sqlite3
9
11
  database: db/database_rewinder_test2.sqlite3
10
12
  pool: 5
11
13
  timeout: 5000
12
14
 
13
- mysql: &mysql
15
+ <% when 'mysql' %>
16
+ test:
14
17
  adapter: mysql2
15
18
  host: localhost
16
19
  username: root
17
20
  password:
18
21
  database: database_rewinder_test
19
22
 
20
- mysql_2: &mysql_2
23
+ test2:
21
24
  adapter: mysql2
22
25
  host: localhost
23
26
  username: root
24
27
  password:
25
28
  database: database_rewinder_test2
26
29
 
27
- postgresql: &postgresql
30
+ <% when 'postgresql' %>
31
+ test:
28
32
  adapter: postgresql
29
33
  host: localhost
30
34
  username: postgres
31
35
  password:
32
36
  database: database_rewinder_test
33
37
 
34
- postgresql_2: &postgresql_2
38
+ test2:
35
39
  adapter: postgresql
36
40
  host: localhost
37
41
  username: postgres
38
42
  password:
39
43
  database: database_rewinder_test2
40
-
41
- test:
42
- <<: *<%= ENV['DB'] %>
43
-
44
- test2:
45
- <<: *<%= "#{ENV['DB']}_2" %>
44
+ <% end %>
@@ -3,7 +3,7 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
6
- if ActiveRecord::VERSION::STRING >= '5'
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
@@ -76,6 +124,25 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
76
124
  DatabaseRewinder.database_configuration = nil
77
125
  end
78
126
 
127
+ sub_test_case 'via General Active Record insertions' do
128
+ setup do
129
+ DatabaseRewinder.cleaners
130
+ @cleaner = DatabaseRewinder.instance_variable_get(:'@cleaners').detect {|c| c.db == (ENV['DB'] == 'sqlite3' ? 'db/database_rewinder_test.sqlite3' : 'database_rewinder_test')}
131
+ end
132
+
133
+ test 'create' do
134
+ Bar.create name: 'bar1'
135
+ assert_equal ['bars'], @cleaner.inserted_tables
136
+ end
137
+
138
+ if ActiveRecord::VERSION::MAJOR >= 6
139
+ test 'insert_all' do
140
+ Bar.insert_all! [{name: 'bar1'}]
141
+ assert_equal ['bars'], @cleaner.inserted_tables
142
+ end
143
+ end
144
+ end
145
+
79
146
  sub_test_case 'common database' do
80
147
  test 'include database name' do
81
148
  perform_insert 'INSERT INTO "database"."foos" ("name") VALUES (?)'
@@ -95,6 +162,10 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
95
162
  SQL
96
163
  assert_equal ['foos'], @cleaner.inserted_tables
97
164
  end
165
+ test 'without spaces between table name and columns list' do
166
+ perform_insert 'INSERT INTO foos(name) VALUES (?)'
167
+ assert_equal ['foos'], @cleaner.inserted_tables
168
+ end
98
169
 
99
170
  test 'with multi statement query' do
100
171
  perform_insert <<-SQL
@@ -136,7 +207,7 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
136
207
  assert_equal 0, Bar.count
137
208
  end
138
209
 
139
- if ActiveRecord::VERSION::STRING >= '4'
210
+ if ActiveRecord::VERSION::MAJOR >= 4
140
211
  sub_test_case 'migrations' do
141
212
  test '.clean_all should not touch AR::SchemaMigration' do
142
213
  begin
@@ -160,7 +231,7 @@ class DatabaseRewinder::DatabaseRewinderTest < ActiveSupport::TestCase
160
231
  @except = @cleaner.instance_variable_get(:@except)
161
232
  Foo.create! name: 'foo1'
162
233
  Bar.create! name: 'bar1'
163
- DatabaseRewinder.clean_with :truncation, options
234
+ DatabaseRewinder.clean_with :truncation, **options
164
235
  end
165
236
 
166
237
  test 'with only option' do
data/test/fake_app.rb CHANGED
@@ -17,30 +17,30 @@ load 'active_record/railties/databases.rake'
17
17
 
18
18
  require 'active_record/base'
19
19
  ActiveRecord::Tasks::DatabaseTasks.root ||= Rails.root
20
- ActiveRecord::Tasks::DatabaseTasks.drop_current ENV['DB']
21
- ActiveRecord::Tasks::DatabaseTasks.drop_current "#{ENV['DB']}_2"
22
- ActiveRecord::Tasks::DatabaseTasks.create_current ENV['DB']
23
- ActiveRecord::Tasks::DatabaseTasks.create_current "#{ENV['DB']}_2"
20
+ ActiveRecord::Tasks::DatabaseTasks.drop_current 'test'
21
+ ActiveRecord::Tasks::DatabaseTasks.drop_current 'test2'
22
+ ActiveRecord::Tasks::DatabaseTasks.create_current 'test'
23
+ ActiveRecord::Tasks::DatabaseTasks.create_current 'test2'
24
24
 
25
25
  # models
26
26
  class Foo < ActiveRecord::Base; end
27
27
  class Bar < ActiveRecord::Base; end
28
28
  class Baz < ActiveRecord::Base; end
29
29
  class Quu < ActiveRecord::Base
30
- establish_connection "#{ENV['DB']}_2".to_sym
30
+ establish_connection :test2
31
31
  end
32
32
 
33
33
  # migrations
34
34
  class CreateAllTables < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
35
35
  def self.up
36
- ActiveRecord::Base.establish_connection ENV['DB'].to_sym
37
- create_table(:bars) {|t| t.string :name }
36
+ ActiveRecord::Base.establish_connection :test
37
+ create_table(:bars) {|t| t.string :name; t.index :name, unique: true }
38
38
  create_table(:foos) {|t| t.string :name; t.references :bar, foreign_key: true }
39
39
  create_table(:bazs) {|t| t.string :name }
40
40
 
41
- test2_connection = ActiveRecord::Base.establish_connection("#{ENV['DB']}_2".to_sym).connection
41
+ test2_connection = ActiveRecord::Base.establish_connection(:test2).connection
42
42
  test2_connection.create_table(:quus) {|t| t.string :name }
43
- ActiveRecord::Base.establish_connection ENV['DB'].to_sym
43
+ ActiveRecord::Base.establish_connection :test
44
44
  end
45
45
 
46
46
  def self.down
@@ -48,8 +48,8 @@ class CreateAllTables < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migrat
48
48
  drop_table(:bars) {|t| t.string :name }
49
49
  drop_table(:bazs) {|t| t.string :name }
50
50
 
51
- test2_connection = ActiveRecord::Base.establish_connection("#{ENV['DB']}_2".to_sym).connection
51
+ test2_connection = ActiveRecord::Base.establish_connection(:test2).connection
52
52
  test2_connection.drop_table :quus
53
- ActiveRecord::Base.establish_connection ENV['DB'].to_sym
53
+ ActiveRecord::Base.establish_connection :test
54
54
  end
55
55
  end
data/test/test_helper.rb CHANGED
@@ -10,6 +10,10 @@ require 'active_record'
10
10
  require 'database_rewinder'
11
11
  require 'fake_app'
12
12
  require 'test/unit/rails/test_help'
13
+ begin
14
+ require 'selenium/webdriver' # rails 6
15
+ rescue LoadError
16
+ end
13
17
 
14
18
  migrated = ActiveRecord::Base.connection.respond_to?(:data_source_exists?) ? ActiveRecord::Base.connection.data_source_exists?('foos') : ActiveRecord::Base.connection.table_exists?('foos')
15
19
  CreateAllTables.up unless migrated
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_rewinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.6
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: 2018-12-18 00:00:00.000000000 Z
11
+ date: 2021-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: A minimalist's tiny and ultra-fast database cleaner
111
+ description: A minimalist's tiny and ultra-fast database cleaner for Active Record
112
112
  email:
113
113
  - ronnie@dio.jp
114
114
  executables: []
@@ -128,6 +128,8 @@ files:
128
128
  - gemfiles/rails_50.gemfile
129
129
  - gemfiles/rails_51.gemfile
130
130
  - gemfiles/rails_52.gemfile
131
+ - gemfiles/rails_60.gemfile
132
+ - gemfiles/rails_61.gemfile
131
133
  - gemfiles/rails_edge.gemfile
132
134
  - lib/database_rewinder.rb
133
135
  - lib/database_rewinder/active_record_monkey.rb
@@ -147,7 +149,7 @@ homepage: https://github.com/amatsuda/database_rewinder
147
149
  licenses:
148
150
  - MIT
149
151
  metadata: {}
150
- post_install_message:
152
+ post_install_message:
151
153
  rdoc_options: []
152
154
  require_paths:
153
155
  - lib
@@ -162,8 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
164
  - !ruby/object:Gem::Version
163
165
  version: '0'
164
166
  requirements: []
165
- rubygems_version: 3.0.0.beta3
166
- signing_key:
167
+ rubygems_version: 3.2.15
168
+ signing_key:
167
169
  specification_version: 4
168
170
  summary: A minimalist's tiny and ultra-fast database cleaner
169
171
  test_files: