aboutsummaryrefslogtreecommitdiffstats
path: root/activejob
diff options
context:
space:
mode:
authorAbdelkader Boudih <terminale@gmail.com>2014-08-17 13:23:24 +0000
committerAbdelkader Boudih <terminale@gmail.com>2014-08-17 23:10:45 +0000
commit931cfc40796bfd2f4638d8ca7a11723d7562e9cd (patch)
tree16b02f80182f49bff8e24aef35730111faf48f4d /activejob
parent2f7b239fca6630e49ba8ad9df6fc7db25e1080f0 (diff)
downloadrails-931cfc40796bfd2f4638d8ca7a11723d7562e9cd.tar.gz
rails-931cfc40796bfd2f4638d8ca7a11723d7562e9cd.tar.bz2
rails-931cfc40796bfd2f4638d8ca7a11723d7562e9cd.zip
[ActiveJob] Fix tests for sucker_punch
Diffstat (limited to 'activejob')
-rw-r--r--activejob/test/cases/job_serialization_test.rb4
-rw-r--r--activejob/test/cases/logging_test.rb2
-rw-r--r--activejob/test/cases/queuing_test.rb6
-rw-r--r--activejob/test/cases/rescue_test.rb4
-rw-r--r--activejob/test/helper.rb20
-rw-r--r--activejob/test/jobs/gid_job.rb2
-rw-r--r--activejob/test/jobs/hello_job.rb2
-rw-r--r--activejob/test/jobs/rescue_job.rb4
8 files changed, 32 insertions, 12 deletions
diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb
index f3b89d8899..fc1b77744c 100644
--- a/activejob/test/cases/job_serialization_test.rb
+++ b/activejob/test/cases/job_serialization_test.rb
@@ -4,12 +4,12 @@ require 'models/person'
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
diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb
index f0f315c906..888c183a0b 100644
--- a/activejob/test/cases/logging_test.rb
+++ b/activejob/test/cases/logging_test.rb
@@ -23,7 +23,7 @@ class AdapterTest < ActiveSupport::TestCase
def setup
super
- Thread.current[:ajbuffer] = []
+ JobBuffer.clear
@old_logger = ActiveJob::Base.logger
@logger = ActiveSupport::TaggedLogging.new(TestLogger.new)
set_logger @logger
diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb
index 49760ce9c0..f020316d7e 100644
--- a/activejob/test/cases/queuing_test.rb
+++ b/activejob/test/cases/queuing_test.rb
@@ -5,17 +5,17 @@ require 'active_support/core_ext/numeric/time'
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
diff --git a/activejob/test/cases/rescue_test.rb b/activejob/test/cases/rescue_test.rb
index 4fbd27fe6c..250ab68671 100644
--- a/activejob/test/cases/rescue_test.rb
+++ b/activejob/test/cases/rescue_test.rb
@@ -5,13 +5,13 @@ require 'active_support/core_ext/object/inclusion'
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
diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb
index a56b35da12..ca67700273 100644
--- a/activejob/test/helper.rb
+++ b/activejob/test/helper.rb
@@ -28,3 +28,23 @@ require "adapters/#{@adapter}"
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
diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb
index eeb34c8a87..35c2366ec4 100644
--- a/activejob/test/jobs/gid_job.rb
+++ b/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
diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb
index cb067bbe69..4c6256af0d 100644
--- a/activejob/test/jobs/hello_job.rb
+++ b/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
diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb
index e42de4876e..77084160d9 100644
--- a/activejob/test/jobs/rescue_job.rb
+++ b/activejob/test/jobs/rescue_job.rb
@@ -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
@@ -14,7 +14,7 @@ class RescueJob < ActiveJob::Base
when "other"
raise OtherError
else
- Thread.current[:ajbuffer] << "performed beautifully"
+ JobBuffer.add('performed beautifully')
end
end
end