diff options
Diffstat (limited to 'activejob')
106 files changed, 716 insertions, 71 deletions
diff --git a/activejob/.gitignore b/activejob/.gitignore deleted file mode 100644 index b3aaf55871..0000000000 --- a/activejob/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test/dummy diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index ddfb926e02..0c69a5c663 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,7 +1,5 @@ -* Change logging instrumentation to log errors when a job raises an exception. +* Support redis-rb 4.0. - Fixes #26848. - - *Steven Bull* + *Jeremy Daer* Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activejob/CHANGELOG.md) for previous changes. diff --git a/activejob/README.md b/activejob/README.md index 8becac7753..8a9a23929b 100644 --- a/activejob/README.md +++ b/activejob/README.md @@ -108,7 +108,7 @@ Source code can be downloaded as part of the Rails project on GitHub Active Job is released under the MIT license: -* http://www.opensource.org/licenses/MIT +* https://opensource.org/licenses/MIT ## Support diff --git a/activejob/Rakefile b/activejob/Rakefile index 41ff76135e..6f13ef449d 100644 --- a/activejob/Rakefile +++ b/activejob/Rakefile @@ -1,8 +1,9 @@ +# frozen_string_literal: true + require "rake/testtask" #TODO: add qu back to the list after it support Rails 5.1 -#TODO: add delayed_job back to the list after it support Rails 5.1 -ACTIVEJOB_ADAPTERS = %w(async inline que queue_classic resque sidekiq sneakers sucker_punch backburner test) +ACTIVEJOB_ADAPTERS = %w(async inline delayed_job que queue_classic resque sidekiq sneakers sucker_punch backburner test) ACTIVEJOB_ADAPTERS.delete("queue_classic") if defined?(JRUBY_VERSION) task default: :test @@ -44,9 +45,8 @@ namespace :test do namespace :isolated do task adapter => "test:env:#{adapter}" do - dir = File.dirname(__FILE__) - Dir.glob("#{dir}/test/cases/**/*_test.rb").all? do |file| - sh(Gem.ruby, "-w", "-I#{dir}/lib", "-I#{dir}/test", file) + Dir.glob("#{__dir__}/test/cases/**/*_test.rb").all? do |file| + sh(Gem.ruby, "-w", "-I#{__dir__}/lib", "-I#{__dir__}/test", file) end || raise("Failures") end end diff --git a/activejob/activejob.gemspec b/activejob/activejob.gemspec index 2547e91262..71e32f695b 100644 --- a/activejob/activejob.gemspec +++ b/activejob/activejob.gemspec @@ -1,4 +1,6 @@ -version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip +# frozen_string_literal: true + +version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY @@ -18,6 +20,11 @@ Gem::Specification.new do |s| s.files = Dir["CHANGELOG.md", "MIT-LICENSE", "README.md", "lib/**/*"] s.require_path = "lib" + s.metadata = { + "source_code_uri" => "https://github.com/rails/rails/tree/v#{version}/activejob", + "changelog_uri" => "https://github.com/rails/rails/blob/v#{version}/activejob/CHANGELOG.md" + } + s.add_dependency "activesupport", version s.add_dependency "globalid", ">= 0.3.6" end diff --git a/activejob/bin/test b/activejob/bin/test index a7beb14b27..c53377cc97 100755 --- a/activejob/bin/test +++ b/activejob/bin/test @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true COMPONENT_ROOT = File.expand_path("..", __dir__) -require File.expand_path("../tools/test", COMPONENT_ROOT) +require_relative "../../tools/test" diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb index 8b7aef65a2..1f5bd7b3e9 100644 --- a/activejob/lib/active_job.rb +++ b/activejob/lib/active_job.rb @@ -1,3 +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 523a0e7f33..de11e7fcb1 100644 --- a/activejob/lib/active_job/arguments.rb +++ b/activejob/lib/active_job/arguments.rb @@ -1,3 +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 18e8641e50..ae112abb2c 100644 --- a/activejob/lib/active_job/base.rb +++ b/activejob/lib/active_job/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_job/core" require "active_job/queue_adapter" require "active_job/queue_name" diff --git a/activejob/lib/active_job/callbacks.rb b/activejob/lib/active_job/callbacks.rb index d5b17de8b5..334b24fb3b 100644 --- a/activejob/lib/active_job/callbacks.rb +++ b/activejob/lib/active_job/callbacks.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require "active_support/callbacks" module ActiveJob # = Active Job Callbacks # # Active Job provides hooks during the life cycle of a job. Callbacks allow you - # to trigger logic during the life cycle of a job. Available callbacks are: + # to trigger logic during this cycle. Available callbacks are: # # * <tt>before_enqueue</tt> # * <tt>around_enqueue</tt> @@ -13,6 +15,8 @@ module ActiveJob # * <tt>around_perform</tt> # * <tt>after_perform</tt> # + # NOTE: Calling the same callback multiple times will overwrite previous callback definitions. + # module Callbacks extend ActiveSupport::Concern include ActiveSupport::Callbacks diff --git a/activejob/lib/active_job/configured_job.rb b/activejob/lib/active_job/configured_job.rb index 2ff31f2dae..67daf48b36 100644 --- a/activejob/lib/active_job/configured_job.rb +++ b/activejob/lib/active_job/configured_job.rb @@ -1,3 +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 548ec89ee2..c4e12fc518 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -1,3 +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. @@ -80,6 +82,7 @@ module ActiveJob { "job_class" => self.class.name, "job_id" => job_id, + "provider_job_id" => provider_job_id, "queue_name" => queue_name, "priority" => priority, "arguments" => serialize_arguments(arguments), diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index c73117e7f3..53cb98fc71 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_job/arguments" module ActiveJob @@ -8,7 +10,7 @@ module ActiveJob # Includes the +perform_later+ method for job initialization. module ClassMethods # Push a job onto the queue. The arguments must be legal JSON types - # (string, int, float, nil, true, false, hash or array) or + # (+string+, +int+, +float+, +nil+, +true+, +false+, +hash+ or +array+) or # GlobalID::Identification instances. Arbitrary Ruby objects # are not supported. # diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb index c1b5d35313..8b4a88ba6a 100644 --- a/activejob/lib/active_job/exceptions.rb +++ b/activejob/lib/active_job/exceptions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/numeric/time" module ActiveJob @@ -47,7 +49,7 @@ module ActiveJob retry_job wait: determine_delay(wait), queue: queue, priority: priority else if block_given? - yield self, exception + yield self, error else logger.error "Stopped retrying #{self.class} due to a #{exception}, which reoccurred on #{executions} attempts. The original exception was #{error.cause.inspect}." raise error diff --git a/activejob/lib/active_job/execution.rb b/activejob/lib/active_job/execution.rb index 94d30c8eaf..d75be376ec 100644 --- a/activejob/lib/active_job/execution.rb +++ b/activejob/lib/active_job/execution.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/rescuable" require "active_job/arguments" diff --git a/activejob/lib/active_job/gem_version.rb b/activejob/lib/active_job/gem_version.rb index bf81f37e81..7ee61780e1 100644 --- a/activejob/lib/active_job/gem_version.rb +++ b/activejob/lib/active_job/gem_version.rb @@ -1,3 +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 f46d5c68a8..f53b7eaee5 100644 --- a/activejob/lib/active_job/logging.rb +++ b/activejob/lib/active_job/logging.rb @@ -1,3 +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" @@ -8,7 +10,7 @@ module ActiveJob extend ActiveSupport::Concern included do - cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) } + cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) around_enqueue do |_, block, _| tag_logger do diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb index 9dae80ffc2..dd05800baf 100644 --- a/activejob/lib/active_job/queue_adapter.rb +++ b/activejob/lib/active_job/queue_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/string/inflections" module ActiveJob @@ -7,6 +9,7 @@ module ActiveJob extend ActiveSupport::Concern included do + class_attribute :_queue_adapter_name, instance_accessor: false, instance_predicate: false class_attribute :_queue_adapter, instance_accessor: false, instance_predicate: false self.queue_adapter = :async end @@ -19,11 +22,15 @@ module ActiveJob _queue_adapter end + def queue_adapter_name + _queue_adapter_name + end + # Specify the backend queue provider. The default queue adapter # is the +:async+ queue. See QueueAdapters for more # information. def queue_adapter=(name_or_adapter_or_class) - self._queue_adapter = interpret_adapter(name_or_adapter_or_class) + interpret_adapter(name_or_adapter_or_class) end private @@ -31,16 +38,24 @@ module ActiveJob def interpret_adapter(name_or_adapter_or_class) case name_or_adapter_or_class when Symbol, String - ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new + assign_adapter(name_or_adapter_or_class.to_s, + ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new) else if queue_adapter?(name_or_adapter_or_class) - name_or_adapter_or_class + adapter_name = "#{name_or_adapter_or_class.class.name.demodulize.remove('Adapter').underscore}" + assign_adapter(adapter_name, + name_or_adapter_or_class) else raise ArgumentError end end end + def assign_adapter(adapter_name, queue_adapter) + self._queue_adapter_name = adapter_name + self._queue_adapter = queue_adapter + end + QUEUE_ADAPTER_METHODS = [:enqueue, :enqueue_at].freeze def queue_adapter?(object) diff --git a/activejob/lib/active_job/queue_adapters.rb b/activejob/lib/active_job/queue_adapters.rb index c8eedb6156..c1a1d3c510 100644 --- a/activejob/lib/active_job/queue_adapters.rb +++ b/activejob/lib/active_job/queue_adapters.rb @@ -1,3 +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 e2bff9e646..ebf6f384e3 100644 --- a/activejob/lib/active_job/queue_adapters/async_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/async_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "securerandom" require "concurrent/scheduled_task" require "concurrent/executor/thread_pool_executor" @@ -29,7 +31,7 @@ module ActiveJob # jobs. Since jobs share a single thread pool, long-running jobs will block # short-lived jobs. Fine for dev/test; bad for production. class AsyncAdapter - # See {Concurrent::ThreadPoolExecutor}[http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadPoolExecutor.html] for executor options. + # See {Concurrent::ThreadPoolExecutor}[https://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadPoolExecutor.html] for executor options. def initialize(**executor_options) @scheduler = Scheduler.new(**executor_options) end diff --git a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb index e3eccce62b..0ba93c6e0b 100644 --- a/activejob/lib/active_job/queue_adapters/backburner_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/backburner_adapter.rb @@ -1,3 +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 83ad2e767d..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,3 +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 0496f8449e..3d0b590212 100644 --- a/activejob/lib/active_job/queue_adapters/inline_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/inline_adapter.rb @@ -1,3 +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 e8994533e4..bd7003e177 100644 --- a/activejob/lib/active_job/queue_adapters/qu_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/qu_adapter.rb @@ -1,3 +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 0e698f0d79..86b5e07743 100644 --- a/activejob/lib/active_job/queue_adapters/que_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/que_adapter.rb @@ -1,3 +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 1115eb88ae..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,3 +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 2df157ef89..590b4ee98d 100644 --- a/activejob/lib/active_job/queue_adapters/resque_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/resque_adapter.rb @@ -1,3 +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 895cc1f981..5a1135854b 100644 --- a/activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb @@ -1,3 +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 f00acfc04a..de98a950d0 100644 --- a/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb @@ -1,3 +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 dd59a79813..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,3 +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 1b633b210e..885f9ff01c 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ActiveJob module QueueAdapters # == Test adapter for Active Job @@ -10,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. @@ -52,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 352cf62424..9dc6bc7f2e 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + module ActiveJob module QueueName extend ActiveSupport::Concern # Includes the ability to override the default queue name and prefix. module ClassMethods - mattr_accessor(:queue_name_prefix) - mattr_accessor(:default_queue_name) { "default" } + mattr_accessor :queue_name_prefix + mattr_accessor :default_queue_name, default: "default" # Specifies the name of the queue to process the job on. # @@ -32,11 +34,8 @@ module ActiveJob end included do - class_attribute :queue_name, instance_accessor: false - class_attribute :queue_name_delimiter, instance_accessor: false - - self.queue_name = default_queue_name - self.queue_name_delimiter = "_" # set default delimiter to '_' + class_attribute :queue_name, instance_accessor: false, default: default_queue_name + class_attribute :queue_name_delimiter, instance_accessor: false, default: "_" end # Returns the name of the queue the job will be run on. diff --git a/activejob/lib/active_job/queue_priority.rb b/activejob/lib/active_job/queue_priority.rb index b02202fcc8..063bccdb01 100644 --- a/activejob/lib/active_job/queue_priority.rb +++ b/activejob/lib/active_job/queue_priority.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module ActiveJob module QueuePriority extend ActiveSupport::Concern # Includes the ability to override the default queue priority. module ClassMethods - mattr_accessor(:default_priority) + mattr_accessor :default_priority # Specifies the priority of the queue to create the job with. # @@ -27,9 +29,7 @@ module ActiveJob end included do - class_attribute :priority, instance_accessor: false - - self.priority = default_priority + class_attribute :priority, instance_accessor: false, default: default_priority end # Returns the priority that the job will be created with diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index 4a8bf04d70..7b0742a6d2 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -1,3 +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 a5ec45e4a7..49cd51bdd0 100644 --- a/activejob/lib/active_job/test_case.rb +++ b/activejob/lib/active_job/test_case.rb @@ -1,3 +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 a61e4f59a5..1cd2c40c15 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/class/subclasses" require "active_support/core_ext/hash/keys" @@ -87,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 @@ -96,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 @@ -104,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 @@ -140,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. @@ -189,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 @@ -200,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" @@ -241,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. @@ -315,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 @@ -350,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) @@ -383,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 67e4cf4ab9..fb45c80d67 100644 --- a/activejob/lib/active_job/translation.rb +++ b/activejob/lib/active_job/translation.rb @@ -1,3 +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 60b463817f..eae7da4d05 100644 --- a/activejob/lib/active_job/version.rb +++ b/activejob/lib/active_job/version.rb @@ -1,3 +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 50476a2e50..69b4fe7d26 100644 --- a/activejob/lib/rails/generators/job/job_generator.rb +++ b/activejob/lib/rails/generators/job/job_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rails/generators/named_base" module Rails # :nodoc: @@ -12,7 +14,7 @@ module Rails # :nodoc: hook_for :test_framework def self.default_generator_root - File.dirname(__FILE__) + __dir__ end def create_job_file diff --git a/activejob/lib/rails/generators/job/templates/application_job.rb b/activejob/lib/rails/generators/job/templates/application_job.rb.tt index f93745a31a..f93745a31a 100644 --- a/activejob/lib/rails/generators/job/templates/application_job.rb +++ b/activejob/lib/rails/generators/job/templates/application_job.rb.tt diff --git a/activejob/lib/rails/generators/job/templates/job.rb b/activejob/lib/rails/generators/job/templates/job.rb.tt index 4ad2914a45..4ad2914a45 100644 --- a/activejob/lib/rails/generators/job/templates/job.rb +++ b/activejob/lib/rails/generators/job/templates/job.rb.tt diff --git a/activejob/test/adapters/async.rb b/activejob/test/adapters/async.rb index 08eb9658cd..a4fed7c2f7 100644 --- a/activejob/test/adapters/async.rb +++ b/activejob/test/adapters/async.rb @@ -1,2 +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 17ba07b802..bc34c78e9c 100644 --- a/activejob/test/adapters/backburner.rb +++ b/activejob/test/adapters/backburner.rb @@ -1,3 +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 5f0ee2418c..904b4c3f90 100644 --- a/activejob/test/adapters/delayed_job.rb +++ b/activejob/test/adapters/delayed_job.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + ActiveJob::Base.queue_adapter = :delayed_job -$LOAD_PATH << File.dirname(__FILE__) + "/../support/delayed_job" +$LOAD_PATH << File.expand_path("../support/delayed_job", __dir__) Delayed::Worker.delay_jobs = false Delayed::Worker.backend = :test diff --git a/activejob/test/adapters/inline.rb b/activejob/test/adapters/inline.rb index 24113dfa5a..b1ddcb28f1 100644 --- a/activejob/test/adapters/inline.rb +++ b/activejob/test/adapters/inline.rb @@ -1 +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 b89c504091..5b471fa347 100644 --- a/activejob/test/adapters/qu.rb +++ b/activejob/test/adapters/qu.rb @@ -1,3 +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 0c49274a4e..af77b0d4d1 100644 --- a/activejob/test/adapters/que.rb +++ b/activejob/test/adapters/que.rb @@ -1,3 +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 e301a7ca96..73902a5e62 100644 --- a/activejob/test/adapters/queue_classic.rb +++ b/activejob/test/adapters/queue_classic.rb @@ -1,2 +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 af7080358d..ad84a49372 100644 --- a/activejob/test/adapters/resque.rb +++ b/activejob/test/adapters/resque.rb @@ -1,2 +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 8036331ef1..7df1c36488 100644 --- a/activejob/test/adapters/sidekiq.rb +++ b/activejob/test/adapters/sidekiq.rb @@ -1,2 +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 159c0d1906..38d82aa778 100644 --- a/activejob/test/adapters/sneakers.rb +++ b/activejob/test/adapters/sneakers.rb @@ -1,2 +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 5661b6ee92..04bad984d4 100644 --- a/activejob/test/adapters/sucker_punch.rb +++ b/activejob/test/adapters/sucker_punch.rb @@ -1,2 +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 7180b38a57..0a1367dacf 100644 --- a/activejob/test/adapters/test.rb +++ b/activejob/test/adapters/test.rb @@ -1,3 +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 caf5d44a5e..2c179b2d38 100644 --- a/activejob/test/cases/adapter_test.rb +++ b/activejob/test/cases/adapter_test.rb @@ -1,3 +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 7934d8e556..13e6fcb727 100644 --- a/activejob/test/cases/argument_serialization_test.rb +++ b/activejob/test/cases/argument_serialization_test.rb @@ -1,3 +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 8d1c9c3058..df6ce16858 100644 --- a/activejob/test/cases/callbacks_test.rb +++ b/activejob/test/cases/callbacks_test.rb @@ -1,3 +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 dbe55f7430..22fed0a808 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "helper" require "jobs/retry_job" @@ -59,7 +61,7 @@ class ExceptionsTest < ActiveJob::TestCase test "custom handling of job that exceeds retry attempts" do perform_enqueued_jobs do RetryJob.perform_later "CustomCatchError", 6 - assert_equal "Dealt with a job that failed to retry in a custom way after 6 attempts", JobBuffer.last_value + assert_equal "Dealt with a job that failed to retry in a custom way after 6 attempts. Message: CustomCatchError", JobBuffer.last_value end end diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb index 3f2e300dfa..440051c427 100644 --- a/activejob/test/cases/job_serialization_test.rb +++ b/activejob/test/cases/job_serialization_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "helper" require "jobs/gid_job" require "jobs/hello_job" @@ -44,4 +46,12 @@ class JobSerializationTest < ActiveSupport::TestCase job.deserialize({}) assert_equal "en", job.locale end + + test "serialize stores provider_job_id" do + job = HelloJob.new + assert_nil job.serialize["provider_job_id"] + + job.provider_job_id = "some value set by adapter" + assert_equal job.provider_job_id, job.serialize["provider_job_id"] + end end diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index d5ca0f385c..1f8c4a5573 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -1,3 +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 9611b0909b..e71cfa49cf 100644 --- a/activejob/test/cases/queue_adapter_test.rb +++ b/activejob/test/cases/queue_adapter_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "helper" module ActiveJob @@ -25,14 +27,19 @@ class QueueAdapterTest < ActiveJob::TestCase base_queue_adapter = ActiveJob::Base.queue_adapter child_job_one = Class.new(ActiveJob::Base) + assert_equal child_job_one.queue_adapter_name, ActiveJob::Base.queue_adapter_name + child_job_one.queue_adapter = :stub_one assert_not_equal ActiveJob::Base.queue_adapter, child_job_one.queue_adapter + assert_equal "stub_one", child_job_one.queue_adapter_name assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.queue_adapter child_job_two = Class.new(ActiveJob::Base) child_job_two.queue_adapter = :stub_two + assert_equal "stub_two", child_job_two.queue_adapter_name + assert_kind_of ActiveJob::QueueAdapters::StubTwoAdapter, child_job_two.queue_adapter assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.queue_adapter, "child_job_one's queue adapter should remain unchanged" assert_equal base_queue_adapter, ActiveJob::Base.queue_adapter, "ActiveJob::Base's queue adapter should remain unchanged" diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 0247bc111e..b64a38f91e 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -1,3 +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 171fb1e593..4b3006ae81 100644 --- a/activejob/test/cases/queue_priority_test.rb +++ b/activejob/test/cases/queue_priority_test.rb @@ -1,3 +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 a3ecb15c31..0e843b7215 100644 --- a/activejob/test/cases/queuing_test.rb +++ b/activejob/test/cases/queuing_test.rb @@ -1,3 +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 afb1b48831..da9c87dbf0 100644 --- a/activejob/test/cases/rescue_test.rb +++ b/activejob/test/cases/rescue_test.rb @@ -1,3 +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 3db2d9dec7..4ae2add3a8 100644 --- a/activejob/test/cases/test_case_test.rb +++ b/activejob/test/cases/test_case_test.rb @@ -1,3 +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 81e75b4374..66bcd8f3a0 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "helper" require "active_support/core_ext/time" require "active_support/core_ext/date" @@ -106,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 @@ -120,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 @@ -141,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 @@ -152,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 @@ -162,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 @@ -172,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 @@ -180,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 @@ -191,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 @@ -199,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 @@ -284,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 @@ -389,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 @@ -399,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 @@ -409,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 @@ -420,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 @@ -430,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 @@ -438,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 @@ -446,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 @@ -457,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 27bfd50985..6a0d6d3e54 100644 --- a/activejob/test/cases/translation_test.rb +++ b/activejob/test/cases/translation_test.rb @@ -1,3 +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 db07ecab7a..694232d7ef 100644 --- a/activejob/test/helper.rb +++ b/activejob/test/helper.rb @@ -1,3 +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 2669c52a1c..0d8aa336a6 100644 --- a/activejob/test/integration/queuing_test.rb +++ b/activejob/test/integration/queuing_test.rb @@ -1,3 +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 a009ace51c..d92ffddcb5 100644 --- a/activejob/test/jobs/application_job.rb +++ b/activejob/test/jobs/application_job.rb @@ -1,2 +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 ca2a8e031a..436cb55492 100644 --- a/activejob/test/jobs/callback_job.rb +++ b/activejob/test/jobs/callback_job.rb @@ -1,3 +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 c7cfa6e7a2..2136f57e05 100644 --- a/activejob/test/jobs/gid_job.rb +++ b/activejob/test/jobs/gid_job.rb @@ -1,3 +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 126fefae00..404df6150a 100644 --- a/activejob/test/jobs/hello_job.rb +++ b/activejob/test/jobs/hello_job.rb @@ -1,3 +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 60fca66f88..14f852ed06 100644 --- a/activejob/test/jobs/inherited_job.rb +++ b/activejob/test/jobs/inherited_job.rb @@ -1,3 +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 9f9d809673..b86b06bada 100644 --- a/activejob/test/jobs/kwargs_job.rb +++ b/activejob/test/jobs/kwargs_job.rb @@ -1,3 +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 119b32fa67..4605fa6937 100644 --- a/activejob/test/jobs/logging_job.rb +++ b/activejob/test/jobs/logging_job.rb @@ -1,3 +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 21b7692cd1..aafad0dba9 100644 --- a/activejob/test/jobs/nested_job.rb +++ b/activejob/test/jobs/nested_job.rb @@ -1,3 +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 2b17a65142..2ee363637d 100644 --- a/activejob/test/jobs/overridden_logging_job.rb +++ b/activejob/test/jobs/overridden_logging_job.rb @@ -1,3 +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 0c8ba040f5..dacd09afdc 100644 --- a/activejob/test/jobs/provider_jid_job.rb +++ b/activejob/test/jobs/provider_jid_job.rb @@ -1,3 +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 160dfd74ec..1c31a60ba2 100644 --- a/activejob/test/jobs/queue_adapter_job.rb +++ b/activejob/test/jobs/queue_adapter_job.rb @@ -1,3 +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 7dc318e736..0feee99e87 100644 --- a/activejob/test/jobs/queue_as_job.rb +++ b/activejob/test/jobs/queue_as_job.rb @@ -1,3 +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 62add4271a..d142cec1ea 100644 --- a/activejob/test/jobs/rescue_job.rb +++ b/activejob/test/jobs/rescue_job.rb @@ -1,3 +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 c02febc50c..9aa99d9a21 100644 --- a/activejob/test/jobs/retry_job.rb +++ b/activejob/test/jobs/retry_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../support/job_buffer" require "active_support/core_ext/integer/inflections" @@ -15,7 +17,7 @@ class RetryJob < ActiveJob::Base retry_on ShortWaitTenAttemptsError, wait: 1.second, attempts: 10 retry_on ExponentialWaitTenAttemptsError, wait: :exponentially_longer, attempts: 10 retry_on CustomWaitTenAttemptsError, wait: ->(executions) { executions * 2 }, attempts: 10 - retry_on(CustomCatchError) { |job, exception| JobBuffer.add("Dealt with a job that failed to retry in a custom way after #{job.arguments.second} attempts") } + retry_on(CustomCatchError) { |job, exception| JobBuffer.add("Dealt with a job that failed to retry in a custom way after #{job.arguments.second} attempts. Message: #{exception.message}") } discard_on DiscardableError def perform(raising, attempts) diff --git a/activejob/test/jobs/translated_hello_job.rb b/activejob/test/jobs/translated_hello_job.rb index 56e9f147b9..a0a68b4040 100644 --- a/activejob/test/jobs/translated_hello_job.rb +++ b/activejob/test/jobs/translated_hello_job.rb @@ -1,3 +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 b5d68ad9c1..9a3bfab25f 100644 --- a/activejob/test/models/person.rb +++ b/activejob/test/models/person.rb @@ -1,3 +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 9758332b6f..6c708c0b7b 100644 --- a/activejob/test/support/backburner/inline.rb +++ b/activejob/test/support/backburner/inline.rb @@ -1,3 +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 98d731ff1e..9280a37a5c 100644 --- a/activejob/test/support/delayed_job/delayed/backend/test.rb +++ b/activejob/test/support/delayed_job/delayed/backend/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + #copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb require "ostruct" @@ -19,8 +21,7 @@ module Delayed include Delayed::Backend::Base - cattr_accessor :id - self.id = 0 + cattr_accessor :id, default: 0 def initialize(hash = {}) self.attempts = 0 @@ -76,7 +77,7 @@ module Delayed self.locked_by = worker end - return true + true end def self.db_time_now diff --git a/activejob/test/support/integration/adapters/async.rb b/activejob/test/support/integration/adapters/async.rb index 44ab98437a..ba9674d7a1 100644 --- a/activejob/test/support/integration/adapters/async.rb +++ b/activejob/test/support/integration/adapters/async.rb @@ -1,3 +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 2e194933a1..eb179011d9 100644 --- a/activejob/test/support/integration/adapters/backburner.rb +++ b/activejob/test/support/integration/adapters/backburner.rb @@ -1,3 +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 2adbbcd88f..fc9bae47fa 100644 --- a/activejob/test/support/integration/adapters/delayed_job.rb +++ b/activejob/test/support/integration/adapters/delayed_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "delayed_job" require "delayed_job_active_record" @@ -16,5 +18,6 @@ module DelayedJobJobsManager def stop_workers @worker.stop + @thread.join end end diff --git a/activejob/test/support/integration/adapters/inline.rb b/activejob/test/support/integration/adapters/inline.rb index e06b34c976..10a97fb941 100644 --- a/activejob/test/support/integration/adapters/inline.rb +++ b/activejob/test/support/integration/adapters/inline.rb @@ -1,3 +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 71819f5a55..67db03e279 100644 --- a/activejob/test/support/integration/adapters/qu.rb +++ b/activejob/test/support/integration/adapters/qu.rb @@ -1,3 +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 20faee3427..2a771b08c7 100644 --- a/activejob/test/support/integration/adapters/que.rb +++ b/activejob/test/support/integration/adapters/que.rb @@ -1,3 +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 369693e947..1b0685a971 100644 --- a/activejob/test/support/integration/adapters/queue_classic.rb +++ b/activejob/test/support/integration/adapters/queue_classic.rb @@ -1,3 +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 a21a1786c9..2ed8302277 100644 --- a/activejob/test/support/integration/adapters/resque.rb +++ b/activejob/test/support/integration/adapters/resque.rb @@ -1,11 +1,14 @@ +# frozen_string_literal: true + module ResqueJobsManager def setup ActiveJob::Base.queue_adapter = :resque - Resque.redis = Redis::Namespace.new "active_jobs_int_test", redis: Redis.connect(url: "redis://127.0.0.1:6379/12", thread_safe: true) + Resque.redis = Redis::Namespace.new "active_jobs_int_test", redis: Redis.new(url: "redis://127.0.0.1:6379/12", thread_safe: true) Resque.logger = Rails.logger unless can_run? puts "Cannot run integration tests for resque. To be able to run integration tests for resque you need to install and start redis.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -39,11 +42,8 @@ module ResqueJobsManager end def can_run? - begin - Resque.redis.client.connect - rescue - return false - end - true + Resque.redis.ping == "PONG" + rescue + false end end diff --git a/activejob/test/support/integration/adapters/sidekiq.rb b/activejob/test/support/integration/adapters/sidekiq.rb index bbb575f6da..4b01a81ec5 100644 --- a/activejob/test/support/integration/adapters/sidekiq.rb +++ b/activejob/test/support/integration/adapters/sidekiq.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "sidekiq/api" require "sidekiq/testing" @@ -8,7 +10,8 @@ module SidekiqJobsManager ActiveJob::Base.queue_adapter = :sidekiq unless can_run? puts "Cannot run integration tests for sidekiq. To be able to run integration tests for sidekiq you need to install and start redis.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -28,7 +31,7 @@ module SidekiqJobsManager # Sidekiq is not warning-clean :( $VERBOSE = false - $stdin.reopen("/dev/null") + $stdin.reopen(File::NULL) $stdout.sync = true $stderr.sync = true diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb index 1c8dfaca59..965e6e2e6c 100644 --- a/activejob/test/support/integration/adapters/sneakers.rb +++ b/activejob/test/support/integration/adapters/sneakers.rb @@ -1,3 +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 9c0d66b469..099d412c8f 100644 --- a/activejob/test/support/integration/adapters/sucker_punch.rb +++ b/activejob/test/support/integration/adapters/sucker_punch.rb @@ -1,3 +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 29a5691f30..7ea78c3350 100644 --- a/activejob/test/support/integration/dummy_app_template.rb +++ b/activejob/test/support/integration/dummy_app_template.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + if ENV["AJ_ADAPTER"] == "delayed_job" generate "delayed_job:active_record", "--quiet" end -rails_command("db:migrate") - initializer "activejob.rb", <<-CODE -require "#{File.expand_path("../jobs_manager.rb", __FILE__)}" +require "#{File.expand_path("jobs_manager.rb", __dir__)}" JobsManager.current_manager.setup CODE diff --git a/activejob/test/support/integration/helper.rb b/activejob/test/support/integration/helper.rb index 626b932cce..a02d874e2e 100644 --- a/activejob/test/support/integration/helper.rb +++ b/activejob/test/support/integration/helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + puts "\n\n*** rake aj:integration:#{ENV['AJ_ADAPTER']} ***\n" ENV["RAILS_ENV"] = "test" @@ -7,7 +9,7 @@ require "rails/generators/rails/app/app_generator" require "tmpdir" dummy_app_path = Dir.mktmpdir + "/dummy" -dummy_app_template = File.expand_path("../dummy_app_template.rb", __FILE__) +dummy_app_template = File.expand_path("dummy_app_template.rb", __dir__) args = Rails::Generators::ARGVScrubber.new(["new", dummy_app_path, "--skip-gemfile", "--skip-bundle", "--skip-git", "--skip-spring", "-d", "sqlite3", "--skip-javascript", "--force", "--quiet", "--template", dummy_app_template]).prepare! @@ -16,6 +18,7 @@ Rails::Generators::AppGenerator.start args require "#{dummy_app_path}/config/environment.rb" ActiveRecord::Migrator.migrations_paths = [ Rails.root.join("db/migrate").to_s ] +ActiveRecord::Tasks::DatabaseTasks.migrate require "rails/test_help" Rails.backtrace_cleaner.remove_silencers! diff --git a/activejob/test/support/integration/jobs_manager.rb b/activejob/test/support/integration/jobs_manager.rb index 488756437b..4775f52b2f 100644 --- a/activejob/test/support/integration/jobs_manager.rb +++ b/activejob/test/support/integration/jobs_manager.rb @@ -1,3 +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 41bf9c89d1..f02a32a38e 100644 --- a/activejob/test/support/integration/test_case_helpers.rb +++ b/activejob/test/support/integration/test_case_helpers.rb @@ -1,4 +1,5 @@ -require "active_support/core_ext/string/inflections" +# frozen_string_literal: true + require "support/integration/jobs_manager" module TestCaseHelpers @@ -28,8 +29,7 @@ module TestCaseHelpers end def adapter_is?(*adapter_class_symbols) - adapter = ActiveJob::Base.queue_adapter.class.name.demodulize.chomp("Adapter").underscore - adapter_class_symbols.map(&:to_s).include? adapter + adapter_class_symbols.map(&:to_s).include? ActiveJob::Base.queue_adapter_name end def wait_for_jobs_to_finish_for(seconds = 60) diff --git a/activejob/test/support/job_buffer.rb b/activejob/test/support/job_buffer.rb index 620cb5288d..45a6437685 100644 --- a/activejob/test/support/job_buffer.rb +++ b/activejob/test/support/job_buffer.rb @@ -1,3 +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 55eb0d01ef..4ca65c1cd4 100644 --- a/activejob/test/support/que/inline.rb +++ b/activejob/test/support/que/inline.rb @@ -1,3 +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 dcd834ecce..ca3cd4581b 100644 --- a/activejob/test/support/queue_classic/inline.rb +++ b/activejob/test/support/queue_classic/inline.rb @@ -1,3 +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 cf102ae5c2..92b69ee3bc 100644 --- a/activejob/test/support/sneakers/inline.rb +++ b/activejob/test/support/sneakers/inline.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "sneakers" module Sneakers |