Skip to content

Commit 2b01d45

Browse files
author
spicychickensauce
committed
Add test for values using naive_datetime
1 parent 40733b8 commit 2b01d45

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

integration_test/values_test.exs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@ defmodule Ecto.Integration.ValuesTest do
77
alias Ecto.Integration.Post
88
alias Ecto.Integration.TestRepo
99

10+
test "values works with datetime" do
11+
TestRepo.insert!(%Post{inserted_at: ~N[2000-01-01 00:01:00]})
12+
TestRepo.insert!(%Post{inserted_at: ~N[2000-01-01 00:02:00]})
13+
TestRepo.insert!(%Post{inserted_at: ~N[2000-01-01 00:03:00]})
14+
15+
params = [
16+
%{id: 1, date: ~N[2000-01-01 00:00:00]},
17+
%{id: 2, date: ~N[2000-01-01 00:01:00]},
18+
%{id: 3, date: ~N[2000-01-01 00:02:00]},
19+
%{id: 4, date: ~N[2000-01-01 00:03:00]}
20+
]
21+
22+
types = %{id: :integer, date: :naive_datetime}
23+
24+
results =
25+
from(params in values(params, types),
26+
left_join: p in Post,
27+
on: p.inserted_at <= params.date,
28+
group_by: params.id,
29+
select: %{id: params.id, count: count(p.id)},
30+
order_by: count(p.id)
31+
)
32+
|> TestRepo.all()
33+
34+
assert results == [
35+
%{count: 0, id: 1},
36+
%{count: 1, id: 2},
37+
%{count: 2, id: 3},
38+
%{count: 3, id: 4}
39+
]
40+
end
41+
1042
test "join to values works" do
1143
TestRepo.insert!(%Post{id: 1})
1244
TestRepo.insert!(%Comment{post_id: 1, text: "short"})

0 commit comments

Comments
 (0)