From e1a60fda9b8acf05189fddd8b394bee27ea74104 Mon Sep 17 00:00:00 2001 From: Parker Selbert Date: Tue, 24 Oct 2023 22:39:39 -0400 Subject: [PATCH] Cast timestamp to utc_datetime in testing queries Timestamps with a timezone are now cast to `:utc_datetime` via a changeset before running `Oban.Testing` queries. This fixes a regression introduced in f8e5785. Closes #977 --- lib/oban/testing.ex | 9 ++++----- test/oban/testing_test.exs | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/oban/testing.ex b/lib/oban/testing.ex index 94f13bb9..9930409a 100644 --- a/lib/oban/testing.ex +++ b/lib/oban/testing.ex @@ -610,13 +610,12 @@ defmodule Oban.Testing do defp conditions({key, val}, query) when key in @timestamp_fields do {time, delta} = case val do - {time, delta: delta} -> - {time, delta} - - time -> - {time, 1} + {time, delta: delta} -> {time, delta} + time -> {time, 1} end + {:ok, time} = Ecto.Type.cast(:utc_datetime, time) + begin = DateTime.add(time, -delta, :second) until = DateTime.add(time, +delta, :second) diff --git a/test/oban/testing_test.exs b/test/oban/testing_test.exs index eeb3ee8f..625a9894 100644 --- a/test/oban/testing_test.exs +++ b/test/oban/testing_test.exs @@ -264,6 +264,7 @@ defmodule Oban.TestingTest do insert!(%{}, worker: Pong, scheduled_at: seconds_from_now(60)) assert_enqueued worker: Ping, state: "available", scheduled_at: DateTime.utc_now() + assert_enqueued worker: Ping, scheduled_at: DateTime.now!("America/Chicago") assert_enqueued worker: Pong, scheduled_at: seconds_from_now(60) assert_enqueued worker: Pong, scheduled_at: {seconds_from_now(69), delta: 10} end