Remove outdated Job test helpers

This logic around testing jobs is already handled by integrations with ActiveJob since Rails 4.2
This commit is contained in:
Matt-Yorkley
2021-05-29 16:37:06 +01:00
parent 834140f0a2
commit 53e3e2b66d
4 changed files with 1 additions and 82 deletions

View File

@@ -36,10 +36,8 @@ describe UserPasswordsController, type: :controller do
it "renders Darkswarm" do
setup_email
clear_jobs
user.send_reset_password_instructions
flush_jobs # Send the reset password instructions
user.reload
spree_get :edit, reset_password_token: user.reset_password_token

View File

@@ -13,16 +13,8 @@ describe HeartbeatJob do
end
it "updates the last_job_queue_heartbeat_at config var" do
run_job
HeartbeatJob.perform_now
expect(Time.parse(Spree::Config.last_job_queue_heartbeat_at).in_time_zone).to eq(run_time)
end
end
private
def run_job
clear_jobs
HeartbeatJob.perform_now
flush_jobs ignore_exceptions: false
end
end

View File

@@ -199,7 +199,6 @@ RSpec.configure do |config|
config.include OpenFoodNetwork::DistributionHelper
config.include OpenFoodNetwork::HtmlHelper
config.include ActionView::Helpers::DateHelper
config.include OpenFoodNetwork::DelayedJobHelper
config.include OpenFoodNetwork::PerformanceHelper
config.include DownloadsHelper, type: :feature
config.include ActiveJob::TestHelper

View File

@@ -1,70 +0,0 @@
# frozen_string_literal: true
module OpenFoodNetwork
module DelayedJobHelper
# Process all pending Delayed jobs, keeping in mind jobs could spawn new
# delayed job (so things might be added to the queue while processing)
def flush_jobs(options = {})
options[:ignore_exceptions] ||= false
Delayed::Worker.new.work_off(100)
unless options[:ignore_exceptions]
Delayed::Job.all.each do |job|
if job.last_error.present?
throw "There was an error in a delayed job: #{job.last_error}"
end
end
end
end
def clear_jobs
Delayed::Job.delete_all
end
# expect { foo }.to enqueue_job MyJob, field1: 'foo', field2: 'bar'
RSpec::Matchers.define :enqueue_job do |klass, options = {}|
match do |event_proc|
last_job_id_before = Delayed::Job.last.andand.id || 0
begin
event_proc.call
rescue StandardError => e
@exception = e
raise e
end
@jobs_created = Delayed::Job.where('id > ?', last_job_id_before)
@jobs_created.any? do |job|
job = job.payload_object
match = true
match &= (job.class == klass)
options.each_pair do |k, v|
begin
match &= (job[k] == v)
rescue NameError
match = false
end
end
match
end
end
failure_message do |_event_proc|
@exception || "expected #{klass} to be enqueued matching #{options.inspect} (#{@jobs_created.count} others enqueued)"
end
failure_message_when_negated do |_event_proc|
@exception || "expected #{klass} to not be enqueued matching #{options.inspect}"
end
def supports_block_expectations?
true
end
end
end
end