Skip to content

Commit

Permalink
[ActiveJob] Fix tests for sucker_punch
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Aug 17, 2014
1 parent 2f7b239 commit 931cfc4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions activejob/test/cases/job_serialization_test.rb
Expand Up @@ -4,12 +4,12 @@

class JobSerializationTest < ActiveSupport::TestCase
setup do
Thread.current[:ajbuffer] = []
JobBuffer.clear
@person = Person.find(5)
end

test 'serialize job with gid' do
GidJob.enqueue @person
assert_equal "Person with ID: 5", Thread.current[:ajbuffer].pop
assert_equal "Person with ID: 5", JobBuffer.last_value
end
end
2 changes: 1 addition & 1 deletion activejob/test/cases/logging_test.rb
Expand Up @@ -23,7 +23,7 @@ def messages

def setup
super
Thread.current[:ajbuffer] = []
JobBuffer.clear
@old_logger = ActiveJob::Base.logger
@logger = ActiveSupport::TaggedLogging.new(TestLogger.new)
set_logger @logger
Expand Down
6 changes: 3 additions & 3 deletions activejob/test/cases/queuing_test.rb
Expand Up @@ -5,17 +5,17 @@

class QueuingTest < ActiveSupport::TestCase
setup do
Thread.current[:ajbuffer] = []
JobBuffer.clear
end

test 'run queued job' do
HelloJob.enqueue
assert_equal "David says hello", Thread.current[:ajbuffer].pop
assert_equal "David says hello", JobBuffer.last_value
end

test 'run queued job with arguments' do
HelloJob.enqueue "Jamie"
assert_equal "Jamie says hello", Thread.current[:ajbuffer].pop
assert_equal "Jamie says hello", JobBuffer.last_value
end

test 'run queued job later' do
Expand Down
4 changes: 2 additions & 2 deletions activejob/test/cases/rescue_test.rb
Expand Up @@ -5,13 +5,13 @@

class RescueTest < ActiveSupport::TestCase
setup do
Thread.current[:ajbuffer] = []
JobBuffer.clear
end

test 'rescue perform exception with retry' do
job = RescueJob.new
job.execute(SecureRandom.uuid, "david")
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], Thread.current[:ajbuffer]
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], JobBuffer.values
end

test 'let through unhandled perform exception' do
Expand Down
20 changes: 20 additions & 0 deletions activejob/test/helper.rb
Expand Up @@ -28,3 +28,23 @@ def ruby_193?
require 'active_support/testing/autorun'

ActiveJob::Base.logger.level = Logger::DEBUG

module JobBuffer
class << self
def clear
@buffer = []
end

def add(value)
@buffer << value
end

def values
@buffer
end

def last_value
@buffer.last
end
end
end
2 changes: 1 addition & 1 deletion activejob/test/jobs/gid_job.rb
@@ -1,6 +1,6 @@
class GidJob < ActiveJob::Base
def perform(person)
Thread.current[:ajbuffer] << "Person with ID: #{person.id}"
JobBuffer.add("Person with ID: #{person.id}")
end
end

2 changes: 1 addition & 1 deletion activejob/test/jobs/hello_job.rb
@@ -1,5 +1,5 @@
class HelloJob < ActiveJob::Base
def perform(greeter = "David")
Thread.current[:ajbuffer] << "#{greeter} says hello"
JobBuffer.add("#{greeter} says hello")
end
end
4 changes: 2 additions & 2 deletions activejob/test/jobs/rescue_job.rb
Expand Up @@ -2,7 +2,7 @@ class RescueJob < ActiveJob::Base
class OtherError < StandardError; end

rescue_from(ArgumentError) do
Thread.current[:ajbuffer] << "rescued from ArgumentError"
JobBuffer.add('rescued from ArgumentError')
arguments[0] = "DIFFERENT!"
retry_now
end
Expand All @@ -14,7 +14,7 @@ def perform(person = "david")
when "other"
raise OtherError
else
Thread.current[:ajbuffer] << "performed beautifully"
JobBuffer.add('performed beautifully')
end
end
end

0 comments on commit 931cfc4

Please sign in to comment.