fix: Ensure ActiveJob::TestHelper sets scheduled_at to a Float

I noticed a difference in behavior when inspecting `ActiveJob::Core#scheduled_at` in non-test environments vs when inspecting in while executing tests.

Prior to this change, `ActiveJob::TestHelper` would set `ActiveJob::Core#scheduled_at` to a `Time` object in tests,
however this attribute was set to a `Float` objects in non-test environments:

<d1aa6af5cc/activejob/lib/active_job/core.rb (L161)>

This change ensures parity in all runtime environments.
This commit is contained in:
Ariel Valentin 2022-10-17 18:36:00 +00:00 committed by GitHub
parent 69cd9c2e8f
commit 658fd53741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

@ -710,7 +710,7 @@ def deserialize_args_for_assertion(job)
def instantiate_job(payload, skip_deserialize_arguments: false)
job = payload[:job].deserialize(payload)
job.scheduled_at = Time.at(payload[:at]) if payload.key?(:at)
job.scheduled_at = payload[:at].to_f if payload.key?(:at)
job.send(:deserialize_arguments_if_needed) unless skip_deserialize_arguments
job
end

@ -515,7 +515,7 @@ def test_assert_enqueued_with_returns
end
assert_instance_of LoggingJob, job
assert_in_delta 5.minutes.from_now, job.scheduled_at, 1
assert_in_delta 5.minutes.from_now.to_f, job.scheduled_at, 1
assert_equal "default", job.queue_name
assert_equal [1, 2, 3, { keyword: true }], job.arguments
end
@ -525,7 +525,7 @@ def test_assert_enqueued_with_with_no_block_returns
job = assert_enqueued_with(job: LoggingJob)
assert_instance_of LoggingJob, job
assert_in_delta 5.minutes.from_now, job.scheduled_at, 1
assert_in_delta 5.minutes.from_now.to_f, job.scheduled_at, 1
assert_equal "default", job.queue_name
assert_equal [1, 2, 3, { keyword: true }], job.arguments
end