Skip to content

Commit

Permalink
Add test for Ecto.Enum usage
Browse files Browse the repository at this point in the history
  • Loading branch information
warmwaffles committed Sep 14, 2024
1 parent 80adc08 commit b39bcba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/ecto/integration/crud_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ defmodule Ecto.Integration.CrudTest do
assert found.tags == []
end

test "inserts product with type set" do
assert {:ok, account} = TestRepo.insert(%Account{name: "Something"})

assert {:ok, product} =
TestRepo.insert(%Product{
name: "Thing",
type: :inventory,
account_id: account.id,
approved_at: nil
})

assert found = TestRepo.get(Product, product.id)
assert found.id == product.id
assert found.approved_at == nil
assert found.description == nil
assert found.type == :inventory
assert found.name == "Thing"
assert found.tags == []
end

test "insert_all" do
TestRepo.insert!(%User{name: "John"}, [])
timestamp = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
Expand Down
1 change: 1 addition & 0 deletions test/support/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defmodule EctoSQLite3.Integration.Migration do
add(:external_id, :uuid)
add(:bid, :binary_id)
add(:tags, {:array, :string})
add(:type, :integer)
add(:approved_at, :naive_datetime)
add(:ordered_at, :utc_datetime)
add(:price, :decimal)
Expand Down
4 changes: 3 additions & 1 deletion test/support/schemas/product.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule EctoSQLite3.Schemas.Product do
field(:name, :string)
field(:description, :string)
field(:external_id, Ecto.UUID)
field(:type, Ecto.Enum, values: [inventory: 1, non_inventory: 2])
field(:bid, :binary_id)
field(:tags, {:array, :string}, default: [])
field(:approved_at, :naive_datetime)
Expand All @@ -31,7 +32,8 @@ defmodule EctoSQLite3.Schemas.Product do
:account_id,
:approved_at,
:ordered_at,
:inserted_at
:inserted_at,
:type
])
|> validate_required([:name])
|> maybe_generate_external_id()
Expand Down

0 comments on commit b39bcba

Please sign in to comment.