Skip to content

Commit

Permalink
Try to recreate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
warmwaffles committed May 15, 2024
1 parent ba44719 commit 44a1899
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/ecto/integration/timestamps_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 44a1899

Please sign in to comment.