test-prof 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e1623dde5386ea71184b81cf99eb67ac377613d46b2ebac3ce874164103fcbd
4
- data.tar.gz: 1b9fa94cb2616226019cbc57ee8dbefa5c03db8f42f0be277352884ab6dfdb48
3
+ metadata.gz: 9680aa33c1d917182a0be6e8cfd0656149d510b634db637b8023feda29f10886
4
+ data.tar.gz: 721767f61684ed87eff0f2e4c62080b9bb2a9e24bf6f47db194fc687bedbbe9b
5
5
  SHA512:
6
- metadata.gz: 7eeec86920c82c3afb8b89478b3992bf1750fdacd949913c0a6c18a684bcefb5998880e4da2cecec1c8d5866dcc89b8a16de31e7e881713f8a4707aa08b25fd6
7
- data.tar.gz: 793ec788e3cb95c29b8b3b1a9026db05e64d1ae828ca2ce8a180ffc460cf3d653710b2c4356e47d0dbc3aa8a3fd5ea633502fa5c0f0114a467a5dd01ae99b5b5
6
+ metadata.gz: 5a1d037cdac034f7c58f7bd090de128a81d41c3927787c953cacd33e8ecec1dd11cbda282f64fd542c2679b5176aa7bce4fe2ecb49806abac895d2cf9f478c00
7
+ data.tar.gz: baf837db1165a0d5631f07c9f4a978234afcce65fd9be886ef80bcf0a020fd43926e57eb5f295f0daddb22027c821ee72960fb01cd2cd4c7db6d18100d404343
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.0.9 (2022-05-05)
6
+
7
+ - Add `AnyFixture.before_fixtures_reset` and `AnyFixture.after_fixtures_reset` callbacks. ([@ruslanshakirov][])
8
+
9
+ - Fixes ActiveRecord 6.1 issue with AnyFixture and Postgres config ([@markedmondson][])
10
+
5
11
  ## 1.0.8 (2022-03-11)
6
12
 
7
13
  - Restore the lock_thread value after rollback. ([@cou929][])
@@ -277,3 +283,4 @@ See [changelog](https://github.com/test-prof/test-prof/blob/v0.8.0/CHANGELOG.md)
277
283
  [@alexvko]: https://github.com/alexvko
278
284
  [@grillermo]: https://github.com/grillermo
279
285
  [@cou929]: https://github.com/cou929
286
+ [@ruslanshakirov]: https://github.com/ruslanshakirov
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TestProf
4
4
  module AnyFixture
5
- # Adds "global" `fixture` method (through refinement)
5
+ # Adds "global" `fixture`, `before_fixtures_reset` and `after_fixtures_reset` methods (through refinement)
6
6
  module DSL
7
7
  # Refine object, 'cause refining modules (Kernel) is vulnerable to prepend:
8
8
  # - https://bugs.ruby-lang.org/issues/13446
@@ -11,6 +11,14 @@ module TestProf
11
11
  def fixture(id, &block)
12
12
  ::TestProf::AnyFixture.register(:"#{id}", &block)
13
13
  end
14
+
15
+ def before_fixtures_reset(&block)
16
+ ::TestProf::AnyFixture.before_fixtures_reset(&block)
17
+ end
18
+
19
+ def after_fixtures_reset(&block)
20
+ ::TestProf::AnyFixture.after_fixtures_reset(&block)
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -30,7 +30,7 @@ module TestProf
30
30
  # Test if psql is installed
31
31
  `psql --version`
32
32
 
33
- tasks = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(conn.pool.spec.config.with_indifferent_access)
33
+ tasks = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(config)
34
34
 
35
35
  while_disconnected do
36
36
  tasks.structure_load(path, "--output=/dev/null")
@@ -85,6 +85,15 @@ module TestProf
85
85
  def execute(query)
86
86
  super.values
87
87
  end
88
+
89
+ def config
90
+ conn_pool = conn.pool
91
+ if conn_pool.respond_to?(:spec) # Support for Rails < 6.1
92
+ conn_pool.spec.config
93
+ else
94
+ conn_pool.db_config
95
+ end
96
+ end
88
97
  end
89
98
  end
90
99
  end
@@ -119,6 +119,8 @@ module TestProf
119
119
  # returns the result of the block execution
120
120
  def register(id)
121
121
  cached(id) do
122
+ raise "No fixture named #{id} has been registered" unless block_given?
123
+
122
124
  ActiveSupport::Notifications.subscribed(method(:subscriber), "sql.active_record") do
123
125
  yield
124
126
  end
@@ -175,9 +177,22 @@ module TestProf
175
177
 
176
178
  # Reset all information and clean tables
177
179
  def reset
180
+ callbacks[:before_fixtures_reset].each(&:call)
181
+
178
182
  clean
179
183
  tables_cache.clear
180
184
  cache.clear
185
+
186
+ callbacks[:after_fixtures_reset].each(&:call)
187
+ callbacks.clear
188
+ end
189
+
190
+ def before_fixtures_reset(&block)
191
+ callbacks[:before_fixtures_reset] << block
192
+ end
193
+
194
+ def after_fixtures_reset(&block)
195
+ callbacks[:after_fixtures_reset] << block
181
196
  end
182
197
 
183
198
  def subscriber(_event, _start, _finish, _id, data)
@@ -254,6 +269,10 @@ module TestProf
254
269
  @tables_cache ||= {}
255
270
  end
256
271
 
272
+ def callbacks
273
+ @callbacks ||= Hash.new { |h, k| h[k] = [] }
274
+ end
275
+
257
276
  def disable_referential_integrity
258
277
  connection = ActiveRecord::Base.connection
259
278
  return yield unless connection.respond_to?(:disable_referential_integrity)
@@ -48,14 +48,15 @@ module RuboCop
48
48
 
49
49
  def transform_its(body, arguments)
50
50
  argument = arguments.first
51
- replacement = case argument.type
52
- when :array
53
- key = argument.values.first
54
- "expect(subject[#{key.source}])"
55
- else
56
- property = argument.value
57
- "expect(subject.#{property})"
58
- end
51
+ replacement =
52
+ case argument.type
53
+ when :array
54
+ key = argument.values.first
55
+ "expect(subject[#{key.source}])"
56
+ else
57
+ property = argument.value
58
+ "expect(subject.#{property})"
59
+ end
59
60
  body.source.gsub(/is_expected|are_expected/, replacement)
60
61
  end
61
62
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestProf
4
- VERSION = "1.0.8"
4
+ VERSION = "1.0.9"
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.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler