diff --git a/test/ecto/integration/timestamps_test.exs b/test/ecto/integration/timestamps_test.exs index fca29b7..20a23fa 100644 --- a/test/ecto/integration/timestamps_test.exs +++ b/test/ecto/integration/timestamps_test.exs @@ -126,10 +126,7 @@ defmodule Ecto.Integration.TimestampsTest do test "insert and fetch nil values" do now = DateTime.utc_now() - {:ok, product} = - %Product{} - |> Product.changeset(%{name: "Nil Date Test", approved_at: now, ordered_at: now}) - |> TestRepo.insert() + product = insert_product(%{name: "Nil Date Test", approved_at: now, ordered_at: now}) product = TestRepo.get(Product, product.id) assert product.name == "Nil Date Test" @@ -146,34 +143,25 @@ defmodule Ecto.Integration.TimestampsTest do end test "datetime comparisons" do - account = - %Account{} - |> Account.changeset(%{name: "Test"}) - |> TestRepo.insert!() + account = insert_account(%{name: "Test"}) - %Product{} - |> Product.changeset(%{ + insert_product(%{ account_id: account.id, name: "Foo", approved_at: ~U[2023-01-01T01:00:00Z] }) - |> TestRepo.insert!() - %Product{} - |> Product.changeset(%{ + insert_product(%{ account_id: account.id, name: "Bar", approved_at: ~U[2023-01-01T02:00:00Z] }) - |> TestRepo.insert!() - %Product{} - |> Product.changeset(%{ + insert_product(%{ account_id: account.id, name: "Qux", approved_at: ~U[2023-01-01T03:00:00Z] }) - |> TestRepo.insert!() since = ~U[2023-01-01T01:59:00Z] @@ -187,4 +175,16 @@ defmodule Ecto.Integration.TimestampsTest do |> order_by([p], desc: p.approved_at) |> TestRepo.all() end + + defp insert_account(attrs) do + %Account{} + |> Account.changeset(attrs) + |> TestRepo.insert!() + end + + defp insert_product(attrs) do + %Product{} + |> Product.changeset(attrs) + |> TestRepo.insert!() + end end diff --git a/test/support/schemas/product.ex b/test/support/schemas/product.ex index 654e023..c0b3803 100644 --- a/test/support/schemas/product.ex +++ b/test/support/schemas/product.ex @@ -24,7 +24,15 @@ defmodule EctoSQLite3.Schemas.Product do def changeset(struct, attrs) do struct - |> cast(attrs, [:name, :description, :tags, :account_id, :approved_at, :ordered_at]) + |> cast(attrs, [ + :name, + :description, + :tags, + :account_id, + :approved_at, + :ordered_at, + :inserted_at + ]) |> validate_required([:name]) |> maybe_generate_external_id() end