Skip to content

Commit

Permalink
Add test for updating with empty cast association (#3077)
Browse files Browse the repository at this point in the history
Show that update works the same way as insert
  • Loading branch information
nathanl authored and José Valim committed Jul 29, 2019
1 parent 698d3ac commit 2e700ef
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions integration_test/cases/assoc.exs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 654,23 @@ defmodule Ecto.Integration.AssocTest do
assert post.comments == []
end

test "updating changeset with empty cast associations" do
post = TestRepo.insert!(%Post{})
c1 = TestRepo.insert!(%Comment{post_id: post.id})
c2 = TestRepo.insert!(%Comment{post_id: post.id})

assert TestRepo.all(Comment) == [c1, c2]

post = TestRepo.get!(from(Post, preload: [:comments]), post.id)

post
|> Ecto.Changeset.change
|> Ecto.Changeset.put_assoc(:comments, [])
|> TestRepo.update!()

assert TestRepo.all(Comment) == []
end

## Dependent

test "has_many assoc on delete deletes all" do
Expand Down

0 comments on commit 2e700ef

Please sign in to comment.