Skip to content

Commit

Permalink
add resources_toys == pets_toys to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstanding committed Sep 30, 2023
1 parent 08751b8 commit f267862
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/ecto_diff_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,16 @@ defmodule EctoDiffTest do
|> Pet.new()
|> Repo.insert()

pet = Repo.preload(pet, [:resources, :toys])
pet = Repo.preload(pet, :toys)

id = pet.id
[%{id: resource_id}] = pet.resources
[ball_id, mouse_id] = Enum.map(pet.toys, & &1.id)

{:ok, diff} = EctoDiff.diff(nil, pet)
[%{changes: %{toys: resource_toys}}] = diff.changes.resources

assert resource_toys == diff.changes.toys

assert %EctoDiff{
effect: :added,
Expand Down Expand Up @@ -817,6 +820,9 @@ defmodule EctoDiffTest do
|> Repo.update()

{:ok, diff} = EctoDiff.diff(pet, updated_pet)
[%{changes: %{toys: resource_toys}}] = diff.changes.resources

assert resource_toys == diff.changes.toys

assert %EctoDiff{
effect: :changed,
Expand Down Expand Up @@ -866,6 +872,9 @@ defmodule EctoDiffTest do
{:ok, updated_pet} = pet |> Pet.update(%{resources: [%{id: resource_id, toys: []}]}) |> Repo.update()

{:ok, diff} = EctoDiff.diff(pet, updated_pet)
[%{changes: %{toys: resource_toys}}] = diff.changes.resources

assert resource_toys == diff.changes.toys

assert %EctoDiff{
effect: :changed,
Expand Down

0 comments on commit f267862

Please sign in to comment.