diff options
Diffstat (limited to 'activejob/test')
-rw-r--r-- | activejob/test/cases/queue_naming_test.rb | 2 | ||||
-rw-r--r-- | activejob/test/cases/queue_priority_test.rb | 4 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 8 | ||||
-rw-r--r-- | activejob/test/helper.rb | 3 | ||||
-rw-r--r-- | activejob/test/models/person.rb | 2 | ||||
-rw-r--r-- | activejob/test/support/backburner/inline.rb | 2 | ||||
-rw-r--r-- | activejob/test/support/delayed_job/delayed/backend/test.rb | 6 | ||||
-rw-r--r-- | activejob/test/support/integration/adapters/que.rb | 2 | ||||
-rw-r--r-- | activejob/test/support/integration/adapters/queue_classic.rb | 2 | ||||
-rw-r--r-- | activejob/test/support/integration/adapters/sneakers.rb | 4 | ||||
-rw-r--r-- | activejob/test/support/integration/dummy_app_template.rb | 3 | ||||
-rw-r--r-- | activejob/test/support/integration/helper.rb | 1 | ||||
-rw-r--r-- | activejob/test/support/integration/test_case_helpers.rb | 11 |
13 files changed, 26 insertions, 24 deletions
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/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 |