Make sure scheduled_at is a Time object when asserting enqueued jobs

When the `:at` attribute is sent to the test adapter it is converted
to a float, and that float is what is added to the payload, so we
need to convert back to a Time object.

See:
8a37276416/activejob/lib/active_job/enqueuing.rb (L95)
8a37276416/activejob/lib/active_job/queue_adapters/test_adapter.rb (L34)
This commit is contained in:
Rafael Mendonça França 2023-09-27 15:26:32 +00:00
parent 5d48062099
commit 32eba97a08
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 3 additions and 3 deletions

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

@ -527,7 +527,7 @@ def test_assert_enqueued_with_returns
end
assert_instance_of LoggingJob, job
assert_in_delta 5.minutes.from_now.to_f, job.scheduled_at, 1
assert_in_delta 5.minutes.from_now.to_f, job.scheduled_at.to_f, 1
assert_equal "default", job.queue_name
assert_equal [1, 2, 3, { keyword: true }], job.arguments
end
@ -537,7 +537,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.to_f, job.scheduled_at, 1
assert_in_delta 5.minutes.from_now.to_f, job.scheduled_at.to_f, 1
assert_equal "default", job.queue_name
assert_equal [1, 2, 3, { keyword: true }], job.arguments
end