diff options
Diffstat (limited to 'activejob/test/support')
22 files changed, 173 insertions, 163 deletions
diff --git a/activejob/test/support/backburner/inline.rb b/activejob/test/support/backburner/inline.rb index f761b53e27..6c708c0b7b 100644 --- a/activejob/test/support/backburner/inline.rb +++ b/activejob/test/support/backburner/inline.rb @@ -1,8 +1,10 @@ -require 'backburner' +# frozen_string_literal: true + +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
\ No newline at end of file +end diff --git a/activejob/test/support/delayed_job/delayed/backend/test.rb b/activejob/test/support/delayed_job/delayed/backend/test.rb index f80ec3a5a6..1691896b7c 100644 --- a/activejob/test/support/delayed_job/delayed/backend/test.rb +++ b/activejob/test/support/delayed_job/delayed/backend/test.rb @@ -1,5 +1,7 @@ -#copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb -require 'ostruct' +# frozen_string_literal: true + +# copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb +require "ostruct" # An in-memory backend suitable only for testing. Tries to behave as if it were an ORM. module Delayed @@ -19,14 +21,13 @@ module Delayed include Delayed::Backend::Base - cattr_accessor :id - self.id = 0 + cattr_accessor :id, default: 0 def initialize(hash = {}) 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 = [] @@ -49,7 +50,7 @@ module Delayed def self.create!(*args); create(*args); end def self.clear_locks!(worker_name) - all.select{|j| j.locked_by == worker_name}.each {|j| j.locked_by = nil; j.locked_at = nil} + all.select { |j| j.locked_by == worker_name }.each { |j| j.locked_by = nil; j.locked_at = nil } end # Find a few candidate jobs to run (in case some immediately get locked by others). @@ -60,10 +61,10 @@ module Delayed !j.failed? end - 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 = 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] end # Lock this job for this worker. @@ -76,7 +77,7 @@ module Delayed self.locked_by = worker end - return true + true end def self.db_time_now @@ -84,7 +85,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/async.rb b/activejob/test/support/integration/adapters/async.rb index 42beb12b1f..ba9674d7a1 100644 --- a/activejob/test/support/integration/adapters/async.rb +++ b/activejob/test/support/integration/adapters/async.rb @@ -1,9 +1,12 @@ +# frozen_string_literal: true + module AsyncJobsManager def setup ActiveJob::Base.queue_adapter = :async + ActiveJob::Base.queue_adapter.immediate = false end def clear_jobs - ActiveJob::AsyncJob::QUEUES.clear + ActiveJob::Base.queue_adapter.shutdown end end diff --git a/activejob/test/support/integration/adapters/backburner.rb b/activejob/test/support/integration/adapters/backburner.rb index 2e82562948..1163ae8178 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 @@ -6,7 +8,8 @@ module BackburnerJobsManager end unless can_run? puts "Cannot run integration tests for backburner. To be able to run integration tests for backburner you need to install and start beanstalkd.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -23,16 +26,15 @@ module BackburnerJobsManager end def tube - @tube ||= Beaneater::Tube.new(Backburner::Worker.connection, "backburner.worker.queue.integration-tests") # backburner dasherizes the queue name + @tube ||= Beaneater::Tube.new(@worker.connection, "backburner.worker.queue.integration-tests") # backburner dasherizes the queue name end def can_run? begin - Backburner::Worker.connection.send :connect! + @worker = Backburner::Worker.new rescue return false end true end end - diff --git a/activejob/test/support/integration/adapters/delayed_job.rb b/activejob/test/support/integration/adapters/delayed_job.rb index 0b591964bc..fc9bae47fa 100644 --- a/activejob/test/support/integration/adapters/delayed_job.rb +++ b/activejob/test/support/integration/adapters/delayed_job.rb @@ -1,5 +1,7 @@ -require 'delayed_job' -require 'delayed_job_active_record' +# frozen_string_literal: true + +require "delayed_job" +require "delayed_job_active_record" module DelayedJobJobsManager def setup @@ -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 83c38f706f..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 @@ -12,4 +14,3 @@ module InlineJobsManager def stop_workers end end - diff --git a/activejob/test/support/integration/adapters/qu.rb b/activejob/test/support/integration/adapters/qu.rb deleted file mode 100644 index 256ddb3cf3..0000000000 --- a/activejob/test/support/integration/adapters/qu.rb +++ /dev/null @@ -1,38 +0,0 @@ -module QuJobsManager - def setup - require 'qu-rails' - require 'qu-redis' - ActiveJob::Base.queue_adapter = :qu - ENV['REDISTOGO_URL'] = "redis://127.0.0.1:6379/12" - backend = Qu::Backend::Redis.new - backend.namespace = "active_jobs_int_test" - Qu.backend = backend - Qu.logger = Rails.logger - Qu.interval = 0.5 - unless can_run? - puts "Cannot run integration tests for qu. To be able to run integration tests for qu you need to install and start redis.\n" - exit - end - end - - def clear_jobs - Qu.clear "integration_tests" - end - - def start_workers - @thread = Thread.new { Qu::Worker.new("integration_tests").start } - end - - def stop_workers - @thread.kill - end - - def can_run? - begin - Qu.backend.connection.client.connect - rescue - return false - end - true - end -end diff --git a/activejob/test/support/integration/adapters/que.rb b/activejob/test/support/integration/adapters/que.rb index 0cd8952a28..f231e5e12d 100644 --- a/activejob/test/support/integration/adapters/que.rb +++ b/activejob/test/support/integration/adapters/que.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module QueJobsManager def setup - require 'sequel' + require "sequel" ActiveJob::Base.queue_adapter = :que Que.mode = :off Que.worker_count = 1 @@ -11,13 +13,13 @@ module QueJobsManager end def start_workers - que_url = ENV['QUE_DATABASE_URL'] || 'postgres:///active_jobs_que_int_test' + 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} - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'drop database if exists "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'create database "#{db}"' -U #{user} -t template1} Que.connection = Sequel.connect(que_url) Que.migrate! @@ -30,7 +32,8 @@ module QueJobsManager rescue Sequel::DatabaseConnectionError puts "Cannot run integration tests for que. To be able to run integration tests for que you need to install and start postgresql.\n" - exit + status = ENV["CI"] ? false : true + exit status end def stop_workers diff --git a/activejob/test/support/integration/adapters/queue_classic.rb b/activejob/test/support/integration/adapters/queue_classic.rb index 29c04bf625..2b5375461a 100644 --- a/activejob/test/support/integration/adapters/queue_classic.rb +++ b/activejob/test/support/integration/adapters/queue_classic.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module QueueClassicJobsManager def setup - ENV['QC_DATABASE_URL'] ||= 'postgres:///active_jobs_qc_int_test' - ENV['QC_RAILS_DATABASE'] = 'false' - ENV['QC_LISTEN_TIME'] = "0.5" + ENV["QC_DATABASE_URL"] ||= "postgres:///active_jobs_qc_int_test" + ENV["QC_RAILS_DATABASE"] = "false" + ENV["QC_LISTEN_TIME"] = "0.5" ActiveJob::Base.queue_adapter = :queue_classic end @@ -11,27 +13,28 @@ module QueueClassicJobsManager end def start_workers - uri = URI.parse(ENV['QC_DATABASE_URL']) - user = uri.user||ENV['USER'] + uri = URI.parse(ENV["QC_DATABASE_URL"]) + 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} - %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'create database "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'drop database if exists "#{db}"' -U #{user} -t template1} + %x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -X -c 'create database "#{db}"' -U #{user} -t template1} QC::Setup.create QC.default_conn_adapter.disconnect QC.default_conn_adapter = nil @pid = fork do - worker = QC::Worker.new(q_name: 'integration_tests') + worker = QC::Worker.new(q_name: "integration_tests") worker.start end rescue PG::ConnectionBad puts "Cannot run integration tests for queue_classic. To be able to run integration tests for queue_classic you need to install and start postgresql.\n" - exit + status = ENV["CI"] ? false : true + exit status end def stop_workers - Process.kill 'HUP', @pid + Process.kill "HUP", @pid end end diff --git a/activejob/test/support/integration/adapters/resque.rb b/activejob/test/support/integration/adapters/resque.rb index 912f4bc387..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 9aa07bcb52..c79de12eaf 100644 --- a/activejob/test/support/integration/adapters/sidekiq.rb +++ b/activejob/test/support/integration/adapters/sidekiq.rb @@ -1,15 +1,17 @@ -require 'sidekiq/api' +# frozen_string_literal: true -require 'sidekiq/testing' +require "sidekiq/api" + +require "sidekiq/testing" Sidekiq::Testing.disable! module SidekiqJobsManager - def setup 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 @@ -26,10 +28,10 @@ module SidekiqJobsManager continue_read.close death_write.close - # Celluloid & Sidekiq are not warning-clean :( + # Sidekiq is not warning-clean :( $VERBOSE = false - $stdin.reopen('/dev/null') + $stdin.reopen(File::NULL) $stdout.sync = true $stderr.sync = true @@ -49,14 +51,12 @@ module SidekiqJobsManager self_write.puts("TERM") end - require 'celluloid' - Celluloid.logger = nil - require 'sidekiq/launcher' - sidekiq = Sidekiq::Launcher.new({queues: ["integration_tests"], + require "sidekiq/cli" + require "sidekiq/launcher" + sidekiq = Sidekiq::Launcher.new(queues: ["integration_tests"], environment: "test", concurrency: 1, - timeout: 1, - }) + timeout: 1) Sidekiq.average_scheduled_poll_interval = 0.5 Sidekiq.options[:poll_interval_average] = 1 begin @@ -81,7 +81,7 @@ module SidekiqJobsManager def stop_workers if @pid - Process.kill 'TERM', @pid + Process.kill "TERM", @pid Process.wait @pid end end diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb index 875803a2d8..eb8d4cc2d5 100644 --- a/activejob/test/support/integration/adapters/sneakers.rb +++ b/activejob/test/support/integration/adapters/sneakers.rb @@ -1,34 +1,25 @@ -require 'sneakers/runner' -require 'sneakers/publisher' -require 'timeout' - -module Sneakers - class Publisher - def safe_ensure_connected - @mutex.synchronize do - ensure_connection! unless connected? - end - end - end -end +# frozen_string_literal: true +require "sneakers/runner" +require "timeout" module SneakersJobsManager def setup ActiveJob::Base.queue_adapter = :sneakers - Sneakers.configure :heartbeat => 2, - :amqp => 'amqp://guest:guest@localhost:5672', - :vhost => '/', - :exchange => 'active_jobs_sneakers_int_test', - :exchange_type => :direct, - :daemonize => true, - :threads => 1, - :workers => 1, - :pid_path => Rails.root.join("tmp/sneakers.pid").to_s, - :log => Rails.root.join("log/sneakers.log").to_s + Sneakers.configure heartbeat: 2, + amqp: "amqp://guest:guest@localhost:5672", + vhost: "/", + exchange: "active_jobs_sneakers_int_test", + exchange_type: :direct, + daemonize: true, + threads: 1, + workers: 1, + pid_path: Rails.root.join("tmp/sneakers.pid").to_s, + log: Rails.root.join("log/sneakers.log").to_s unless can_run? puts "Cannot run integration tests for sneakers. To be able to run integration tests for sneakers you need to install and start rabbitmq.\n" - exit + status = ENV["CI"] ? false : true + exit status end end @@ -40,7 +31,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) @@ -60,8 +51,8 @@ module SneakersJobsManager end def stop_workers - Process.kill 'TERM', @pid - Process.kill 'TERM', File.open(Rails.root.join("tmp/sneakers.pid").to_s).read.to_i + Process.kill "TERM", @pid + Process.kill "TERM", File.open(Rails.root.join("tmp/sneakers.pid").to_s).read.to_i rescue end @@ -74,11 +65,11 @@ module SneakersJobsManager true end - protected + private def bunny_publisher @bunny_publisher ||= begin p = ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper.send(:publisher) - p.safe_ensure_connected + p.ensure_connection! p end end @@ -86,5 +77,4 @@ module SneakersJobsManager def bunny_queue @queue ||= bunny_publisher.exchange.channel.queue "integration_tests", durable: true end - end 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 262ca72327..b56dd3e591 100644 --- a/activejob/test/support/integration/dummy_app_template.rb +++ b/activejob/test/support/integration/dummy_app_template.rb @@ -1,29 +1,31 @@ -if ENV['AJ_ADAPTER'] == 'delayed_job' +# frozen_string_literal: true + +if ENV["AJ_ADAPTER"] == "delayed_job" generate "delayed_job:active_record", "--quiet" end -rake("db:migrate") - -initializer 'activejob.rb', <<-CODE -require "#{File.expand_path("../jobs_manager.rb", __FILE__)}" +initializer "activejob.rb", <<-CODE +require "#{File.expand_path("jobs_manager.rb", __dir__)}" JobsManager.current_manager.setup CODE -initializer 'i18n.rb', <<-CODE +initializer "i18n.rb", <<-CODE I18n.available_locales = [:en, :de] CODE -file 'app/jobs/test_job.rb', <<-CODE +file "app/jobs/test_job.rb", <<-CODE 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", + "timezone" => Time.zone.try(:name) || "UTC", "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 4a1b0bfbcb..c5fa2b136f 100644 --- a/activejob/test/support/integration/helper.rb +++ b/activejob/test/support/integration/helper.rb @@ -1,12 +1,15 @@ -puts "\n\n*** rake aj:integration:#{ENV['AJ_ADAPTER']} ***\n" +# frozen_string_literal: true + +puts "\n\n*** rake test:integration:#{ENV['AJ_ADAPTER']} ***\n" ENV["RAILS_ENV"] = "test" ActiveJob::Base.queue_name_prefix = nil -require 'rails/generators/rails/app/app_generator' +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! @@ -14,12 +17,13 @@ Rails::Generators::AppGenerator.start args require "#{dummy_app_path}/config/environment.rb" -ActiveRecord::Migrator.migrations_paths = [ Rails.root.join('db/migrate').to_s ] -require 'rails/test_help' +ActiveRecord::Migrator.migrations_paths = [ Rails.root.join("db/migrate").to_s ] +ActiveRecord::Tasks::DatabaseTasks.migrate +require "rails/test_help" Rails.backtrace_cleaner.remove_silencers! -require_relative 'test_case_helpers' +require_relative "test_case_helpers" ActiveSupport::TestCase.include(TestCaseHelpers) JobsManager.current_manager.start_workers diff --git a/activejob/test/support/integration/jobs_manager.rb b/activejob/test/support/integration/jobs_manager.rb index 78d48e8d9a..4775f52b2f 100644 --- a/activejob/test/support/integration/jobs_manager.rb +++ b/activejob/test/support/integration/jobs_manager.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class JobsManager @@managers = {} attr :adapter_name def self.current_manager - @@managers[ENV['AJ_ADAPTER']] ||= new(ENV['AJ_ADAPTER']) + @@managers[ENV["AJ_ADAPTER"]] ||= new(ENV["AJ_ADAPTER"]) end def initialize(adapter_name) diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb index 9897f76fd0..3d9b265b66 100644 --- a/activejob/test/support/integration/test_case_helpers.rb +++ b/activejob/test/support/integration/test_case_helpers.rb @@ -1,5 +1,6 @@ -require 'active_support/concern' -require 'support/integration/jobs_manager' +# frozen_string_literal: true + +require "support/integration/jobs_manager" module TestCaseHelpers extend ActiveSupport::Concern @@ -17,7 +18,7 @@ module TestCaseHelpers end end - protected + private def jobs_manager JobsManager.current_manager @@ -28,10 +29,10 @@ module TestCaseHelpers end def adapter_is?(*adapter_class_symbols) - adapter_class_symbols.map(&:to_s).include?(ActiveJob::Base.queue_adapter.class.name.split("::").last.gsub(/Adapter$/, '').underscore) + adapter_class_symbols.map(&:to_s).include? ActiveJob::Base.queue_adapter_name 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 @@ -46,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 @@ -54,11 +55,15 @@ 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 + + def job_executed_in_timezone(id = @id) + job_data(id)["timezone"] + end end 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 0950e52d28..4ca65c1cd4 100644 --- a/activejob/test/support/que/inline.rb +++ b/activejob/test/support/que/inline.rb @@ -1,4 +1,6 @@ -require 'que' +# frozen_string_literal: true + +require "que" Que::Job.class_eval do class << self; alias_method :original_enqueue, :enqueue; end @@ -9,6 +11,6 @@ Que::Job.class_eval do options.delete(:priority) args << options unless options.empty? end - self.run(*args) + run(*args) end end diff --git a/activejob/test/support/queue_classic/inline.rb b/activejob/test/support/queue_classic/inline.rb index 5743d5bbb5..0695a34c27 100644 --- a/activejob/test/support/queue_classic/inline.rb +++ b/activejob/test/support/queue_classic/inline.rb @@ -1,21 +1,24 @@ -require 'queue_classic' +# frozen_string_literal: true + +require "queue_classic" +require "active_support/core_ext/module/redefine_method" module QC class Queue - def enqueue(method, *args) - receiver_str, _, message = method.rpartition('.') + redefine_method(:enqueue) do |method, *args| + receiver_str, _, message = method.rpartition(".") receiver = eval(receiver_str) receiver.send(message, *args) end - def enqueue_in(seconds, method, *args) - receiver_str, _, message = method.rpartition('.') + redefine_method(:enqueue_in) do |seconds, method, *args| + receiver_str, _, message = method.rpartition(".") receiver = eval(receiver_str) receiver.send(message, *args) end - def enqueue_at(not_before, method, *args) - receiver_str, _, message = method.rpartition('.') + redefine_method(:enqueue_at) do |not_before, method, *args| + receiver_str, _, message = method.rpartition(".") receiver = eval(receiver_str) receiver.send(message, *args) end diff --git a/activejob/test/support/sneakers/inline.rb b/activejob/test/support/sneakers/inline.rb index 16d9b830fa..e772c68c6e 100644 --- a/activejob/test/support/sneakers/inline.rb +++ b/activejob/test/support/sneakers/inline.rb @@ -1,10 +1,13 @@ -require 'sneakers' +# frozen_string_literal: true + +require "sneakers" +require "active_support/core_ext/module/redefine_method" module Sneakers module Worker module ClassMethods - def enqueue(msg) - worker = self.new(nil, nil, {}) + redefine_method(:enqueue) do |msg| + worker = new(nil, nil, {}) worker.work(*msg) end end diff --git a/activejob/test/support/stubs/strong_parameters.rb b/activejob/test/support/stubs/strong_parameters.rb new file mode 100644 index 0000000000..acba3a4504 --- /dev/null +++ b/activejob/test/support/stubs/strong_parameters.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class Parameters + def initialize(parameters = {}) + @parameters = parameters.with_indifferent_access + end + + def permitted? + true + end + + def to_h + @parameters.to_h + end +end |