Skip to content

Commit 99918ed

Browse files
author
Alex
committed
Add test case for update_all with select error
1 parent 5fc162d commit 99918ed

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/ecto/integration/crud_test.exs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,29 @@ defmodule Ecto.Integration.CrudTest do
104104
assert changed.name == "Bob"
105105
end
106106

107+
test "update_all with select returns a row count of 0 when no records were updated" do
108+
{:ok, _lj} = TestRepo.insert(%User{name: "Lebron James"}, [])
109+
110+
no_match_query =
111+
from(
112+
a in Account,
113+
where: a.name == "Michael Jordan",
114+
select: %{name: a.name}
115+
)
116+
117+
assert {0, nil} = TestRepo.update_all(no_match_query, set: [name: "G.O.A.T"])
118+
119+
match_query =
120+
from(
121+
a in Account,
122+
where: a.name == "Lebron James",
123+
select: %{name: a.name}
124+
)
125+
126+
assert {1, %{name: "Lebron James"}} =
127+
TestRepo.update_all(no_match_query, set: [name: "G.O.A.T"])
128+
end
129+
107130
test "update_all handles null<->nil conversion correctly" do
108131
account = TestRepo.insert!(%Account{name: "hello"})
109132
assert {1, nil} = TestRepo.update_all(Account, set: [name: nil])

0 commit comments

Comments
 (0)