Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/ecto/integration/crud_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ defmodule Ecto.Integration.CrudTest do
assert changed.name == "Bob"
end

test "update_all with select returns a row count of 0 when no records were updated" do
{:ok, _lj} = TestRepo.insert(%User{name: "Lebron James"}, [])

no_match_query =
from(
a in Account,
where: a.name == "Michael Jordan",
select: %{name: a.name}
)

assert {0, nil} = TestRepo.update_all(no_match_query, set: [name: "G.O.A.T"])

match_query =
from(
a in Account,
where: a.name == "Lebron James",
select: %{name: a.name}
)

assert {1, %{name: "Lebron James"}} =
TestRepo.update_all(match_query, set: [name: "G.O.A.T"])
end

test "update_all handles null<->nil conversion correctly" do
account = TestRepo.insert!(%Account{name: "hello"})
assert {1, nil} = TestRepo.update_all(Account, set: [name: nil])
Expand Down