From 44a1899b033c322b2cb7f4c73fa954f22b723392 Mon Sep 17 00:00:00 2001 From: Matthew Johnston Date: Tue, 14 May 2024 20:24:21 -0500 Subject: [PATCH] Try to recreate issue --- test/ecto/integration/timestamps_test.exs | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/ecto/integration/timestamps_test.exs b/test/ecto/integration/timestamps_test.exs index 20a23fa..03cbb20 100644 --- a/test/ecto/integration/timestamps_test.exs +++ b/test/ecto/integration/timestamps_test.exs @@ -176,6 +176,40 @@ defmodule Ecto.Integration.TimestampsTest do |> TestRepo.all() end + test "using built in ecto functions" do + Application.put_env(:ecto_sqlite3, :datetime_type, :text_datetime) + + account = insert_account(%{name: "Test"}) + + insert_product(%{ + account_id: account.id, + name: "Foo", + inserted_at: days_ago(1) + }) + + insert_product(%{ + account_id: account.id, + name: "Bar", + inserted_at: days_ago(2) + }) + + insert_product(%{ + account_id: account.id, + name: "Qux", + inserted_at: days_ago(5) + }) + + assert [ + %{name: "Foo"}, + %{name: "Bar"} + ] = + Product + |> select([p], p) + |> where([p], p.inserted_at >= from_now(-3, "day")) + |> order_by([p], desc: p.inserted_at) + |> TestRepo.all() + end + defp insert_account(attrs) do %Account{} |> Account.changeset(attrs) @@ -187,4 +221,9 @@ defmodule Ecto.Integration.TimestampsTest do |> Product.changeset(attrs) |> TestRepo.insert!() end + + defp days_ago(days) do + now = DateTime.utc_now() + DateTime.add(now, -days * 24 * 60 * 60, :second) + end end