diff options
Diffstat (limited to 'activejob')
100 files changed, 539 insertions, 15 deletions
diff --git a/activejob/Rakefile b/activejob/Rakefile index 5d0d22e88b..6f13ef449d 100644 --- a/activejob/Rakefile +++ b/activejob/Rakefile @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rake/testtask" #TODO: add qu back to the list after it support Rails 5.1 diff --git a/activejob/activejob.gemspec b/activejob/activejob.gemspec index d3fe7b45e7..71e32f695b 100644 --- a/activejob/activejob.gemspec +++ b/activejob/activejob.gemspec @@ -1,4 +1,5 @@ # frozen_string_literal: true + version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip Gem::Specification.new do |s| diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb index d6e21bf372..56dab66544 100644 --- a/activejob/lib/active_job.rb +++ b/activejob/lib/active_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + #-- # Copyright (c) 2014-2017 David Heinemeier Hansson # diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb index dde7d7afa6..de11e7fcb1 100644 --- a/activejob/lib/active_job/arguments.rb +++ b/activejob/lib/active_job/arguments.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/hash" module ActiveJob diff --git a/activejob/lib/active_job/base.rb b/activejob/lib/active_job/base.rb index 96d47ac19f..6af41260db 100644 --- a/activejob/lib/active_job/base.rb +++ b/activejob/lib/active_job/base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "core" require_relative "queue_adapter" require_relative "queue_name" diff --git a/activejob/lib/active_job/callbacks.rb b/activejob/lib/active_job/callbacks.rb index ab225a93d3..334b24fb3b 100644 --- a/activejob/lib/active_job/callbacks.rb +++ b/activejob/lib/active_job/callbacks.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/callbacks" module ActiveJob diff --git a/activejob/lib/active_job/configured_job.rb b/activejob/lib/active_job/configured_job.rb index 79c197d531..67daf48b36 100644 --- a/activejob/lib/active_job/configured_job.rb +++ b/activejob/lib/active_job/configured_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob class ConfiguredJob #:nodoc: def initialize(job_class, options = {}) diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb index 7f1d4efc65..c4e12fc518 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob # Provides general behavior that will be included into every Active Job # object that inherits from ActiveJob::Base. diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index 0c38200b76..ad32d3065b 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "arguments" module ActiveJob diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb index 3a91cbc0b6..dfc74deb1a 100644 --- a/activejob/lib/active_job/exceptions.rb +++ b/activejob/lib/active_job/exceptions.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/numeric/time" module ActiveJob diff --git a/activejob/lib/active_job/execution.rb b/activejob/lib/active_job/execution.rb index d4e068d6ec..85e050b489 100644 --- a/activejob/lib/active_job/execution.rb +++ b/activejob/lib/active_job/execution.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/rescuable" require_relative "arguments" diff --git a/activejob/lib/active_job/gem_version.rb b/activejob/lib/active_job/gem_version.rb index 0e414f1b11..7ee61780e1 100644 --- a/activejob/lib/active_job/gem_version.rb +++ b/activejob/lib/active_job/gem_version.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob # Returns the version of the currently loaded Active Job as a <tt>Gem::Version</tt> def self.gem_version diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb index 8f8f4cb244..f53b7eaee5 100644 --- a/activejob/lib/active_job/logging.rb +++ b/activejob/lib/active_job/logging.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/hash/transform_values" require "active_support/core_ext/string/filters" require "active_support/tagged_logging" diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb index 8f4d40de19..dd05800baf 100644 --- a/activejob/lib/active_job/queue_adapter.rb +++ b/activejob/lib/active_job/queue_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/string/inflections" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters.rb b/activejob/lib/active_job/queue_adapters.rb index b89a62319a..c1a1d3c510 100644 --- a/activejob/lib/active_job/queue_adapters.rb +++ b/activejob/lib/active_job/queue_adapters.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob # == Active Job adapters # diff --git a/activejob/lib/active_job/queue_adapters/async_adapter.rb b/activejob/lib/active_job/queue_adapters/async_adapter.rb index d2fc686339..eec9ae08bb 100644 --- a/activejob/lib/active_job/queue_adapters/async_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/async_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "securerandom" require "concurrent/scheduled_task" require "concurrent/executor/thread_pool_executor" diff --git a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb index 63519df551..0ba93c6e0b 100644 --- a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "backburner" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb b/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb index 54a5af2ae6..1978179948 100644 --- a/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "delayed_job" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters/inline_adapter.rb b/activejob/lib/active_job/queue_adapters/inline_adapter.rb index e793fff89d..3d0b590212 100644 --- a/activejob/lib/active_job/queue_adapters/inline_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/inline_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob module QueueAdapters # == Active Job Inline adapter diff --git a/activejob/lib/active_job/queue_adapters/qu_adapter.rb b/activejob/lib/active_job/queue_adapters/qu_adapter.rb index 9b2072f611..bd7003e177 100644 --- a/activejob/lib/active_job/queue_adapters/qu_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/qu_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "qu" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters/que_adapter.rb b/activejob/lib/active_job/queue_adapters/que_adapter.rb index e72899a1cb..86b5e07743 100644 --- a/activejob/lib/active_job/queue_adapters/que_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/que_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "que" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters/queue_classic_adapter.rb b/activejob/lib/active_job/queue_adapters/queue_classic_adapter.rb index 53fb0d83b4..ccc1881091 100644 --- a/activejob/lib/active_job/queue_adapters/queue_classic_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/queue_classic_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "queue_classic" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters/resque_adapter.rb b/activejob/lib/active_job/queue_adapters/resque_adapter.rb index f9cefd3c33..590b4ee98d 100644 --- a/activejob/lib/active_job/queue_adapters/resque_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/resque_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "resque" require "active_support/core_ext/enumerable" require "active_support/core_ext/array/access" diff --git a/activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb b/activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb index 35f399b0f0..5a1135854b 100644 --- a/activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "sidekiq" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb b/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb index 972ff5af0f..de98a950d0 100644 --- a/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "sneakers" require "monitor" diff --git a/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb b/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb index 2ba9372f4f..d09e1e9143 100644 --- a/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "sucker_punch" module ActiveJob diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index 5972b28156..885f9ff01c 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob module QueueAdapters # == Test adapter for Active Job @@ -11,7 +12,7 @@ module ActiveJob # # Rails.application.config.active_job.queue_adapter = :test class TestAdapter - attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter) + attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject) attr_writer(:enqueued_jobs, :performed_jobs) # Provides a store of all the enqueued jobs with the TestAdapter so you can check them. @@ -53,7 +54,13 @@ module ActiveJob end def filtered?(job) - filter && !Array(filter).include?(job.class) + if filter + !Array(filter).include?(job.class) + elsif reject + Array(reject).include?(job.class) + else + false + end end end end diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index 22ebd5e3fc..9dc6bc7f2e 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob module QueueName extend ActiveSupport::Concern diff --git a/activejob/lib/active_job/queue_priority.rb b/activejob/lib/active_job/queue_priority.rb index fd1c0f6286..063bccdb01 100644 --- a/activejob/lib/active_job/queue_priority.rb +++ b/activejob/lib/active_job/queue_priority.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob module QueuePriority extend ActiveSupport::Concern diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index 8adbd3473c..7b0742a6d2 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "global_id/railtie" require "active_job" diff --git a/activejob/lib/active_job/test_case.rb b/activejob/lib/active_job/test_case.rb index 028ff552bf..49cd51bdd0 100644 --- a/activejob/lib/active_job/test_case.rb +++ b/activejob/lib/active_job/test_case.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/test_case" module ActiveJob diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 60ca1b5f1b..1cd2c40c15 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/class/subclasses" require "active_support/core_ext/hash/keys" @@ -88,7 +89,7 @@ module ActiveJob # end # end # - # The number of times a specific job is enqueued can be asserted. + # The number of times a specific job was enqueued can be asserted. # # def test_logging_job # assert_enqueued_jobs 1, only: LoggingJob do @@ -97,6 +98,15 @@ module ActiveJob # end # end # + # The number of times a job except specific class was enqueued can be asserted. + # + # def test_logging_job + # assert_enqueued_jobs 1, except: HelloJob do + # LoggingJob.perform_later + # HelloJob.perform_later('jeremy') + # end + # end + # # The number of times a job is enqueued to a specific queue can also be asserted. # # def test_logging_job @@ -105,14 +115,14 @@ module ActiveJob # HelloJob.perform_later('elfassy') # end # end - def assert_enqueued_jobs(number, only: nil, queue: nil) + def assert_enqueued_jobs(number, only: nil, except: nil, queue: nil) if block_given? - original_count = enqueued_jobs_size(only: only, queue: queue) + original_count = enqueued_jobs_size(only: only, except: except, queue: queue) yield - new_count = enqueued_jobs_size(only: only, queue: queue) + new_count = enqueued_jobs_size(only: only, except: except, queue: queue) assert_equal number, new_count - original_count, "#{number} jobs expected, but #{new_count - original_count} were enqueued" else - actual_count = enqueued_jobs_size(only: only, queue: queue) + actual_count = enqueued_jobs_size(only: only, except: except, queue: queue) assert_equal number, actual_count, "#{number} jobs expected, but #{actual_count} were enqueued" end end @@ -141,11 +151,19 @@ module ActiveJob # end # end # + # It can be asserted that no jobs except specific class are enqueued: + # + # def test_no_logging + # assert_no_enqueued_jobs except: HelloJob do + # HelloJob.perform_later('jeremy') + # end + # end + # # Note: This assertion is simply a shortcut for: # # assert_enqueued_jobs 0, &block - def assert_no_enqueued_jobs(only: nil, &block) - assert_enqueued_jobs 0, only: only, &block + def assert_no_enqueued_jobs(only: nil, except: nil, &block) + assert_enqueued_jobs 0, only: only, except: except, &block end # Asserts that the number of performed jobs matches the given number. @@ -190,6 +208,16 @@ module ActiveJob # end # end # + # Also if the :except option is specified, + # then the job(s) except specific class will be performed. + # + # def test_hello_job + # assert_performed_jobs 1, except: LoggingJob do + # HelloJob.perform_later('jeremy') + # LoggingJob.perform_later + # end + # end + # # An array may also be specified, to support testing multiple jobs. # # def test_hello_and_logging_jobs @@ -201,10 +229,10 @@ module ActiveJob # end # end # end - def assert_performed_jobs(number, only: nil) + def assert_performed_jobs(number, only: nil, except: nil) if block_given? original_count = performed_jobs.size - perform_enqueued_jobs(only: only) { yield } + perform_enqueued_jobs(only: only, except: except) { yield } new_count = performed_jobs.size assert_equal number, new_count - original_count, "#{number} jobs expected, but #{new_count - original_count} were performed" @@ -242,11 +270,20 @@ module ActiveJob # end # end # + # Also if the :except option is specified, + # then the job(s) except specific class will not be performed. + # + # def test_no_logging + # assert_no_performed_jobs except: HelloJob do + # HelloJob.perform_later('jeremy') + # end + # end + # # Note: This assertion is simply a shortcut for: # # assert_performed_jobs 0, &block - def assert_no_performed_jobs(only: nil, &block) - assert_performed_jobs 0, only: only, &block + def assert_no_performed_jobs(only: nil, except: nil, &block) + assert_performed_jobs 0, only: only, except: except, &block end # Asserts that the job passed in the block has been enqueued with the given arguments. @@ -316,20 +353,36 @@ module ActiveJob # end # assert_performed_jobs 1 # end - def perform_enqueued_jobs(only: nil) + # + # Also if the +:except+ option is specified, + # then the job(s) except specific class will be performed. + # + # def test_perform_enqueued_jobs_with_except + # perform_enqueued_jobs(except: HelloJob) do + # MyJob.perform_later(1, 2, 3) # will be performed + # HelloJob.perform_later(1, 2, 3) # will not be performed + # end + # assert_performed_jobs 1 + # end + # + def perform_enqueued_jobs(only: nil, except: nil) + validate_option(only: only, except: except) old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs old_filter = queue_adapter.filter + old_reject = queue_adapter.reject begin queue_adapter.perform_enqueued_jobs = true queue_adapter.perform_enqueued_at_jobs = true queue_adapter.filter = only + queue_adapter.reject = except yield ensure queue_adapter.perform_enqueued_jobs = old_perform_enqueued_jobs queue_adapter.perform_enqueued_at_jobs = old_perform_enqueued_at_jobs queue_adapter.filter = old_filter + queue_adapter.reject = old_reject end end @@ -351,11 +404,14 @@ module ActiveJob performed_jobs.clear end - def enqueued_jobs_size(only: nil, queue: nil) + def enqueued_jobs_size(only: nil, except: nil, queue: nil) + validate_option(only: only, except: except) enqueued_jobs.count do |job| job_class = job.fetch(:job) if only next false unless Array(only).include?(job_class) + elsif except + next false if Array(except).include?(job_class) end if queue next false unless queue.to_s == job.fetch(:queue, job_class.queue_name) @@ -384,5 +440,9 @@ module ActiveJob klass.singleton_class.public_instance_methods(false).include?(:_queue_adapter) end end + + def validate_option(only: nil, except: nil) + raise ArgumentError, "Cannot specify both `:only` and `:except` options." if only && except + end end end diff --git a/activejob/lib/active_job/translation.rb b/activejob/lib/active_job/translation.rb index 71c4cb24af..fb45c80d67 100644 --- a/activejob/lib/active_job/translation.rb +++ b/activejob/lib/active_job/translation.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ActiveJob module Translation #:nodoc: extend ActiveSupport::Concern diff --git a/activejob/lib/active_job/version.rb b/activejob/lib/active_job/version.rb index afff4271d4..eae7da4d05 100644 --- a/activejob/lib/active_job/version.rb +++ b/activejob/lib/active_job/version.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "gem_version" module ActiveJob diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb index dce4e3a3fe..69b4fe7d26 100644 --- a/activejob/lib/rails/generators/job/job_generator.rb +++ b/activejob/lib/rails/generators/job/job_generator.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails/generators/named_base" module Rails # :nodoc: diff --git a/activejob/test/adapters/async.rb b/activejob/test/adapters/async.rb index d5a61d7684..a4fed7c2f7 100644 --- a/activejob/test/adapters/async.rb +++ b/activejob/test/adapters/async.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + ActiveJob::Base.queue_adapter = :async ActiveJob::Base.queue_adapter.immediate = true diff --git a/activejob/test/adapters/backburner.rb b/activejob/test/adapters/backburner.rb index cfc97432f2..bc34c78e9c 100644 --- a/activejob/test/adapters/backburner.rb +++ b/activejob/test/adapters/backburner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "support/backburner/inline" ActiveJob::Base.queue_adapter = :backburner diff --git a/activejob/test/adapters/delayed_job.rb b/activejob/test/adapters/delayed_job.rb index 3aa646555a..904b4c3f90 100644 --- a/activejob/test/adapters/delayed_job.rb +++ b/activejob/test/adapters/delayed_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveJob::Base.queue_adapter = :delayed_job $LOAD_PATH << File.expand_path("../support/delayed_job", __dir__) diff --git a/activejob/test/adapters/inline.rb b/activejob/test/adapters/inline.rb index ec3f0940e6..b1ddcb28f1 100644 --- a/activejob/test/adapters/inline.rb +++ b/activejob/test/adapters/inline.rb @@ -1,2 +1,3 @@ # frozen_string_literal: true + ActiveJob::Base.queue_adapter = :inline diff --git a/activejob/test/adapters/qu.rb b/activejob/test/adapters/qu.rb index f8e7eb624d..5b471fa347 100644 --- a/activejob/test/adapters/qu.rb +++ b/activejob/test/adapters/qu.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "qu-immediate" ActiveJob::Base.queue_adapter = :qu diff --git a/activejob/test/adapters/que.rb b/activejob/test/adapters/que.rb index 0d27bb8fc9..af77b0d4d1 100644 --- a/activejob/test/adapters/que.rb +++ b/activejob/test/adapters/que.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "support/que/inline" ActiveJob::Base.queue_adapter = :que diff --git a/activejob/test/adapters/queue_classic.rb b/activejob/test/adapters/queue_classic.rb index f57057c914..73902a5e62 100644 --- a/activejob/test/adapters/queue_classic.rb +++ b/activejob/test/adapters/queue_classic.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + require "support/queue_classic/inline" ActiveJob::Base.queue_adapter = :queue_classic diff --git a/activejob/test/adapters/resque.rb b/activejob/test/adapters/resque.rb index 6c732c1e33..ad84a49372 100644 --- a/activejob/test/adapters/resque.rb +++ b/activejob/test/adapters/resque.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + ActiveJob::Base.queue_adapter = :resque Resque.inline = true diff --git a/activejob/test/adapters/sidekiq.rb b/activejob/test/adapters/sidekiq.rb index 6cc64e7684..7df1c36488 100644 --- a/activejob/test/adapters/sidekiq.rb +++ b/activejob/test/adapters/sidekiq.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + require "sidekiq/testing/inline" ActiveJob::Base.queue_adapter = :sidekiq diff --git a/activejob/test/adapters/sneakers.rb b/activejob/test/adapters/sneakers.rb index 85f6b74144..38d82aa778 100644 --- a/activejob/test/adapters/sneakers.rb +++ b/activejob/test/adapters/sneakers.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + require "support/sneakers/inline" ActiveJob::Base.queue_adapter = :sneakers diff --git a/activejob/test/adapters/sucker_punch.rb b/activejob/test/adapters/sucker_punch.rb index 45b5fa1db2..04bad984d4 100644 --- a/activejob/test/adapters/sucker_punch.rb +++ b/activejob/test/adapters/sucker_punch.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + require "sucker_punch/testing/inline" ActiveJob::Base.queue_adapter = :sucker_punch diff --git a/activejob/test/adapters/test.rb b/activejob/test/adapters/test.rb index 965f7e91a2..0a1367dacf 100644 --- a/activejob/test/adapters/test.rb +++ b/activejob/test/adapters/test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ActiveJob::Base.queue_adapter = :test ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true diff --git a/activejob/test/cases/adapter_test.rb b/activejob/test/cases/adapter_test.rb index 764ce3ccbc..2c179b2d38 100644 --- a/activejob/test/cases/adapter_test.rb +++ b/activejob/test/cases/adapter_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" class AdapterTest < ActiveSupport::TestCase diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb index ebd9a4fe41..13e6fcb727 100644 --- a/activejob/test/cases/argument_serialization_test.rb +++ b/activejob/test/cases/argument_serialization_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "active_job/arguments" require "models/person" diff --git a/activejob/test/cases/callbacks_test.rb b/activejob/test/cases/callbacks_test.rb index fbca367ae9..df6ce16858 100644 --- a/activejob/test/cases/callbacks_test.rb +++ b/activejob/test/cases/callbacks_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/callback_job" diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index 5f56d47e8e..7a3c372143 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/retry_job" diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb index fa8d98ddca..440051c427 100644 --- a/activejob/test/cases/job_serialization_test.rb +++ b/activejob/test/cases/job_serialization_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/gid_job" require "jobs/hello_job" diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index 117d9b23a3..1f8c4a5573 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "active_support/log_subscriber/test_helper" require "active_support/core_ext/numeric/time" diff --git a/activejob/test/cases/queue_adapter_test.rb b/activejob/test/cases/queue_adapter_test.rb index 6061fb2127..e71cfa49cf 100644 --- a/activejob/test/cases/queue_adapter_test.rb +++ b/activejob/test/cases/queue_adapter_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" module ActiveJob diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 8ba4324c46..b64a38f91e 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/hello_job" require "jobs/logging_job" diff --git a/activejob/test/cases/queue_priority_test.rb b/activejob/test/cases/queue_priority_test.rb index 416498c270..4b3006ae81 100644 --- a/activejob/test/cases/queue_priority_test.rb +++ b/activejob/test/cases/queue_priority_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/hello_job" diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb index 44f674a2ee..0e843b7215 100644 --- a/activejob/test/cases/queuing_test.rb +++ b/activejob/test/cases/queuing_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/hello_job" require "active_support/core_ext/numeric/time" diff --git a/activejob/test/cases/rescue_test.rb b/activejob/test/cases/rescue_test.rb index c2a991cb2d..da9c87dbf0 100644 --- a/activejob/test/cases/rescue_test.rb +++ b/activejob/test/cases/rescue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/rescue_job" require "models/person" diff --git a/activejob/test/cases/test_case_test.rb b/activejob/test/cases/test_case_test.rb index eb320a98d1..4ae2add3a8 100644 --- a/activejob/test/cases/test_case_test.rb +++ b/activejob/test/cases/test_case_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/hello_job" require "jobs/logging_job" diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 0f8174663e..66bcd8f3a0 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "active_support/core_ext/time" require "active_support/core_ext/date" @@ -107,8 +108,31 @@ class EnqueuedJobsTest < ActiveJob::TestCase assert_enqueued_jobs 1, only: HelloJob do HelloJob.perform_later("jeremy") LoggingJob.perform_later + LoggingJob.perform_later + end + end + end + + def test_assert_enqueued_jobs_with_except_option + assert_nothing_raised do + assert_enqueued_jobs 1, except: LoggingJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + LoggingJob.perform_later + end + end + end + + def test_assert_enqueued_jobs_with_only_and_except_option + error = assert_raise ArgumentError do + assert_enqueued_jobs 1, only: HelloJob, except: HelloJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + LoggingJob.perform_later end end + + assert_match(/`:only` and `:except`/, error.message) end def test_assert_enqueued_jobs_with_only_and_queue_option @@ -121,6 +145,28 @@ class EnqueuedJobsTest < ActiveJob::TestCase end end + def test_assert_enqueued_jobs_with_except_and_queue_option + assert_nothing_raised do + assert_enqueued_jobs 1, except: LoggingJob, queue: :some_queue do + HelloJob.set(queue: :some_queue).perform_later + HelloJob.set(queue: :other_queue).perform_later + LoggingJob.perform_later + end + end + end + + def test_assert_enqueued_jobs_with_only_and_except_and_queue_option + error = assert_raise ArgumentError do + assert_enqueued_jobs 1, only: HelloJob, except: HelloJob, queue: :some_queue do + HelloJob.set(queue: :some_queue).perform_later + HelloJob.set(queue: :other_queue).perform_later + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_enqueued_jobs_with_queue_option assert_nothing_raised do assert_enqueued_jobs 2, queue: :default do @@ -142,6 +188,26 @@ class EnqueuedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 0/, error.message) end + def test_assert_enqueued_jobs_with_except_option_and_none_sent + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_enqueued_jobs 1, except: LoggingJob do + LoggingJob.perform_later + end + end + + assert_match(/1 .* but 0/, error.message) + end + + def test_assert_enqueued_jobs_with_only_and_except_option_and_none_sent + error = assert_raise ArgumentError do + assert_enqueued_jobs 1, only: HelloJob, except: HelloJob do + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_enqueued_jobs_with_only_option_and_too_few_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_enqueued_jobs 5, only: HelloJob do @@ -153,6 +219,28 @@ class EnqueuedJobsTest < ActiveJob::TestCase assert_match(/5 .* but 1/, error.message) end + def test_assert_enqueued_jobs_with_except_option_and_too_few_sent + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_enqueued_jobs 5, except: LoggingJob do + HelloJob.perform_later("jeremy") + 4.times { LoggingJob.perform_later } + end + end + + assert_match(/5 .* but 1/, error.message) + end + + def test_assert_enqueued_jobs_with_only_and_except_option_and_too_few_sent + error = assert_raise ArgumentError do + assert_enqueued_jobs 5, only: HelloJob, except: HelloJob do + HelloJob.perform_later("jeremy") + 4.times { LoggingJob.perform_later } + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_enqueued_jobs_with_only_option_and_too_many_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_enqueued_jobs 1, only: HelloJob do @@ -163,6 +251,26 @@ class EnqueuedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 2/, error.message) end + def test_assert_enqueued_jobs_with_except_option_and_too_many_sent + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_enqueued_jobs 1, except: LoggingJob do + 2.times { HelloJob.perform_later("jeremy") } + end + end + + assert_match(/1 .* but 2/, error.message) + end + + def test_assert_enqueued_jobs_with_only_and_except_option_and_too_many_sent + error = assert_raise ArgumentError do + assert_enqueued_jobs 1, only: HelloJob, except: HelloJob do + 2.times { HelloJob.perform_later("jeremy") } + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_enqueued_jobs_with_only_option_as_array assert_nothing_raised do assert_enqueued_jobs 2, only: [HelloJob, LoggingJob] do @@ -173,6 +281,28 @@ class EnqueuedJobsTest < ActiveJob::TestCase end end + def test_assert_enqueued_jobs_with_except_option_as_array + assert_nothing_raised do + assert_enqueued_jobs 1, except: [HelloJob, LoggingJob] do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("stewie") + RescueJob.perform_later("david") + end + end + end + + def test_assert_enqueued_jobs_with_only_and_except_option_as_array + error = assert_raise ArgumentError do + assert_enqueued_jobs 2, only: [HelloJob, LoggingJob], except: [HelloJob, LoggingJob] do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("stewie") + RescueJob.perform_later("david") + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_no_enqueued_jobs_with_only_option assert_nothing_raised do assert_no_enqueued_jobs only: HelloJob do @@ -181,6 +311,24 @@ class EnqueuedJobsTest < ActiveJob::TestCase end end + def test_assert_no_enqueued_jobs_with_except_option + assert_nothing_raised do + assert_no_enqueued_jobs except: LoggingJob do + LoggingJob.perform_later + end + end + end + + def test_assert_no_enqueued_jobs_with_only_and_except_option + error = assert_raise ArgumentError do + assert_no_enqueued_jobs only: HelloJob, except: HelloJob do + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_no_enqueued_jobs_with_only_option_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_enqueued_jobs only: HelloJob do @@ -192,6 +340,28 @@ class EnqueuedJobsTest < ActiveJob::TestCase assert_match(/0 .* but 1/, error.message) end + def test_assert_no_enqueued_jobs_with_except_option_failure + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_no_enqueued_jobs except: LoggingJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + end + end + + assert_match(/0 .* but 1/, error.message) + end + + def test_assert_no_enqueued_jobs_with_only_and_except_option_failure + error = assert_raise ArgumentError do + assert_no_enqueued_jobs only: HelloJob, except: HelloJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_no_enqueued_jobs_with_only_option_as_array assert_nothing_raised do assert_no_enqueued_jobs only: [HelloJob, RescueJob] do @@ -200,6 +370,25 @@ class EnqueuedJobsTest < ActiveJob::TestCase end end + def test_assert_no_enqueued_jobs_with_except_option_as_array + assert_nothing_raised do + assert_no_enqueued_jobs except: [HelloJob, RescueJob] do + HelloJob.perform_later + RescueJob.perform_later + end + end + end + + def test_assert_no_enqueued_jobs_with_only_and_except_option_as_array + error = assert_raise ArgumentError do + assert_no_enqueued_jobs only: [HelloJob, RescueJob], except: [HelloJob, RescueJob] do + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_enqueued_job assert_enqueued_with(job: LoggingJob, queue: "default") do LoggingJob.set(wait_until: Date.tomorrow.noon).perform_later @@ -285,6 +474,14 @@ class PerformedJobsTest < ActiveJob::TestCase assert_nil queue_adapter.filter end + def test_performed_enqueue_jobs_with_except_option_doesnt_leak_outside_the_block + assert_nil queue_adapter.reject + perform_enqueued_jobs except: HelloJob do + assert_equal HelloJob, queue_adapter.reject + end + assert_nil queue_adapter.reject + end + def test_assert_performed_jobs assert_nothing_raised do assert_performed_jobs 1 do @@ -390,6 +587,26 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_performed_jobs_with_except_option + assert_nothing_raised do + assert_performed_jobs 1, except: LoggingJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + end + end + end + + def test_assert_performed_jobs_with_only_and_except_option + error = assert_raise ArgumentError do + assert_performed_jobs 1, only: HelloJob, except: HelloJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_performed_jobs_with_only_option_as_array assert_nothing_raised do assert_performed_jobs 2, only: [HelloJob, LoggingJob] do @@ -400,6 +617,28 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_performed_jobs_with_except_option_as_array + assert_nothing_raised do + assert_performed_jobs 1, except: [LoggingJob, RescueJob] do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("stewie") + RescueJob.perform_later("david") + end + end + end + + def test_assert_performed_jobs_with_only_and_except_option_as_array + error = assert_raise ArgumentError do + assert_performed_jobs 2, only: [HelloJob, LoggingJob], except: [HelloJob, LoggingJob] do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("stewie") + RescueJob.perform_later("david") + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_performed_jobs_with_only_option_and_none_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_performed_jobs 1, only: HelloJob do @@ -410,6 +649,26 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 0/, error.message) end + def test_assert_performed_jobs_with_except_option_and_none_sent + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 1, except: LoggingJob do + LoggingJob.perform_later + end + end + + assert_match(/1 .* but 0/, error.message) + end + + def test_assert_performed_jobs_with_only_and_except_option_and_none_sent + error = assert_raise ArgumentError do + assert_performed_jobs 1, only: HelloJob, except: HelloJob do + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_performed_jobs_with_only_option_and_too_few_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_performed_jobs 5, only: HelloJob do @@ -421,6 +680,28 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/5 .* but 1/, error.message) end + def test_assert_performed_jobs_with_except_option_and_too_few_sent + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 5, except: LoggingJob do + HelloJob.perform_later("jeremy") + 4.times { LoggingJob.perform_later } + end + end + + assert_match(/5 .* but 1/, error.message) + end + + def test_assert_performed_jobs_with_only_and_except_option_and_too_few_sent + error = assert_raise ArgumentError do + assert_performed_jobs 5, only: HelloJob, except: HelloJob do + HelloJob.perform_later("jeremy") + 4.times { LoggingJob.perform_later } + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_performed_jobs_with_only_option_and_too_many_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_performed_jobs 1, only: HelloJob do @@ -431,6 +712,26 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 2/, error.message) end + def test_assert_performed_jobs_with_except_option_and_too_many_sent + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 1, except: LoggingJob do + 2.times { HelloJob.perform_later("jeremy") } + end + end + + assert_match(/1 .* but 2/, error.message) + end + + def test_assert_performed_jobs_with_only_and_except_option_and_too_many_sent + error = assert_raise ArgumentError do + assert_performed_jobs 1, only: HelloJob, except: HelloJob do + 2.times { HelloJob.perform_later("jeremy") } + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_no_performed_jobs_with_only_option assert_nothing_raised do assert_no_performed_jobs only: HelloJob do @@ -439,6 +740,24 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_no_performed_jobs_with_except_option + assert_nothing_raised do + assert_no_performed_jobs except: LoggingJob do + LoggingJob.perform_later + end + end + end + + def test_assert_no_performed_jobs_with_only_and_except_option + error = assert_raise ArgumentError do + assert_no_performed_jobs only: HelloJob, except: HelloJob do + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_no_performed_jobs_with_only_option_as_array assert_nothing_raised do assert_no_performed_jobs only: [HelloJob, RescueJob] do @@ -447,6 +766,25 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_no_performed_jobs_with_except_option_as_array + assert_nothing_raised do + assert_no_performed_jobs except: [HelloJob, RescueJob] do + HelloJob.perform_later + RescueJob.perform_later + end + end + end + + def test_assert_no_performed_jobs_with_only_and_except_option_as_array + error = assert_raise ArgumentError do + assert_no_performed_jobs only: [HelloJob, RescueJob], except: [HelloJob, RescueJob] do + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_no_performed_jobs_with_only_option_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_performed_jobs only: HelloJob do @@ -458,6 +796,28 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/0 .* but 1/, error.message) end + def test_assert_no_performed_jobs_with_except_option_failure + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_no_performed_jobs except: LoggingJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + end + end + + assert_match(/0 .* but 1/, error.message) + end + + def test_assert_no_performed_jobs_with_only_and_except_option_failure + error = assert_raise ArgumentError do + assert_no_performed_jobs only: HelloJob, except: HelloJob do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later + end + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_performed_job assert_performed_with(job: NestedJob, queue: "default") do NestedJob.perform_later diff --git a/activejob/test/cases/translation_test.rb b/activejob/test/cases/translation_test.rb index d6782a38bd..6a0d6d3e54 100644 --- a/activejob/test/cases/translation_test.rb +++ b/activejob/test/cases/translation_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/translated_hello_job" diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb index edcf159056..694232d7ef 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_job" require "support/job_buffer" diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb index 72c66d111f..0d8aa336a6 100644 --- a/activejob/test/integration/queuing_test.rb +++ b/activejob/test/integration/queuing_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "helper" require "jobs/logging_job" require "jobs/hello_job" diff --git a/activejob/test/jobs/application_job.rb b/activejob/test/jobs/application_job.rb index 32fe70b8e4..d92ffddcb5 100644 --- a/activejob/test/jobs/application_job.rb +++ b/activejob/test/jobs/application_job.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/activejob/test/jobs/callback_job.rb b/activejob/test/jobs/callback_job.rb index 7c5b161437..436cb55492 100644 --- a/activejob/test/jobs/callback_job.rb +++ b/activejob/test/jobs/callback_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class CallbackJob < ActiveJob::Base before_perform ->(job) { job.history << "CallbackJob ran before_perform" } after_perform ->(job) { job.history << "CallbackJob ran after_perform" } diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb index c43e25a796..2136f57e05 100644 --- a/activejob/test/jobs/gid_job.rb +++ b/activejob/test/jobs/gid_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" class GidJob < ActiveJob::Base diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb index 79e1d6a6f4..404df6150a 100644 --- a/activejob/test/jobs/hello_job.rb +++ b/activejob/test/jobs/hello_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" class HelloJob < ActiveJob::Base diff --git a/activejob/test/jobs/inherited_job.rb b/activejob/test/jobs/inherited_job.rb index 58b6582154..14f852ed06 100644 --- a/activejob/test/jobs/inherited_job.rb +++ b/activejob/test/jobs/inherited_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "application_job" class InheritedJob < ApplicationJob diff --git a/activejob/test/jobs/kwargs_job.rb b/activejob/test/jobs/kwargs_job.rb index ccd9811595..b86b06bada 100644 --- a/activejob/test/jobs/kwargs_job.rb +++ b/activejob/test/jobs/kwargs_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" class KwargsJob < ActiveJob::Base diff --git a/activejob/test/jobs/logging_job.rb b/activejob/test/jobs/logging_job.rb index 1a47601fde..4605fa6937 100644 --- a/activejob/test/jobs/logging_job.rb +++ b/activejob/test/jobs/logging_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class LoggingJob < ActiveJob::Base def perform(dummy) logger.info "Dummy, here is it: #{dummy}" diff --git a/activejob/test/jobs/nested_job.rb b/activejob/test/jobs/nested_job.rb index 891a2f952e..aafad0dba9 100644 --- a/activejob/test/jobs/nested_job.rb +++ b/activejob/test/jobs/nested_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class NestedJob < ActiveJob::Base def perform LoggingJob.perform_later "NestedJob" diff --git a/activejob/test/jobs/overridden_logging_job.rb b/activejob/test/jobs/overridden_logging_job.rb index 808d6e30e6..2ee363637d 100644 --- a/activejob/test/jobs/overridden_logging_job.rb +++ b/activejob/test/jobs/overridden_logging_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class OverriddenLoggingJob < ActiveJob::Base def perform(dummy) logger.info "Dummy, here is it: #{dummy}" diff --git a/activejob/test/jobs/provider_jid_job.rb b/activejob/test/jobs/provider_jid_job.rb index 71ed23e9bb..dacd09afdc 100644 --- a/activejob/test/jobs/provider_jid_job.rb +++ b/activejob/test/jobs/provider_jid_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" class ProviderJidJob < ActiveJob::Base diff --git a/activejob/test/jobs/queue_adapter_job.rb b/activejob/test/jobs/queue_adapter_job.rb index 7058ab2087..1c31a60ba2 100644 --- a/activejob/test/jobs/queue_adapter_job.rb +++ b/activejob/test/jobs/queue_adapter_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class QueueAdapterJob < ActiveJob::Base self.queue_adapter = :inline end diff --git a/activejob/test/jobs/queue_as_job.rb b/activejob/test/jobs/queue_as_job.rb index ab3075aa77..0feee99e87 100644 --- a/activejob/test/jobs/queue_as_job.rb +++ b/activejob/test/jobs/queue_as_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" class QueueAsJob < ActiveJob::Base diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb index fd78820bfe..d142cec1ea 100644 --- a/activejob/test/jobs/rescue_job.rb +++ b/activejob/test/jobs/rescue_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" class RescueJob < ActiveJob::Base diff --git a/activejob/test/jobs/retry_job.rb b/activejob/test/jobs/retry_job.rb index b121296441..a12d09779b 100644 --- a/activejob/test/jobs/retry_job.rb +++ b/activejob/test/jobs/retry_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" require "active_support/core_ext/integer/inflections" diff --git a/activejob/test/jobs/translated_hello_job.rb b/activejob/test/jobs/translated_hello_job.rb index 67ddca2f41..a0a68b4040 100644 --- a/activejob/test/jobs/translated_hello_job.rb +++ b/activejob/test/jobs/translated_hello_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../support/job_buffer" class TranslatedHelloJob < ActiveJob::Base diff --git a/activejob/test/models/person.rb b/activejob/test/models/person.rb index bcd1018782..9a3bfab25f 100644 --- a/activejob/test/models/person.rb +++ b/activejob/test/models/person.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Person class RecordNotFound < StandardError; end diff --git a/activejob/test/support/backburner/inline.rb b/activejob/test/support/backburner/inline.rb index 304f9c781c..6c708c0b7b 100644 --- a/activejob/test/support/backburner/inline.rb +++ b/activejob/test/support/backburner/inline.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "backburner" Backburner::Worker.class_eval do diff --git a/activejob/test/support/delayed_job/delayed/backend/test.rb b/activejob/test/support/delayed_job/delayed/backend/test.rb index ed3b252042..4721c1cc17 100644 --- a/activejob/test/support/delayed_job/delayed/backend/test.rb +++ b/activejob/test/support/delayed_job/delayed/backend/test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + #copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb require "ostruct" diff --git a/activejob/test/support/integration/adapters/async.rb b/activejob/test/support/integration/adapters/async.rb index 19aea8472e..ba9674d7a1 100644 --- a/activejob/test/support/integration/adapters/async.rb +++ b/activejob/test/support/integration/adapters/async.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module AsyncJobsManager def setup ActiveJob::Base.queue_adapter = :async diff --git a/activejob/test/support/integration/adapters/backburner.rb b/activejob/test/support/integration/adapters/backburner.rb index fd1e7697c5..eb179011d9 100644 --- a/activejob/test/support/integration/adapters/backburner.rb +++ b/activejob/test/support/integration/adapters/backburner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module BackburnerJobsManager def setup ActiveJob::Base.queue_adapter = :backburner diff --git a/activejob/test/support/integration/adapters/delayed_job.rb b/activejob/test/support/integration/adapters/delayed_job.rb index 73e1a04e45..ae5de78b60 100644 --- a/activejob/test/support/integration/adapters/delayed_job.rb +++ b/activejob/test/support/integration/adapters/delayed_job.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "delayed_job" require "delayed_job_active_record" diff --git a/activejob/test/support/integration/adapters/inline.rb b/activejob/test/support/integration/adapters/inline.rb index c669793dba..10a97fb941 100644 --- a/activejob/test/support/integration/adapters/inline.rb +++ b/activejob/test/support/integration/adapters/inline.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module InlineJobsManager def setup ActiveJob::Base.queue_adapter = :inline diff --git a/activejob/test/support/integration/adapters/qu.rb b/activejob/test/support/integration/adapters/qu.rb index b2f63d8f94..67db03e279 100644 --- a/activejob/test/support/integration/adapters/qu.rb +++ b/activejob/test/support/integration/adapters/qu.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module QuJobsManager def setup require "qu-rails" diff --git a/activejob/test/support/integration/adapters/que.rb b/activejob/test/support/integration/adapters/que.rb index cf1160d2bc..2a771b08c7 100644 --- a/activejob/test/support/integration/adapters/que.rb +++ b/activejob/test/support/integration/adapters/que.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module QueJobsManager def setup require "sequel" diff --git a/activejob/test/support/integration/adapters/queue_classic.rb b/activejob/test/support/integration/adapters/queue_classic.rb index 7f1308c5d3..1b0685a971 100644 --- a/activejob/test/support/integration/adapters/queue_classic.rb +++ b/activejob/test/support/integration/adapters/queue_classic.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module QueueClassicJobsManager def setup ENV["QC_DATABASE_URL"] ||= "postgres:///active_jobs_qc_int_test" diff --git a/activejob/test/support/integration/adapters/resque.rb b/activejob/test/support/integration/adapters/resque.rb index 5d142d324d..484b476567 100644 --- a/activejob/test/support/integration/adapters/resque.rb +++ b/activejob/test/support/integration/adapters/resque.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ResqueJobsManager def setup ActiveJob::Base.queue_adapter = :resque diff --git a/activejob/test/support/integration/adapters/sidekiq.rb b/activejob/test/support/integration/adapters/sidekiq.rb index 253cbd550b..b63d16d248 100644 --- a/activejob/test/support/integration/adapters/sidekiq.rb +++ b/activejob/test/support/integration/adapters/sidekiq.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "sidekiq/api" require "sidekiq/testing" diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb index dc42501ff3..965e6e2e6c 100644 --- a/activejob/test/support/integration/adapters/sneakers.rb +++ b/activejob/test/support/integration/adapters/sneakers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "sneakers/runner" require "sneakers/publisher" require "timeout" diff --git a/activejob/test/support/integration/adapters/sucker_punch.rb b/activejob/test/support/integration/adapters/sucker_punch.rb index e528f24261..099d412c8f 100644 --- a/activejob/test/support/integration/adapters/sucker_punch.rb +++ b/activejob/test/support/integration/adapters/sucker_punch.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module SuckerPunchJobsManager def setup ActiveJob::Base.queue_adapter = :sucker_punch diff --git a/activejob/test/support/integration/dummy_app_template.rb b/activejob/test/support/integration/dummy_app_template.rb index a054ecea08..ac382bd1b7 100644 --- a/activejob/test/support/integration/dummy_app_template.rb +++ b/activejob/test/support/integration/dummy_app_template.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + if ENV["AJ_ADAPTER"] == "delayed_job" generate "delayed_job:active_record", "--quiet" end diff --git a/activejob/test/support/integration/helper.rb b/activejob/test/support/integration/helper.rb index c0aa14c4c2..a058da141f 100644 --- a/activejob/test/support/integration/helper.rb +++ b/activejob/test/support/integration/helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + puts "\n\n*** rake aj:integration:#{ENV['AJ_ADAPTER']} ***\n" ENV["RAILS_ENV"] = "test" diff --git a/activejob/test/support/integration/jobs_manager.rb b/activejob/test/support/integration/jobs_manager.rb index 1cfbd60dc4..4775f52b2f 100644 --- a/activejob/test/support/integration/jobs_manager.rb +++ b/activejob/test/support/integration/jobs_manager.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class JobsManager @@managers = {} attr :adapter_name diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb index add719187c..9629876a6d 100644 --- a/activejob/test/support/integration/test_case_helpers.rb +++ b/activejob/test/support/integration/test_case_helpers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_support/core_ext/string/inflections" require "support/integration/jobs_manager" diff --git a/activejob/test/support/job_buffer.rb b/activejob/test/support/job_buffer.rb index 3146d06d54..45a6437685 100644 --- a/activejob/test/support/job_buffer.rb +++ b/activejob/test/support/job_buffer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module JobBuffer class << self def clear diff --git a/activejob/test/support/que/inline.rb b/activejob/test/support/que/inline.rb index e204f8154a..4ca65c1cd4 100644 --- a/activejob/test/support/que/inline.rb +++ b/activejob/test/support/que/inline.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "que" Que::Job.class_eval do diff --git a/activejob/test/support/queue_classic/inline.rb b/activejob/test/support/queue_classic/inline.rb index 955469e5a8..ca3cd4581b 100644 --- a/activejob/test/support/queue_classic/inline.rb +++ b/activejob/test/support/queue_classic/inline.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "queue_classic" module QC diff --git a/activejob/test/support/sneakers/inline.rb b/activejob/test/support/sneakers/inline.rb index 46882870d5..92b69ee3bc 100644 --- a/activejob/test/support/sneakers/inline.rb +++ b/activejob/test/support/sneakers/inline.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "sneakers" module Sneakers |