From 05c9b1bd6c81a04f66251183f2d9d0abb14ed6a1 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 28 Apr 2021 09:45:36 -0700 Subject: [PATCH] Add test case for update_all with select error --- test/ecto/integration/crud_test.exs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/ecto/integration/crud_test.exs b/test/ecto/integration/crud_test.exs index 0b58a09..a1e7601 100644 --- a/test/ecto/integration/crud_test.exs +++ b/test/ecto/integration/crud_test.exs @@ -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])