1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Simplest job and inline queue

This commit is contained in:
David Heinemeier Hansson 2014-05-18 12:32:22 +02:00
parent 60d13d638e
commit 08a2ba99e0
4 changed files with 37 additions and 2 deletions

View file

@ -1,4 +1,11 @@
require 'active_job/queue_adapters/inline_queue'
module ActiveJob
class Base
class << self
def enqueue(*args)
ActiveJob::QueueAdapters::InlineQueue.queue self, *args
end
end
end
end

View file

@ -0,0 +1,11 @@
module ActiveJob
module QueueAdapters
class InlineQueue
class << self
def queue(job, *args)
job.perform *args
end
end
end
end
end

View file

@ -1,7 +1,19 @@
require 'helper'
require 'jobs/hello_job'
class QueuingTest < ActiveSupport::TestCase
test 'the truth' do
assert true
setup do
$BUFFER = []
end
test 'run queued job' do
HelloJob.enqueue
assert_equal "David says hello", $BUFFER.pop
end
test 'run queued job with parameters' do
HelloJob.enqueue "Jamie"
assert_equal "Jamie says hello", $BUFFER.pop
end
end

5
test/jobs/hello_job.rb Normal file
View file

@ -0,0 +1,5 @@
class HelloJob < ActiveJob::Base
def self.perform(greeter = "David")
$BUFFER << "#{greeter} says hello"
end
end