acidic_job 1.0.0.pre7 → 1.0.0.pre8

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: bf6aac5040961c40dafe3650663ae883ce7f8a101bea9eaaf3e82c23df75938d
4
- data.tar.gz: 5ddef7d9b955f06306c9a7f338c3b2dca01e85a7716f24c2865d94f294ac26dc
3
+ metadata.gz: 5ed45351f35a4450eebc153e9bff2eba2a8c5cd1dcf5b121f9fa9c9e5e910936
4
+ data.tar.gz: a4eff2b6a54ab1e89fab5b548022e3104540e118694f45bc42ebaf6b8e5cadb1
5
5
  SHA512:
6
- metadata.gz: a224fb33d1c86ac07c4a0d6bd5d4f8853a7ddbb477fef6c3a1584c62002f7e1c7741c89b751874b8405d99132bfa17fefae6aa0364373709f9cd5725b64cb02f
7
- data.tar.gz: '090ca69264e42984c3dd2331e073d90cd9f3d464c602b854f81d745a9dedd33586f155cfbd885d832b30b8e4c0956b0eda192978e3aa5165b623ce503a651b01'
6
+ metadata.gz: 79ebea1341fcab4b84b4534b0a6aa468c1b1b96813bd687744c5caff97050ec62a2af51f6c89b8631801774b06babfb5044233b5e060383051bc33ff4bc8338c
7
+ data.tar.gz: b10c9a7c05c8bd4079a35f865a1c31cef193ccfd2219718cb0df453272211ad2c62772db14763e4244752f6c2c8666a3ef5eb512b07bff7ffa75325d41ccf68e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (1.0.0.pre7)
4
+ acidic_job (1.0.0.pre8)
5
5
  activerecord (>= 6.1.0)
6
6
  activesupport
7
7
 
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_job/test_case"
4
- require "database_cleaner/active_record"
4
+ require "database_cleaner"
5
5
 
6
6
  module AcidicJob
7
7
  class TestCase < ActiveJob::TestCase
8
- self.use_transactional_tests = false
8
+ self.use_transactional_tests = false if respond_to?(:use_transactional_tests)
9
9
 
10
10
  def before_setup
11
+ @original_cleaners = DatabaseCleaner.cleaners
12
+ DatabaseCleaner.cleaners = transaction_free_cleaners_for(@original_cleaners)
11
13
  super
12
14
  DatabaseCleaner.start
13
15
  end
@@ -15,6 +17,55 @@ module AcidicJob
15
17
  def after_teardown
16
18
  DatabaseCleaner.clean
17
19
  super
20
+ DatabaseCleaner.cleaners = @original_cleaners
21
+ end
22
+
23
+ private
24
+
25
+ # Ensure that the system's original DatabaseCleaner configuration is maintained, options included,
26
+ # except that any `transaction` strategies for any ORMs are replaced with a `deletion` strategy.
27
+ def transaction_free_cleaners_for(original_cleaners)
28
+ non_transaction_cleaners = original_cleaners.dup.map do |(orm, opts), cleaner|
29
+ [[orm, opts], ensure_no_transaction_strategies_for(cleaner)]
30
+ end.to_h
31
+ DatabaseCleaner::Cleaners.new(non_transaction_cleaners)
32
+ end
33
+
34
+ def ensure_no_transaction_strategies_for(cleaner)
35
+ return cleaner unless strategy_name_for(cleaner) == "transaction"
36
+
37
+ cleaner.strategy = deletion_strategy_for(cleaner)
38
+ cleaner
39
+ end
40
+
41
+ def strategy_name_for(cleaner)
42
+ cleaner # <DatabaseCleaner::Cleaner>
43
+ .strategy # <DatabaseCleaner::ActiveRecord::Truncation>
44
+ .class # DatabaseCleaner::ActiveRecord::Truncation
45
+ .name # "DatabaseCleaner::ActiveRecord::Truncation"
46
+ .rpartition("::") # ["DatabaseCleaner::ActiveRecord", "::", "Truncation"]
47
+ .last # "Truncation"
48
+ .downcase # "truncation"
49
+ end
50
+
51
+ def deletion_strategy_for(cleaner)
52
+ strategy = cleaner.strategy
53
+ strategy_namespace = strategy # <DatabaseCleaner::ActiveRecord::Truncation>
54
+ .class # DatabaseCleaner::ActiveRecord::Truncation
55
+ .name # "DatabaseCleaner::ActiveRecord::Truncation"
56
+ .rpartition("::") # ["DatabaseCleaner::ActiveRecord", "::", "Truncation"]
57
+ .first # "DatabaseCleaner::ActiveRecord"
58
+ deletion_strategy_class_name = [strategy_namespace, "::", "Deletion"].join
59
+ deletion_strategy_class = deletion_strategy_class_name.constantize
60
+ instance_variable_hash = strategy.instance_variables.map do |var|
61
+ [
62
+ var.to_s.remove("@"),
63
+ strategy.instance_variable_get(var)
64
+ ]
65
+ end.to_h
66
+ options = instance_variable_hash.except("db", "connection_class")
67
+
68
+ deletion_strategy_class.new(**options)
18
69
  end
19
70
  end
20
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "1.0.0.pre7"
4
+ VERSION = "1.0.0.pre8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acidic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre7
4
+ version: 1.0.0.pre8
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-11 00:00:00.000000000 Z
11
+ date: 2022-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord