Skip to content

Commit

Permalink
Cast timestamp to utc_datetime in testing queries
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sorentwo committed Oct 26, 2023
1 parent 943b22b commit e1a60fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/oban/testing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions test/oban/testing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e1a60fd

Please sign in to comment.