aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2018-02-22 14:14:42 +0000
committerAndrew White <andrew.white@unboxed.co>2018-02-22 14:14:42 +0000
commita9d1167b1fdae6f5f5496738b3e7d1e05949dcd0 (patch)
tree8a46f129aaed18c7c48b35aa0e48f9a19c1bc219 /activejob/test/cases
parent9c0c90979a759a41628e0cd9d73821b0b34d03fc (diff)
downloadrails-a9d1167b1fdae6f5f5496738b3e7d1e05949dcd0.tar.gz
rails-a9d1167b1fdae6f5f5496738b3e7d1e05949dcd0.tar.bz2
rails-a9d1167b1fdae6f5f5496738b3e7d1e05949dcd0.zip
Add support for timezones to Active Job
Record what was the current timezone in effect when the job was enqueued and then restore when the job is executed in same way that the current locale is recorded and restored.
Diffstat (limited to 'activejob/test/cases')
-rw-r--r--activejob/test/cases/job_serialization_test.rb7
-rw-r--r--activejob/test/cases/timezones_test.rb24
2 files changed, 31 insertions, 0 deletions
diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb
index 440051c427..5c9994508e 100644
--- a/activejob/test/cases/job_serialization_test.rb
+++ b/activejob/test/cases/job_serialization_test.rb
@@ -54,4 +54,11 @@ class JobSerializationTest < ActiveSupport::TestCase
job.provider_job_id = "some value set by adapter"
assert_equal job.provider_job_id, job.serialize["provider_job_id"]
end
+
+ test "serialize stores the current timezone" do
+ Time.use_zone "Hawaii" do
+ job = HelloJob.new
+ assert_equal "Hawaii", job.serialize["timezone"]
+ end
+ end
end
diff --git a/activejob/test/cases/timezones_test.rb b/activejob/test/cases/timezones_test.rb
new file mode 100644
index 0000000000..e2095b020d
--- /dev/null
+++ b/activejob/test/cases/timezones_test.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require "helper"
+require "jobs/timezone_dependent_job"
+
+class TimezonesTest < ActiveSupport::TestCase
+ setup do
+ JobBuffer.clear
+ end
+
+ test "it performs the job in the given timezone" do
+ job = TimezoneDependentJob.new("2018-01-01T00:00:00Z")
+ job.timezone = "London"
+ job.perform_now
+
+ assert_equal "Happy New Year!", JobBuffer.last_value
+
+ job = TimezoneDependentJob.new("2018-01-01T00:00:00Z")
+ job.timezone = "Eastern Time (US & Canada)"
+ job.perform_now
+
+ assert_equal "Just 5 hours to go", JobBuffer.last_value
+ end
+end