database_rewinder 0.9.5 → 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: b151e420c4e1985e5674d1781dceae421a9e3d9e19c3486cf87529ac14399008
4
- data.tar.gz: e1ad8090d602a4db4d71626b765c6f932ac8690ae8dfeee40d429f8071465812
3
+ metadata.gz: cdfa4a22f839cc429f7334f0c175a8f51a1c398e67cb10ebe831f9ba18761fed
4
+ data.tar.gz: f7bc66b8f216587fdc6af220a5033d973c6da09c2035a0c63c8a5741b31c5fd4
5
5
  SHA512:
6
- metadata.gz: acca967b5d15e66623e5767fcc9304d56e0d19074f5c02619e77c50f6dacfb51bf0289e6ef64252884f2b2fb88ae198b6abde6b152d0beaf7c13e2c4df290552
7
- data.tar.gz: 9be584317f373acaa2797ff723b4e0a2e7e8121a0aecad1920ecb01b06307224e35238e10ede1a5ec43a3a4eb74511b760b132711c4cbf8dfb55d52700626d26
6
+ metadata.gz: 83b2df863231cef40e644e8a6e567862842bb630cbebd965769a19e365c23dd1877675c548e81150e797b95e8f069bc5b45119c3f7186944d44cd9f889c42ed8
7
+ data.tar.gz: 34aa414d520248f0989087acb94d1e2c01f861c84baceb6cfa89c8bbb424018374fc75e261d52e18d651e994a25ae62e2ed447215f8cbd81b19ae729e7de301d
data/.travis.yml CHANGED
@@ -6,8 +6,8 @@ addons:
6
6
 
7
7
  before_install:
8
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;
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
11
  - sudo service mysql restart
12
12
 
13
13
 
@@ -33,12 +33,30 @@ dist: xenial
33
33
 
34
34
  matrix:
35
35
  include:
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
36
42
  - rvm: 3.0.1
37
43
  gemfile: gemfiles/rails_edge.gemfile
38
44
  env: DB=postgresql
45
+ - rvm: 3.0.1
46
+ gemfile: gemfiles/rails_edge.gemfile
47
+ env: DB=mysql
48
+ - rvm: 3.0.1
49
+ gemfile: gemfiles/rails_edge.gemfile
50
+ env: DB=sqlite3
39
51
  - rvm: 3.0.1
40
52
  gemfile: gemfiles/rails_61.gemfile
41
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
59
+ env: DB=sqlite3
42
60
  - rvm: 2.6.7
43
61
  gemfile: gemfiles/rails_60.gemfile
44
62
  env: DB=postgresql
@@ -68,4 +86,5 @@ matrix:
68
86
  env: DB=postgresql
69
87
 
70
88
  allow_failures:
89
+ - rvm: ruby-head
71
90
  - gemfile: gemfiles/rails_edge.gemfile
@@ -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.5'
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"
@@ -92,7 +92,7 @@ module DatabaseRewinder
92
92
 
93
93
  def configuration_hash_for(connection_name)
94
94
  if database_configuration.respond_to?(:configs_for)
95
- hash_config = database_configuration.configs_for(env_name: connection_name).first
95
+ hash_config = database_configuration_for(connection_name)
96
96
  if hash_config
97
97
  if hash_config.respond_to?(:configuration_hash)
98
98
  hash_config.configuration_hash.stringify_keys
@@ -104,6 +104,22 @@ module DatabaseRewinder
104
104
  database_configuration[connection_name]
105
105
  end
106
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
107
123
  end
108
124
 
109
125
  private_class_method :configuration_hash_for, :get_cache_key
@@ -2,29 +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
- if ActiveRecord::VERSION::MAJOR < 5
11
- def exec_query(sql, *)
12
- DatabaseRewinder.record_inserted_table self, sql
13
- 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
14
45
  end
15
- else
16
- def exec_query(sql, *, **)
17
- DatabaseRewinder.record_inserted_table self, sql
18
- super
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
19
52
  end
20
53
  end
21
54
  end
22
55
  end
23
56
 
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
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
28
65
  def (::ActiveRecord::ConnectionAdapters::AbstractAdapter).inherited(adapter)
29
- adapter.prepend DatabaseRewinder::InsertRecorder
66
+ adapter.send :prepend, DatabaseRewinder::InsertRecorder
30
67
  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
@@ -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::STRING >= '6'
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::STRING >= '4'
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
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.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-26 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
@@ -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: []
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
166
  requirements: []
167
- rubygems_version: 3.3.0.dev
167
+ rubygems_version: 3.2.15
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: A minimalist's tiny and ultra-fast database cleaner