Skip to content

Commit 44a1899

Browse files
committed
Try to recreate issue
1 parent ba44719 commit 44a1899

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/ecto/integration/timestamps_test.exs

+39
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,40 @@ defmodule Ecto.Integration.TimestampsTest do
176176
|> TestRepo.all()
177177
end
178178

179+
test "using built in ecto functions" do
180+
Application.put_env(:ecto_sqlite3, :datetime_type, :text_datetime)
181+
182+
account = insert_account(%{name: "Test"})
183+
184+
insert_product(%{
185+
account_id: account.id,
186+
name: "Foo",
187+
inserted_at: days_ago(1)
188+
})
189+
190+
insert_product(%{
191+
account_id: account.id,
192+
name: "Bar",
193+
inserted_at: days_ago(2)
194+
})
195+
196+
insert_product(%{
197+
account_id: account.id,
198+
name: "Qux",
199+
inserted_at: days_ago(5)
200+
})
201+
202+
assert [
203+
%{name: "Foo"},
204+
%{name: "Bar"}
205+
] =
206+
Product
207+
|> select([p], p)
208+
|> where([p], p.inserted_at >= from_now(-3, "day"))
209+
|> order_by([p], desc: p.inserted_at)
210+
|> TestRepo.all()
211+
end
212+
179213
defp insert_account(attrs) do
180214
%Account{}
181215
|> Account.changeset(attrs)
@@ -187,4 +221,9 @@ defmodule Ecto.Integration.TimestampsTest do
187221
|> Product.changeset(attrs)
188222
|> TestRepo.insert!()
189223
end
224+
225+
defp days_ago(days) do
226+
now = DateTime.utc_now()
227+
DateTime.add(now, -days * 24 * 60 * 60, :second)
228+
end
190229
end

0 commit comments

Comments
 (0)