mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
New Rails apps come with this class already, the job generator creates it for every new job and Rubocop requires it as well. Let's make our lives easier and use the same structure as other Rails projects. This class may be handy one day.
38 lines
703 B
Ruby
38 lines
703 B
Ruby
# frozen_string_literal: true
|
|
|
|
# We need to configure MiniRacer to allow forking.
|
|
# Otherwise this spec hangs on CI.
|
|
# https://github.com/rubyjs/mini_racer#fork-safety
|
|
require "mini_racer"
|
|
MiniRacer::Platform.set_flags!(:single_threaded)
|
|
|
|
require 'spec_helper'
|
|
|
|
class TestJob < ApplicationJob
|
|
def initialize
|
|
@file = Tempfile.new("test-job-result")
|
|
super
|
|
end
|
|
|
|
def perform(message)
|
|
@file.write(message)
|
|
end
|
|
|
|
def result
|
|
@file.rewind
|
|
@file.read
|
|
end
|
|
end
|
|
|
|
describe JobProcessor do
|
|
describe ".perform_forked" do
|
|
let(:job) { TestJob.new }
|
|
|
|
it "executes a job" do
|
|
JobProcessor.perform_forked(job, "hello")
|
|
|
|
expect(job.result).to eq "hello"
|
|
end
|
|
end
|
|
end
|