Skip to content

Commit f797cf6

Browse files
committed
Try to recreate issue
1 parent bd52a38 commit f797cf6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/ecto/integration/timestamps_test.exs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,40 @@ defmodule Ecto.Integration.TimestampsTest do
181181
|> TestRepo.all()
182182
end
183183

184+
test "using built in ecto functions" do
185+
Application.put_env(:ecto_sqlite3, :datetime_type, :text_datetime)
186+
187+
account = insert_account(%{name: "Test"})
188+
189+
insert_product(%{
190+
account_id: account.id,
191+
name: "Foo",
192+
inserted_at: days_ago(1)
193+
})
194+
195+
insert_product(%{
196+
account_id: account.id,
197+
name: "Bar",
198+
inserted_at: days_ago(2)
199+
})
200+
201+
insert_product(%{
202+
account_id: account.id,
203+
name: "Qux",
204+
inserted_at: days_ago(5)
205+
})
206+
207+
assert [
208+
%{name: "Foo"},
209+
%{name: "Bar"}
210+
] =
211+
Product
212+
|> select([p], p)
213+
|> where([p], p.inserted_at >= from_now(-3, "day"))
214+
|> order_by([p], desc: p.inserted_at)
215+
|> TestRepo.all()
216+
end
217+
184218
defp insert_account(attrs) do
185219
%Account{}
186220
|> Account.changeset(attrs)
@@ -192,4 +226,9 @@ defmodule Ecto.Integration.TimestampsTest do
192226
|> Product.changeset(attrs)
193227
|> TestRepo.insert!()
194228
end
229+
230+
defp days_ago(days) do
231+
now = DateTime.utc_now()
232+
DateTime.add(now, -days * 24 * 60 * 60, :second)
233+
end
195234
end

0 commit comments

Comments
 (0)