aboutsummaryrefslogtreecommitdiffstats
path: root/activejob
diff options
context:
space:
mode:
Diffstat (limited to 'activejob')
-rw-r--r--activejob/CHANGELOG.md12
-rw-r--r--activejob/MIT-LICENSE2
-rw-r--r--activejob/Rakefile5
-rw-r--r--activejob/lib/active_job.rb2
-rw-r--r--activejob/lib/active_job/arguments.rb18
-rw-r--r--activejob/lib/active_job/configured_job.rb2
-rw-r--r--activejob/lib/active_job/core.rb2
-rw-r--r--activejob/lib/active_job/enqueuing.rb6
-rw-r--r--activejob/lib/active_job/exceptions.rb4
-rw-r--r--activejob/lib/active_job/queue_adapter.rb11
-rw-r--r--activejob/lib/active_job/queue_adapters.rb2
-rw-r--r--activejob/lib/active_job/queue_adapters/qu_adapter.rb2
-rw-r--r--activejob/lib/active_job/queue_name.rb2
-rw-r--r--activejob/lib/active_job/queue_priority.rb2
-rw-r--r--activejob/lib/active_job/railtie.rb2
-rw-r--r--activejob/lib/active_job/test_helper.rb58
-rw-r--r--activejob/test/cases/queue_adapter_test.rb13
-rw-r--r--activejob/test/cases/queue_naming_test.rb2
-rw-r--r--activejob/test/cases/queue_priority_test.rb4
-rw-r--r--activejob/test/cases/test_helper_test.rb8
-rw-r--r--activejob/test/helper.rb3
-rw-r--r--activejob/test/jobs/application_job.rb2
-rw-r--r--activejob/test/models/person.rb2
-rw-r--r--activejob/test/support/backburner/inline.rb2
-rw-r--r--activejob/test/support/delayed_job/delayed/backend/test.rb6
-rw-r--r--activejob/test/support/integration/adapters/que.rb2
-rw-r--r--activejob/test/support/integration/adapters/queue_classic.rb2
-rw-r--r--activejob/test/support/integration/adapters/sneakers.rb4
-rw-r--r--activejob/test/support/integration/dummy_app_template.rb3
-rw-r--r--activejob/test/support/integration/helper.rb1
-rw-r--r--activejob/test/support/integration/test_case_helpers.rb11
31 files changed, 97 insertions, 100 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md
index 9bf397af14..5e8d8cb5c9 100644
--- a/activejob/CHANGELOG.md
+++ b/activejob/CHANGELOG.md
@@ -1,3 +1,11 @@
+* Removed deprecated support to passing the adapter class to `.queue_adapter`.
+
+ *Rafael Mendonça França*
+
+* Removed deprecated `#original_exception` in `ActiveJob::DeserializationError`.
+
+ *Rafael Mendonça França*
+
* Added instance variable `@queue` to JobWrapper.
This will fix issues in [resque-scheduler](https://github.com/resque/resque-scheduler) `#job_to_hash` method,
@@ -16,13 +24,13 @@
class RemoteServiceJob < ActiveJob::Base
retry_on CustomAppException # defaults to 3s wait, 5 attempts
retry_on AnotherCustomAppException, wait: ->(executions) { executions * 2 }
- retry_on ActiveRecord::StatementInvalid, wait: 5.seconds, attempts: 3
+ retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3
retry_on Net::OpenTimeout, wait: :exponentially_longer, attempts: 10
discard_on ActiveJob::DeserializationError
def perform(*args)
# Might raise CustomAppException or AnotherCustomAppException for something domain specific
- # Might raise ActiveRecord::StatementInvalid when a local db deadlock is detected
+ # Might raise ActiveRecord::Deadlocked when a local db deadlock is detected
# Might raise Net::OpenTimeout when the remote service is down
end
end
diff --git a/activejob/MIT-LICENSE b/activejob/MIT-LICENSE
index a3ffb46b3f..daa726b9f0 100644
--- a/activejob/MIT-LICENSE
+++ b/activejob/MIT-LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2014-2016 David Heinemeier Hansson
+Copyright (c) 2014-2017 David Heinemeier Hansson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/activejob/Rakefile b/activejob/Rakefile
index 3953116061..41ff76135e 100644
--- a/activejob/Rakefile
+++ b/activejob/Rakefile
@@ -1,8 +1,9 @@
require "rake/testtask"
#TODO: add qu back to the list after it support Rails 5.1
-ACTIVEJOB_ADAPTERS = %w(async inline delayed_job que queue_classic resque sidekiq sneakers sucker_punch backburner test)
-ACTIVEJOB_ADAPTERS -= %w(queue_classic) if defined?(JRUBY_VERSION)
+#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.delete("queue_classic") if defined?(JRUBY_VERSION)
task default: :test
task test: "test:default"
diff --git a/activejob/lib/active_job.rb b/activejob/lib/active_job.rb
index 20ca7085c6..8b7aef65a2 100644
--- a/activejob/lib/active_job.rb
+++ b/activejob/lib/active_job.rb
@@ -1,5 +1,5 @@
#--
-# Copyright (c) 2014-2016 David Heinemeier Hansson
+# Copyright (c) 2014-2017 David Heinemeier Hansson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb
index 41ce5f863b..523a0e7f33 100644
--- a/activejob/lib/active_job/arguments.rb
+++ b/activejob/lib/active_job/arguments.rb
@@ -5,22 +5,10 @@ module ActiveJob
#
# Wraps the original exception raised as +cause+.
class DeserializationError < StandardError
- def initialize(e = nil) #:nodoc:
- if e
- ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \
- "Exceptions will automatically capture the original exception.", caller)
- end
-
+ def initialize #:nodoc:
super("Error while trying to deserialize arguments: #{$!.message}")
set_backtrace $!.backtrace
end
-
- # The original exception that was raised during deserialization of job
- # arguments.
- def original_exception
- ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller)
- cause
- end
end
# Raised when an unsupported argument type is set as a job argument. We
@@ -34,8 +22,8 @@ module ActiveJob
module Arguments
extend self
# :nodoc:
- # Calls #uniq since Integer, Fixnum, and Bignum are all the same class on Ruby 2.4+
- TYPE_WHITELIST = [ NilClass, String, Integer, Fixnum, Bignum, Float, BigDecimal, TrueClass, FalseClass ].uniq
+ TYPE_WHITELIST = [ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ]
+ TYPE_WHITELIST.push(Fixnum, Bignum) unless 1.class == Integer
# Serializes a set of arguments. Whitelisted types are returned
# as-is. Arrays/Hashes are serialized element by element.
diff --git a/activejob/lib/active_job/configured_job.rb b/activejob/lib/active_job/configured_job.rb
index 979280b910..2ff31f2dae 100644
--- a/activejob/lib/active_job/configured_job.rb
+++ b/activejob/lib/active_job/configured_job.rb
@@ -1,6 +1,6 @@
module ActiveJob
class ConfiguredJob #:nodoc:
- def initialize(job_class, options={})
+ def initialize(job_class, options = {})
@options = options
@job_class = job_class
end
diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb
index a338061766..548ec89ee2 100644
--- a/activejob/lib/active_job/core.rb
+++ b/activejob/lib/active_job/core.rb
@@ -59,7 +59,7 @@ module ActiveJob
# VideoJob.set(queue: :some_queue, wait: 5.minutes).perform_later(Video.last)
# VideoJob.set(queue: :some_queue, wait_until: Time.now.tomorrow).perform_later(Video.last)
# VideoJob.set(queue: :some_queue, wait: 5.minutes, priority: 10).perform_later(Video.last)
- def set(options={})
+ def set(options = {})
ConfiguredJob.new(self, options)
end
end
diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb
index 18051a7d65..c73117e7f3 100644
--- a/activejob/lib/active_job/enqueuing.rb
+++ b/activejob/lib/active_job/enqueuing.rb
@@ -18,8 +18,8 @@ module ActiveJob
job_or_instantiate(*args).enqueue
end
- protected
- def job_or_instantiate(*args)
+ private
+ def job_or_instantiate(*args) # :doc:
args.first.is_a?(self) ? args.first : new(*args)
end
end
@@ -39,7 +39,7 @@ module ActiveJob
# my_job_instance.enqueue queue: :important
# my_job_instance.enqueue wait_until: Date.tomorrow.midnight
# my_job_instance.enqueue priority: 10
- def enqueue(options={})
+ def enqueue(options = {})
self.scheduled_at = options[:wait].seconds.from_now.to_f if options[:wait]
self.scheduled_at = options[:wait_until].to_f if options[:wait_until]
self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb
index d236f03d53..c1b5d35313 100644
--- a/activejob/lib/active_job/exceptions.rb
+++ b/activejob/lib/active_job/exceptions.rb
@@ -17,7 +17,7 @@ module ActiveJob
# ==== Options
# * <tt>:wait</tt> - Re-enqueues the job with a delay specified either in seconds (default: 3 seconds),
# as a computing proc that the number of executions so far as an argument, or as a symbol reference of
- # <tt>:exponentially_longer<>, which applies the wait algorithm of <tt>(executions ** 4) + 2</tt>
+ # <tt>:exponentially_longer</tt>, which applies the wait algorithm of <tt>(executions ** 4) + 2</tt>
# (first wait 3s, then 18s, then 83s, etc)
# * <tt>:attempts</tt> - Re-enqueues the job the specified number of times (default: 5 attempts)
# * <tt>:queue</tt> - Re-enqueues the job on a different queue
@@ -104,7 +104,7 @@ module ActiveJob
def determine_delay(seconds_or_duration_or_algorithm)
case seconds_or_duration_or_algorithm
when :exponentially_longer
- (executions ** 4) + 2
+ (executions**4) + 2
when ActiveSupport::Duration
duration = seconds_or_duration_or_algorithm
duration.to_i
diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb
index 7f9a2da4b0..bcc555d33e 100644
--- a/activejob/lib/active_job/queue_adapter.rb
+++ b/activejob/lib/active_job/queue_adapter.rb
@@ -1,5 +1,4 @@
require "active_job/queue_adapters/inline_adapter"
-require "active_support/core_ext/class/attribute"
require "active_support/core_ext/string/inflections"
module ActiveJob
@@ -37,12 +36,6 @@ module ActiveJob
else
if queue_adapter?(name_or_adapter_or_class)
name_or_adapter_or_class
- elsif queue_adapter_class?(name_or_adapter_or_class)
- ActiveSupport::Deprecation.warn "Passing an adapter class is deprecated " \
- "and will be removed in Rails 5.1. Please pass an adapter name " \
- "(.queue_adapter = :#{name_or_adapter_or_class.name.demodulize.remove('Adapter').underscore}) " \
- "or an instance (.queue_adapter = #{name_or_adapter_or_class.name}.new) instead."
- name_or_adapter_or_class.new
else
raise ArgumentError
end
@@ -54,10 +47,6 @@ module ActiveJob
def queue_adapter?(object)
QUEUE_ADAPTER_METHODS.all? { |meth| object.respond_to?(meth) }
end
-
- def queue_adapter_class?(object)
- object.is_a?(Class) && QUEUE_ADAPTER_METHODS.all? { |meth| object.public_method_defined?(meth) }
- end
end
end
end
diff --git a/activejob/lib/active_job/queue_adapters.rb b/activejob/lib/active_job/queue_adapters.rb
index 86cc880b14..c8eedb6156 100644
--- a/activejob/lib/active_job/queue_adapters.rb
+++ b/activejob/lib/active_job/queue_adapters.rb
@@ -8,7 +8,7 @@ module ActiveJob
# * {Qu}[https://github.com/bkeepers/qu]
# * {Que}[https://github.com/chanks/que]
# * {queue_classic}[https://github.com/QueueClassic/queue_classic]
- # * {Resque 1.x}[https://github.com/resque/resque/tree/1-x-stable]
+ # * {Resque}[https://github.com/resque/resque]
# * {Sidekiq}[http://sidekiq.org]
# * {Sneakers}[https://github.com/jondot/sneakers]
# * {Sucker Punch}[https://github.com/brandonhilkert/sucker_punch]
diff --git a/activejob/lib/active_job/queue_adapters/qu_adapter.rb b/activejob/lib/active_job/queue_adapters/qu_adapter.rb
index 20cc97ebc7..e8994533e4 100644
--- a/activejob/lib/active_job/queue_adapters/qu_adapter.rb
+++ b/activejob/lib/active_job/queue_adapters/qu_adapter.rb
@@ -32,7 +32,7 @@ module ActiveJob
class JobWrapper < Qu::Job #:nodoc:
def initialize(job_data)
- @job_data = job_data
+ @job_data = job_data
end
def perform
diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb
index 143fac9888..352cf62424 100644
--- a/activejob/lib/active_job/queue_name.rb
+++ b/activejob/lib/active_job/queue_name.rb
@@ -16,7 +16,7 @@ module ActiveJob
# post.to_feed!
# end
# end
- def queue_as(part_name=nil, &block)
+ def queue_as(part_name = nil, &block)
if block_given?
self.queue_name = block
else
diff --git a/activejob/lib/active_job/queue_priority.rb b/activejob/lib/active_job/queue_priority.rb
index a48e53b0ef..b02202fcc8 100644
--- a/activejob/lib/active_job/queue_priority.rb
+++ b/activejob/lib/active_job/queue_priority.rb
@@ -17,7 +17,7 @@ module ActiveJob
# end
#
# Specify either an argument or a block.
- def queue_with_priority(priority=nil, &block)
+ def queue_with_priority(priority = nil, &block)
if block_given?
self.priority = block
else
diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb
index e4198a40a5..4a8bf04d70 100644
--- a/activejob/lib/active_job/railtie.rb
+++ b/activejob/lib/active_job/railtie.rb
@@ -15,7 +15,7 @@ module ActiveJob
options.queue_adapter ||= :async
ActiveSupport.on_load(:active_job) do
- options.each { |k,v| send("#{k}=", v) }
+ options.each { |k, v| send("#{k}=", v) }
end
end
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb
index bbd2a0c06c..d01795f0c5 100644
--- a/activejob/lib/active_job/test_helper.rb
+++ b/activejob/lib/active_job/test_helper.rb
@@ -232,16 +232,16 @@ module ActiveJob
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# end
# end
- def assert_enqueued_with(args = {})
+ def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
original_enqueued_jobs_count = enqueued_jobs.count
- args.assert_valid_keys(:job, :args, :at, :queue)
- serialized_args = serialize_args_for_assertion(args)
+ expected = { job: job, args: args, at: at, queue: queue }.compact
+ serialized_args = serialize_args_for_assertion(expected)
yield
in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count)
- matching_job = in_block_jobs.find do |job|
- serialized_args.all? { |key, value| value == job[key] }
+ matching_job = in_block_jobs.find do |in_block_job|
+ serialized_args.all? { |key, value| value == in_block_job[key] }
end
- assert matching_job, "No enqueued job found with #{args}"
+ assert matching_job, "No enqueued job found with #{expected}"
instantiate_job(matching_job)
end
@@ -256,19 +256,38 @@ module ActiveJob
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# end
# end
- def assert_performed_with(args = {})
+ def assert_performed_with(job: nil, args: nil, at: nil, queue: nil)
original_performed_jobs_count = performed_jobs.count
- args.assert_valid_keys(:job, :args, :at, :queue)
- serialized_args = serialize_args_for_assertion(args)
+ expected = { job: job, args: args, at: at, queue: queue }.compact
+ serialized_args = serialize_args_for_assertion(expected)
perform_enqueued_jobs { yield }
in_block_jobs = performed_jobs.drop(original_performed_jobs_count)
- matching_job = in_block_jobs.find do |job|
- serialized_args.all? { |key, value| value == job[key] }
+ matching_job = in_block_jobs.find do |in_block_job|
+ serialized_args.all? { |key, value| value == in_block_job[key] }
end
- assert matching_job, "No performed job found with #{args}"
+ assert matching_job, "No performed job found with #{expected}"
instantiate_job(matching_job)
end
+ # Performs all enqueued jobs in the duration of the block.
+ #
+ # def test_perform_enqueued_jobs
+ # perform_enqueued_jobs do
+ # MyJob.perform_later(1, 2, 3)
+ # end
+ # assert_performed_jobs 1
+ # end
+ #
+ # This method also supports filtering. If the +:only+ option is specified,
+ # then only the listed job(s) will be performed.
+ #
+ # def test_perform_enqueued_jobs_with_only
+ # perform_enqueued_jobs(only: MyJob) do
+ # MyJob.perform_later(1, 2, 3) # will be performed
+ # HelloJob.perform_later(1, 2, 3) # will not be perfomed
+ # end
+ # assert_performed_jobs 1
+ # end
def perform_enqueued_jobs(only: nil)
old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs
old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs
@@ -286,20 +305,25 @@ module ActiveJob
end
end
+ # Accesses the queue_adapter set by ActiveJob::Base.
+ #
+ # def test_assert_job_has_custom_queue_adapter_set
+ # assert_instance_of CustomQueueAdapter, HelloJob.queue_adapter
+ # end
def queue_adapter
ActiveJob::Base.queue_adapter
end
private
- def clear_enqueued_jobs # :nodoc:
+ def clear_enqueued_jobs
enqueued_jobs.clear
end
- def clear_performed_jobs # :nodoc:
+ def clear_performed_jobs
performed_jobs.clear
end
- def enqueued_jobs_size(only: nil) # :nodoc:
+ def enqueued_jobs_size(only: nil)
if only
enqueued_jobs.count { |job| Array(only).include?(job.fetch(:job)) }
else
@@ -307,14 +331,14 @@ module ActiveJob
end
end
- def serialize_args_for_assertion(args) # :nodoc:
+ def serialize_args_for_assertion(args)
args.dup.tap do |serialized_args|
serialized_args[:args] = ActiveJob::Arguments.serialize(serialized_args[:args]) if serialized_args[:args]
serialized_args[:at] = serialized_args[:at].to_f if serialized_args[:at]
end
end
- def instantiate_job(payload) # :nodoc:
+ def instantiate_job(payload)
job = payload[:job].new(*payload[:args])
job.scheduled_at = Time.at(payload[:at]) if payload.key?(:at)
job.queue_name = payload[:queue]
diff --git a/activejob/test/cases/queue_adapter_test.rb b/activejob/test/cases/queue_adapter_test.rb
index dc862450aa..f1e0cf78ad 100644
--- a/activejob/test/cases/queue_adapter_test.rb
+++ b/activejob/test/cases/queue_adapter_test.rb
@@ -20,19 +20,6 @@ class QueueAdapterTest < ActiveJob::TestCase
assert_raises(ArgumentError) { ActiveJob::Base.queue_adapter = Mutex.new }
end
- test "should warn on passing an adapter class" do
- klass = Class.new do
- def self.name
- "fake"
- end
-
- def enqueue(*); end
- def enqueue_at(*); end
- end
-
- assert_deprecated { ActiveJob::Base.queue_adapter = klass }
- end
-
test "should allow overriding the queue_adapter at the child class level without affecting the parent or its sibling" do
base_queue_adapter = ActiveJob::Base.queue_adapter
diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb
index 7777e557c9..0e1e0decd1 100644
--- a/activejob/test/cases/queue_naming_test.rb
+++ b/activejob/test/cases/queue_naming_test.rb
@@ -56,7 +56,7 @@ class QueueNamingTest < ActiveSupport::TestCase
original_queue_name = HelloJob.queue_name
begin
- HelloJob.queue_as { self.arguments.first=="1" ? :one : :two }
+ HelloJob.queue_as { self.arguments.first == "1" ? :one : :two }
assert_equal "one", HelloJob.new("1").queue_name
assert_equal "two", HelloJob.new("3").queue_name
ensure
diff --git a/activejob/test/cases/queue_priority_test.rb b/activejob/test/cases/queue_priority_test.rb
index ab4a1bdf7b..b0d0e903fc 100644
--- a/activejob/test/cases/queue_priority_test.rb
+++ b/activejob/test/cases/queue_priority_test.rb
@@ -3,7 +3,7 @@ require "jobs/hello_job"
class QueuePriorityTest < ActiveSupport::TestCase
test "priority unset by default" do
- assert_equal nil, HelloJob.priority
+ assert_nil HelloJob.priority
end
test "uses given priority" do
@@ -32,7 +32,7 @@ class QueuePriorityTest < ActiveSupport::TestCase
original_priority = HelloJob.priority
begin
- HelloJob.queue_with_priority { self.arguments.first=="1" ? 99 : 11 }
+ HelloJob.queue_with_priority { self.arguments.first == "1" ? 99 : 11 }
assert_equal 99, HelloJob.new("1").priority
assert_equal 11, HelloJob.new("3").priority
ensure
diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb
index 253c557cc5..51fc6cc0c4 100644
--- a/activejob/test/cases/test_helper_test.rb
+++ b/activejob/test/cases/test_helper_test.rb
@@ -250,17 +250,17 @@ class EnqueuedJobsTest < ActiveJob::TestCase
HelloJob.perform_later
end
- assert_equal 2, ActiveJob::Base.queue_adapter.enqueued_jobs.count
+ assert_equal 2, queue_adapter.enqueued_jobs.count
end
end
class PerformedJobsTest < ActiveJob::TestCase
def test_performed_enqueue_jobs_with_only_option_doesnt_leak_outside_the_block
- assert_equal nil, queue_adapter.filter
+ assert_nil queue_adapter.filter
perform_enqueued_jobs only: HelloJob do
assert_equal HelloJob, queue_adapter.filter
end
- assert_equal nil, queue_adapter.filter
+ assert_nil queue_adapter.filter
end
def test_assert_performed_jobs
@@ -507,7 +507,7 @@ class PerformedJobsTest < ActiveJob::TestCase
HelloJob.perform_later
end
- assert_equal 2, ActiveJob::Base.queue_adapter.performed_jobs.count
+ assert_equal 2, queue_adapter.performed_jobs.count
end
end
diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb
index dbc7dad109..776f7788de 100644
--- a/activejob/test/helper.rb
+++ b/activejob/test/helper.rb
@@ -4,7 +4,8 @@ require "support/job_buffer"
ActiveSupport.halt_callback_chains_on_return_false = false
GlobalID.app = "aj"
-@adapter = ENV["AJ_ADAPTER"] || "inline"
+@adapter = ENV["AJ_ADAPTER"] || "inline"
+puts "Using #{@adapter}"
if ENV["AJ_INTEGRATION_TESTS"]
require "support/integration/helper"
diff --git a/activejob/test/jobs/application_job.rb b/activejob/test/jobs/application_job.rb
index 4a78b890ec..a009ace51c 100644
--- a/activejob/test/jobs/application_job.rb
+++ b/activejob/test/jobs/application_job.rb
@@ -1,4 +1,2 @@
-require_relative "../support/job_buffer"
-
class ApplicationJob < ActiveJob::Base
end
diff --git a/activejob/test/models/person.rb b/activejob/test/models/person.rb
index 76a8f40616..b5d68ad9c1 100644
--- a/activejob/test/models/person.rb
+++ b/activejob/test/models/person.rb
@@ -6,7 +6,7 @@ class Person
attr_reader :id
def self.find(id)
- raise RecordNotFound.new("Cannot find person with ID=404") if id.to_i==404
+ raise RecordNotFound.new("Cannot find person with ID=404") if id.to_i == 404
new(id)
end
diff --git a/activejob/test/support/backburner/inline.rb b/activejob/test/support/backburner/inline.rb
index 647dbf317f..9758332b6f 100644
--- a/activejob/test/support/backburner/inline.rb
+++ b/activejob/test/support/backburner/inline.rb
@@ -2,7 +2,7 @@ require "backburner"
Backburner::Worker.class_eval do
class << self; alias_method :original_enqueue, :enqueue; end
- def self.enqueue(job_class, args=[], opts={})
+ def self.enqueue(job_class, args = [], opts = {})
job_class.perform(*args)
end
end
diff --git a/activejob/test/support/delayed_job/delayed/backend/test.rb b/activejob/test/support/delayed_job/delayed/backend/test.rb
index a900b18e2a..98d731ff1e 100644
--- a/activejob/test/support/delayed_job/delayed/backend/test.rb
+++ b/activejob/test/support/delayed_job/delayed/backend/test.rb
@@ -26,7 +26,7 @@ module Delayed
self.attempts = 0
self.priority = 0
self.id = (self.class.id += 1)
- hash.each { |k,v| send(:"#{k}=", v) }
+ hash.each { |k, v| send(:"#{k}=", v) }
end
@jobs = []
@@ -63,7 +63,7 @@ module Delayed
jobs = jobs.select { |j| Worker.queues.include?(j.queue) } if Worker.queues.any?
jobs = jobs.select { |j| j.priority >= Worker.min_priority } if Worker.min_priority
jobs = jobs.select { |j| j.priority <= Worker.max_priority } if Worker.max_priority
- jobs.sort_by { |j| [j.priority, j.run_at] }[0..limit-1]
+ jobs.sort_by { |j| [j.priority, j.run_at] }[0..limit - 1]
end
# Lock this job for this worker.
@@ -84,7 +84,7 @@ module Delayed
end
def update_attributes(attrs = {})
- attrs.each { |k,v| send(:"#{k}=", v) }
+ attrs.each { |k, v| send(:"#{k}=", v) }
save
end
diff --git a/activejob/test/support/integration/adapters/que.rb b/activejob/test/support/integration/adapters/que.rb
index 3d35a0439f..20faee3427 100644
--- a/activejob/test/support/integration/adapters/que.rb
+++ b/activejob/test/support/integration/adapters/que.rb
@@ -13,7 +13,7 @@ module QueJobsManager
def start_workers
que_url = ENV["QUE_DATABASE_URL"] || "postgres:///active_jobs_que_int_test"
uri = URI.parse(que_url)
- user = uri.user||ENV["USER"]
+ user = uri.user || ENV["USER"]
pass = uri.password
db = uri.path[1..-1]
%x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database if exists "#{db}"' -U #{user} -t template1}
diff --git a/activejob/test/support/integration/adapters/queue_classic.rb b/activejob/test/support/integration/adapters/queue_classic.rb
index b5d831428e..369693e947 100644
--- a/activejob/test/support/integration/adapters/queue_classic.rb
+++ b/activejob/test/support/integration/adapters/queue_classic.rb
@@ -12,7 +12,7 @@ module QueueClassicJobsManager
def start_workers
uri = URI.parse(ENV["QC_DATABASE_URL"])
- user = uri.user||ENV["USER"]
+ user = uri.user || ENV["USER"]
pass = uri.password
db = uri.path[1..-1]
%x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database if exists "#{db}"' -U #{user} -t template1}
diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb
index 08743c1f05..1c8dfaca59 100644
--- a/activejob/test/support/integration/adapters/sneakers.rb
+++ b/activejob/test/support/integration/adapters/sneakers.rb
@@ -39,7 +39,7 @@ module SneakersJobsManager
@pid = fork do
queues = %w(integration_tests)
workers = queues.map do |q|
- worker_klass = "ActiveJobWorker"+Digest::MD5.hexdigest(q)
+ worker_klass = "ActiveJobWorker" + Digest::MD5.hexdigest(q)
Sneakers.const_set(worker_klass, Class.new(ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper) do
from_queue q
end)
@@ -73,7 +73,7 @@ module SneakersJobsManager
true
end
- protected
+ private
def bunny_publisher
@bunny_publisher ||= begin
p = ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper.send(:publisher)
diff --git a/activejob/test/support/integration/dummy_app_template.rb b/activejob/test/support/integration/dummy_app_template.rb
index 62f6fa13f6..29a5691f30 100644
--- a/activejob/test/support/integration/dummy_app_template.rb
+++ b/activejob/test/support/integration/dummy_app_template.rb
@@ -18,12 +18,13 @@ class TestJob < ActiveJob::Base
queue_as :integration_tests
def perform(x)
- File.open(Rails.root.join("tmp/\#{x}"), "wb+") do |f|
+ File.open(Rails.root.join("tmp/\#{x}.new"), "wb+") do |f|
f.write Marshal.dump({
"locale" => I18n.locale.to_s || "en",
"executed_at" => Time.now.to_r
})
end
+ File.rename(Rails.root.join("tmp/\#{x}.new"), Rails.root.join("tmp/\#{x}"))
end
end
CODE
diff --git a/activejob/test/support/integration/helper.rb b/activejob/test/support/integration/helper.rb
index 1aaee2c809..626b932cce 100644
--- a/activejob/test/support/integration/helper.rb
+++ b/activejob/test/support/integration/helper.rb
@@ -5,6 +5,7 @@ ActiveJob::Base.queue_name_prefix = nil
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__)
args = Rails::Generators::ARGVScrubber.new(["new", dummy_app_path, "--skip-gemfile", "--skip-bundle",
diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb
index 4c4c56c9da..41bf9c89d1 100644
--- a/activejob/test/support/integration/test_case_helpers.rb
+++ b/activejob/test/support/integration/test_case_helpers.rb
@@ -1,4 +1,3 @@
-require "active_support/concern"
require "active_support/core_ext/string/inflections"
require "support/integration/jobs_manager"
@@ -18,7 +17,7 @@ module TestCaseHelpers
end
end
- protected
+ private
def jobs_manager
JobsManager.current_manager
@@ -33,7 +32,7 @@ module TestCaseHelpers
adapter_class_symbols.map(&:to_s).include? adapter
end
- def wait_for_jobs_to_finish_for(seconds=60)
+ def wait_for_jobs_to_finish_for(seconds = 60)
begin
Timeout.timeout(seconds) do
while !job_executed do
@@ -48,7 +47,7 @@ module TestCaseHelpers
Dummy::Application.root.join("tmp/#{id}")
end
- def job_executed(id=@id)
+ def job_executed(id = @id)
job_file(id).exist?
end
@@ -56,11 +55,11 @@ module TestCaseHelpers
Marshal.load(File.binread(job_file(id)))
end
- def job_executed_at(id=@id)
+ def job_executed_at(id = @id)
job_data(id)["executed_at"]
end
- def job_executed_in_locale(id=@id)
+ def job_executed_in_locale(id = @id)
job_data(id)["locale"]
end
end