delayed 2.0.3 → 2.2.0

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.
data/spec/helper.rb CHANGED
@@ -38,13 +38,12 @@ end
38
38
 
39
39
  ENV['RAILS_ENV'] = 'test'
40
40
 
41
- db_adapter = ENV["ADAPTER"]
42
- gemfile = ENV["BUNDLE_GEMFILE"]
43
- db_adapter ||= gemfile && gemfile[%r{gemfiles/(.*?)/}] && $1 # rubocop:disable Style/PerlBackrefs
44
- db_adapter ||= "sqlite3"
41
+ def current_adapter
42
+ ENV.fetch('ADAPTER', 'sqlite3')
43
+ end
45
44
 
46
45
  config = YAML.load(ERB.new(File.read("spec/database.yml")).result)
47
- ActiveRecord::Base.establish_connection config[db_adapter]
46
+ ActiveRecord::Base.establish_connection config[current_adapter]
48
47
  ActiveRecord::Base.logger = Delayed.logger
49
48
  ActiveJob::Base.logger = Delayed.logger
50
49
  ActiveRecord::Migration.verbose = false
@@ -58,7 +57,7 @@ end
58
57
  # MySQL 5.7 no longer supports null default values for the primary key
59
58
  # Override the default primary key type in Rails <= 4.0
60
59
  # https://stackoverflow.com/a/34555109
61
- if db_adapter == "mysql2"
60
+ if current_adapter == "mysql2"
62
61
  types = if defined?(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
63
62
  # ActiveRecord 3.2+
64
63
  ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES
@@ -208,6 +207,14 @@ else
208
207
  ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
209
208
  end
210
209
 
210
+ def default_timezone=(zone)
211
+ if ActiveRecord::VERSION::MAJOR >= 7
212
+ ActiveRecord.default_timezone = zone
213
+ else
214
+ ActiveRecord::Base.default_timezone = zone
215
+ end
216
+ end
217
+
211
218
  RSpec::Matchers.define :emit_notification do |expected_event_name|
212
219
  attr_reader :actual, :expected
213
220
 
@@ -217,10 +224,12 @@ RSpec::Matchers.define :emit_notification do |expected_event_name|
217
224
 
218
225
  chain :with_payload, :expected_payload
219
226
  chain :with_value, :expected_value
227
+ chain(:approximately) { @approximately = true }
220
228
  diffable
221
229
 
222
230
  match do |block|
223
- @expected = { event_name: expected_event_name, payload: expected_payload, value: expected_value }
231
+ @expected_value = a_value_within([2, @expected_value.abs * 0.05].max).of(@expected_value) if @approximately
232
+ @expected = { event_name: expected_event_name, payload: expected_payload, value: @expected_value }
224
233
  @actuals = []
225
234
  callback = ->(name, _started, _finished, _unique_id, payload) do
226
235
  @actuals << { event_name: name, payload: payload.except(:value), value: payload[:value] }
@@ -249,10 +258,6 @@ RSpec::Matchers.define :emit_notification do |expected_event_name|
249
258
  end
250
259
  end
251
260
 
252
- def current_adapter
253
- ENV.fetch('ADAPTER', 'sqlite3')
254
- end
255
-
256
261
  def current_database
257
262
  if current_adapter == 'sqlite3'
258
263
  a_string_ending_with('tmp/database.sqlite')
@@ -266,6 +271,10 @@ QueryUnderTest = Struct.new(:sql, :connection) do
266
271
  new(query.respond_to?(:to_sql) ? query.to_sql : query.to_s, connection)
267
272
  end
268
273
 
274
+ def full_description
275
+ [formatted, explain].join("\n\n")
276
+ end
277
+
269
278
  def formatted
270
279
  fmt = sql.squish
271
280
 
@@ -279,6 +288,8 @@ QueryUnderTest = Struct.new(:sql, :connection) do
279
288
  .gsub(/ (AND|OR) /) { "\n #{Regexp.last_match(1).strip} " }
280
289
  # normalize and truncate 'AS' names/aliases (changes across Rails versions)
281
290
  .gsub(/AS ("|`)?(\w+)("|`)?/) { "AS #{Regexp.last_match(2)[0...63]}" }
291
+ # newline and indent when aliased columns are listed
292
+ .gsub(/AS (\w+),/) { "AS #{Regexp.last_match(1)},\n " }
282
293
  # remove quotes around column names in aggregate functions
283
294
  .gsub(/(MIN|MAX|COUNT|SUM)\(("|`)(\w+)("|`)\)/) { "#{Regexp.last_match(1)}(#{Regexp.last_match(3)})" }
284
295
  end
@@ -303,7 +314,7 @@ QueryUnderTest = Struct.new(:sql, :connection) do
303
314
  end
304
315
 
305
316
  def mysql2_explain
306
- seed_rows! # MySQL needs a bit of data to reach for indexes
317
+ seed_rows! if Delayed::Job.none? # MySQL needs a bit of data to reach for indexes
307
318
  connection.execute("ANALYZE TABLE #{Delayed::Job.table_name}")
308
319
  connection.execute("SET SESSION max_seeks_for_key = 1")
309
320
  connection.execute("EXPLAIN FORMAT=TREE #{sql}").to_a.map(&:first).join("\n")
@@ -317,7 +328,7 @@ QueryUnderTest = Struct.new(:sql, :connection) do
317
328
 
318
329
  def seed_rows!
319
330
  now = Delayed::Job.db_time_now
320
- 10.times do
331
+ 100.times do
321
332
  [true, false].repeated_combination(5).each_with_index do |(erroring, failed, locked, future), i|
322
333
  Delayed::Job.create!(
323
334
  run_at: now + (future ? i.minutes : -i.minutes),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Griffith
@@ -19,7 +19,7 @@ authors:
19
19
  autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
- date: 2026-02-02 00:00:00.000000000 Z
22
+ date: 2026-02-12 00:00:00.000000000 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: activerecord