2018-02-22 09:14:42 -05:00
|
|
|
# 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
|
2020-06-04 00:19:22 -04:00
|
|
|
|
|
|
|
test "perform_now passes down current timezone to the job" do
|
|
|
|
Time.zone = "America/New_York"
|
|
|
|
|
|
|
|
Time.use_zone("London") do
|
|
|
|
job = TimezoneDependentJob.new("2018-01-01T00:00:00Z")
|
|
|
|
assert_equal "London", job.timezone
|
|
|
|
job.perform_now
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "Happy New Year!", JobBuffer.last_value
|
2020-11-14 20:02:22 -05:00
|
|
|
ensure
|
|
|
|
Time.zone = nil
|
2020-06-04 00:19:22 -04:00
|
|
|
end
|
2018-02-22 09:14:42 -05:00
|
|
|
end
|