Skip to content

Commit b39bcba

Browse files
committed
Add test for Ecto.Enum usage
1 parent 80adc08 commit b39bcba

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

test/ecto/integration/crud_test.exs

+20
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ defmodule Ecto.Integration.CrudTest do
5151
assert found.tags == []
5252
end
5353

54+
test "inserts product with type set" do
55+
assert {:ok, account} = TestRepo.insert(%Account{name: "Something"})
56+
57+
assert {:ok, product} =
58+
TestRepo.insert(%Product{
59+
name: "Thing",
60+
type: :inventory,
61+
account_id: account.id,
62+
approved_at: nil
63+
})
64+
65+
assert found = TestRepo.get(Product, product.id)
66+
assert found.id == product.id
67+
assert found.approved_at == nil
68+
assert found.description == nil
69+
assert found.type == :inventory
70+
assert found.name == "Thing"
71+
assert found.tags == []
72+
end
73+
5474
test "insert_all" do
5575
TestRepo.insert!(%User{name: "John"}, [])
5676
timestamp = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)

test/support/migration.ex

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ defmodule EctoSQLite3.Integration.Migration do
3030
add(:external_id, :uuid)
3131
add(:bid, :binary_id)
3232
add(:tags, {:array, :string})
33+
add(:type, :integer)
3334
add(:approved_at, :naive_datetime)
3435
add(:ordered_at, :utc_datetime)
3536
add(:price, :decimal)

test/support/schemas/product.ex

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule EctoSQLite3.Schemas.Product do
1111
field(:name, :string)
1212
field(:description, :string)
1313
field(:external_id, Ecto.UUID)
14+
field(:type, Ecto.Enum, values: [inventory: 1, non_inventory: 2])
1415
field(:bid, :binary_id)
1516
field(:tags, {:array, :string}, default: [])
1617
field(:approved_at, :naive_datetime)
@@ -31,7 +32,8 @@ defmodule EctoSQLite3.Schemas.Product do
3132
:account_id,
3233
:approved_at,
3334
:ordered_at,
34-
:inserted_at
35+
:inserted_at,
36+
:type
3537
])
3638
|> validate_required([:name])
3739
|> maybe_generate_external_id()

0 commit comments

Comments
 (0)