aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/jobs
diff options
context:
space:
mode:
authorAbdelkader Boudih <terminale@gmail.com>2014-08-12 09:17:19 +0000
committerAbdelkader Boudih <terminale@gmail.com>2014-08-12 09:17:19 +0000
commita75f085941b2d6aed160f5f2f7e64e5fc7e03826 (patch)
tree23174b264983a15c3108ec912b355829c5f17a80 /activejob/test/jobs
parentb45b99894a60eda434abec94d133a1cfd8de2dda (diff)
parent14f74a8331f94150dfee653224de8fc837797709 (diff)
downloadrails-a75f085941b2d6aed160f5f2f7e64e5fc7e03826.tar.gz
rails-a75f085941b2d6aed160f5f2f7e64e5fc7e03826.tar.bz2
rails-a75f085941b2d6aed160f5f2f7e64e5fc7e03826.zip
Add 'activejob/' from commit '14f74a8331f94150dfee653224de8fc837797709'
git-subtree-dir: activejob git-subtree-mainline: b45b99894a60eda434abec94d133a1cfd8de2dda git-subtree-split: 14f74a8331f94150dfee653224de8fc837797709
Diffstat (limited to 'activejob/test/jobs')
-rw-r--r--activejob/test/jobs/callback_job.rb32
-rw-r--r--activejob/test/jobs/gid_job.rb6
-rw-r--r--activejob/test/jobs/hello_job.rb5
-rw-r--r--activejob/test/jobs/logging_job.rb10
-rw-r--r--activejob/test/jobs/nested_job.rb10
-rw-r--r--activejob/test/jobs/rescue_job.rb20
6 files changed, 83 insertions, 0 deletions
diff --git a/activejob/test/jobs/callback_job.rb b/activejob/test/jobs/callback_job.rb
new file mode 100644
index 0000000000..056dd073e8
--- /dev/null
+++ b/activejob/test/jobs/callback_job.rb
@@ -0,0 +1,32 @@
+class CallbackJob < ActiveJob::Base
+ before_perform ->(job) { job.history << "CallbackJob ran before_perform" }
+ after_perform ->(job) { job.history << "CallbackJob ran after_perform" }
+
+ before_enqueue ->(job) { job.history << "CallbackJob ran before_enqueue" }
+ after_enqueue ->(job) { job.history << "CallbackJob ran after_enqueue" }
+
+ around_perform :around_perform
+ around_enqueue :around_enqueue
+
+
+ def perform(person = "david")
+ # NOTHING!
+ end
+
+ def history
+ @history ||= []
+ end
+
+ # FIXME: Not sure why these can't be declared inline like before/after
+ def around_perform
+ history << "CallbackJob ran around_perform_start"
+ yield
+ history << "CallbackJob ran around_perform_stop"
+ end
+
+ def around_enqueue
+ history << "CallbackJob ran around_enqueue_start"
+ yield
+ history << "CallbackJob ran around_enqueue_stop"
+ end
+end
diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb
new file mode 100644
index 0000000000..c69e38d3cc
--- /dev/null
+++ b/activejob/test/jobs/gid_job.rb
@@ -0,0 +1,6 @@
+class GidJob < ActiveJob::Base
+ def perform(person)
+ $BUFFER << "Person with ID: #{person.id}"
+ end
+end
+ \ No newline at end of file
diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb
new file mode 100644
index 0000000000..25441dd0c8
--- /dev/null
+++ b/activejob/test/jobs/hello_job.rb
@@ -0,0 +1,5 @@
+class HelloJob < ActiveJob::Base
+ def perform(greeter = "David")
+ $BUFFER << "#{greeter} says hello"
+ end
+end
diff --git a/activejob/test/jobs/logging_job.rb b/activejob/test/jobs/logging_job.rb
new file mode 100644
index 0000000000..d84ed8589b
--- /dev/null
+++ b/activejob/test/jobs/logging_job.rb
@@ -0,0 +1,10 @@
+class LoggingJob < ActiveJob::Base
+ def perform(dummy)
+ logger.info "Dummy, here is it: #{dummy}"
+ end
+
+ def job_id
+ "LOGGING-JOB-ID"
+ end
+end
+
diff --git a/activejob/test/jobs/nested_job.rb b/activejob/test/jobs/nested_job.rb
new file mode 100644
index 0000000000..fd66f68991
--- /dev/null
+++ b/activejob/test/jobs/nested_job.rb
@@ -0,0 +1,10 @@
+class NestedJob < ActiveJob::Base
+ def perform
+ LoggingJob.enqueue "NestedJob"
+ end
+
+ def job_id
+ "NESTED-JOB-ID"
+ end
+end
+
diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb
new file mode 100644
index 0000000000..acf2b81515
--- /dev/null
+++ b/activejob/test/jobs/rescue_job.rb
@@ -0,0 +1,20 @@
+class RescueJob < ActiveJob::Base
+ class OtherError < StandardError; end
+
+ rescue_from(ArgumentError) do
+ $BUFFER << "rescued from ArgumentError"
+ arguments[0] = "DIFFERENT!"
+ retry_now
+ end
+
+ def perform(person = "david")
+ case person
+ when "david"
+ raise ArgumentError, "Hair too good"
+ when "other"
+ raise OtherError
+ else
+ $BUFFER << "performed beautifully"
+ end
+ end
+end