test-prof 1.4.2 → 1.4.3

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: db12b48471cc8814d90d2388415798a742a5b5d69f61862bc88c12ac118e80c2
4
- data.tar.gz: 9c930443a46e765d13b4528725d795aef8e4a2ab9b9c2c7a3939e2cb458ebd03
3
+ metadata.gz: 97628c14c29719b463c2937602d31e201bafcf3f910b94fb11ee28bd8f23aaf5
4
+ data.tar.gz: 4f924233ae1dfeb81bcca92624c741980c8d7c07a5a02d88909a08685a1980d4
5
5
  SHA512:
6
- metadata.gz: 6fe1ff6102261d0b8c3c9e88e982255996b01ec6a34a9bc0d812a5021e8dd193aba57feca87d467c99f93973e98ed4cc4e94c94e8e1ab2e7b61dce806eeebedc
7
- data.tar.gz: db01e089936817767666c9d8d8fc11c0e2765bbb254be6e1baa5fac3ab26de7ad6d2b937dca7c6f0bef72fb60045caef2e909bf196978ebe94aef0c7f54da1c4
6
+ metadata.gz: 865839f6c518c531be8c41701beb5714fadbbd1824cb96af8509e7a6b601973551a1bbdd0019000df001c82916c12d1232ee9caefeeb1be2eef384056f57da8a
7
+ data.tar.gz: 775d73f88529efdf0c3ad9d93354b0ca18c58640a2fc958d9615773b16f53776d8006d93a1c3094fd02f57bd2d1a412edd35e955369ed477f3102e6a443a1556
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.4.3 (2024-12-18)
6
+
7
+ - Fix handling new (lazy) connection pools in `before_all`. ([@palkan][])
8
+
9
+ - Updates Rubocop::Cop code to comply with most modern API. ([@aseroff][])
10
+
5
11
  ## 1.4.2 (2024-09-03) 🗓️
6
12
 
7
13
  - Ignore default scopes in `ActiveRecord::Base#refind`. ([@palkan][])
@@ -69,7 +69,7 @@ module TestProf
69
69
  end
70
70
 
71
71
  def commit
72
- return unless defined?(:@file)
72
+ return unless instance_variable_defined?(:@file)
73
73
 
74
74
  file.close
75
75
 
@@ -10,6 +10,7 @@ module TestProf
10
10
  class << self
11
11
  if ::ActiveRecord::Base.connection.pool.respond_to?(:pin_connection!)
12
12
  def begin_transaction
13
+ subscribe!
13
14
  ::ActiveRecord::Base.connection_handler.connection_pool_list(:writing).each do |pool|
14
15
  pool.pin_connection!(true)
15
16
  end
@@ -19,6 +20,26 @@ module TestProf
19
20
  ::ActiveRecord::Base.connection_handler.connection_pool_list(:writing).each do |pool|
20
21
  pool.unpin_connection!
21
22
  end
23
+ unsubscribe!
24
+ end
25
+
26
+ def subscribe!
27
+ Thread.current[:before_all_connection_subscriber] = ActiveSupport::Notifications.subscribe("!connection.active_record") do |_, _, _, _, payload|
28
+ connection_name = payload[:connection_name] if payload.key?(:connection_name)
29
+ shard = payload[:shard] if payload.key?(:shard)
30
+ next unless connection_name
31
+
32
+ pool = ::ActiveRecord::Base.connection_handler.retrieve_connection_pool(connection_name, shard: shard)
33
+ next unless pool && pool.role == :writing
34
+
35
+ pool.pin_connection!(true)
36
+ end
37
+ end
38
+
39
+ def unsubscribe!
40
+ return unless Thread.current[:before_all_connection_subscriber]
41
+ ActiveSupport::Notifications.unsubscribe(Thread.current[:before_all_connection_subscriber])
42
+ Thread.current[:before_all_connection_subscriber] = nil
22
43
  end
23
44
  else
24
45
  def all_connections
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- class AggregateExamples < ::RuboCop::Cop::Cop
6
+ class AggregateExamples < ::RuboCop::Cop::Base
7
7
  # @example `its`
8
8
  #
9
9
  # # Supports regular `its` call with an attribute/method name,
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- class AggregateExamples < ::RuboCop::Cop::Cop
6
+ class AggregateExamples < ::RuboCop::Cop::Base
7
7
  # @internal Support methods for keeping newlines around examples.
8
8
  module LineRangeHelpers
9
9
  include RangeHelp
@@ -5,7 +5,7 @@ require "test_prof/cops/rspec/language"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module RSpec
8
- class AggregateExamples < ::RuboCop::Cop::Cop
8
+ class AggregateExamples < ::RuboCop::Cop::Base
9
9
  # When aggregated, the expectations will fail when not supposed to or
10
10
  # have a risk of not failing when expected to. One example is
11
11
  # `validate_presence_of :comment` as it leaves an empty comment after
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- class AggregateExamples < ::RuboCop::Cop::Cop
6
+ class AggregateExamples < ::RuboCop::Cop::Base
7
7
  # @internal
8
8
  # Support methods for example metadata.
9
9
  # Examples with similar metadata are grouped.
@@ -5,7 +5,7 @@ require "test_prof/cops/rspec/language"
5
5
  module RuboCop
6
6
  module Cop
7
7
  module RSpec
8
- class AggregateExamples < ::RuboCop::Cop::Cop
8
+ class AggregateExamples < ::RuboCop::Cop::Base
9
9
  # @internal
10
10
  # Node matchers and searchers.
11
11
  module NodeMatchers
@@ -108,7 +108,8 @@ module RuboCop
108
108
  # expect(number).to be_odd
109
109
  # end
110
110
  #
111
- class AggregateExamples < ::RuboCop::Cop::Cop
111
+ class AggregateExamples < ::RuboCop::Cop::Base
112
+ extend AutoCorrector
112
113
  include LineRangeHelpers
113
114
  include MetadataHelpers
114
115
  include NodeMatchers
@@ -123,29 +124,22 @@ module RuboCop
123
124
  def on_block(node)
124
125
  example_group_with_several_examples(node) do |all_examples|
125
126
  example_clusters(all_examples).each do |_, examples|
126
- examples[1..].each do |example|
127
+ examples.drop(1).each do |example|
127
128
  add_offense(example,
128
- location: :expression,
129
- message: message_for(example, examples[0]))
129
+ message: message_for(example, examples[0])) do |corrector|
130
+ clusters = example_clusters_for_autocorrect(example)
131
+ clusters.each do |metadata, examples|
132
+ range = range_for_replace(examples)
133
+ replacement = aggregated_example(examples, metadata)
134
+ corrector.replace(range, replacement)
135
+ examples.drop(1).map { |example| drop_example(corrector, example) }
136
+ end
137
+ end
130
138
  end
131
139
  end
132
140
  end
133
141
  end
134
142
 
135
- def autocorrect(example_node)
136
- clusters = example_clusters_for_autocorrect(example_node)
137
- return if clusters.empty?
138
-
139
- lambda do |corrector|
140
- clusters.each do |metadata, examples|
141
- range = range_for_replace(examples)
142
- replacement = aggregated_example(examples, metadata)
143
- corrector.replace(range, replacement)
144
- examples[1..].map { |example| drop_example(corrector, example) }
145
- end
146
- end
147
- end
148
-
149
143
  private
150
144
 
151
145
  # Clusters of examples in the same example group, on the same nesting
@@ -105,10 +105,9 @@ module TestProf
105
105
  # Do not analyze code within the block
106
106
  def ignore
107
107
  @ignored = true
108
- res = yield
108
+ yield
109
109
  ensure
110
110
  @ignored = false
111
- res
112
111
  end
113
112
 
114
113
  def ignore!
@@ -104,7 +104,7 @@ module TestProf
104
104
  if base.respond_to?(:parallelize_teardown)
105
105
  base.parallelize_teardown do
106
106
  last_klass = ::Minitest.previous_klass
107
- if last_klass&.respond_to?(:parallelized) && last_klass&.parallelized
107
+ if last_klass&.respond_to?(:parallelized) && last_klass.parallelized
108
108
  last_klass.before_all_executor&.deactivate!
109
109
  end
110
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.4.2"
4
+ VERSION = "1.4.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-03 00:00:00.000000000 Z
11
+ date: 2024-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler