Skip to content

Commit 707fe8e

Browse files
committed
Add test comparing against a Datetime
1 parent f6a91dc commit 707fe8e

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

test/ecto/integration/timestamps_test.exs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule Ecto.Integration.TimestampsTest do
22
use Ecto.Integration.Case
33

44
alias Ecto.Integration.TestRepo
5+
alias EctoSQLite3.Integration.Account
6+
alias EctoSQLite3.Integration.Product
57

68
import Ecto.Query
79

@@ -120,4 +122,47 @@ defmodule Ecto.Integration.TimestampsTest do
120122

121123
assert user
122124
end
125+
126+
test "datetime comparisons" do
127+
account =
128+
%Account{}
129+
|> Account.changeset(%{name: "Test"})
130+
|> TestRepo.insert!()
131+
132+
%Product{}
133+
|> Product.changeset(%{
134+
account_id: account.id,
135+
name: "Foo",
136+
approved_at: ~U[2023-01-01T01:00:00Z]
137+
})
138+
|> TestRepo.insert!()
139+
140+
%Product{}
141+
|> Product.changeset(%{
142+
account_id: account.id,
143+
name: "Bar",
144+
approved_at: ~U[2023-01-01T02:00:00Z]
145+
})
146+
|> TestRepo.insert!()
147+
148+
%Product{}
149+
|> Product.changeset(%{
150+
account_id: account.id,
151+
name: "Qux",
152+
approved_at: ~U[2023-01-01T03:00:00Z]
153+
})
154+
|> TestRepo.insert!()
155+
156+
since = ~U[2023-01-01T01:59:00Z]
157+
158+
assert [
159+
%{name: "Qux"},
160+
%{name: "Bar"}
161+
] =
162+
Product
163+
|> select([p], p)
164+
|> where([p], p.approved_at >= ^since)
165+
|> order_by([p], desc: p.approved_at)
166+
|> TestRepo.all()
167+
end
123168
end

test/support/schemas.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ defmodule EctoSQLite3.Integration.Product do
9797

9898
def changeset(struct, attrs) do
9999
struct
100-
|> cast(attrs, [:name, :description, :tags])
100+
|> cast(attrs, [:name, :description, :tags, :account_id, :approved_at])
101101
|> validate_required([:name])
102102
|> maybe_generate_external_id()
103103
end

0 commit comments

Comments
 (0)