Skip to content

Commit 165cfdd

Browse files
Tag insert_select test (#3942)
1 parent 479484c commit 165cfdd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

integration_test/cases/repo.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,23 @@ defmodule Ecto.Integration.RepoTest do
18401840

18411841
@tag :with_conflict_target
18421842
test "on conflict query and conflict target" do
1843+
on_conflict = from p in Post, where: p.id > ^0, update: [set: [title: "second"]]
1844+
post = [title: "first", uuid: Ecto.UUID.generate()]
1845+
assert TestRepo.insert_all(Post, [post], on_conflict: on_conflict, conflict_target: [:uuid]) ==
1846+
{1, nil}
1847+
1848+
# Error on non-conflict target
1849+
assert catch_error(TestRepo.insert_all(Post, [post], on_conflict: on_conflict, conflict_target: [:id]))
1850+
1851+
# Error on conflict target
1852+
assert TestRepo.insert_all(Post, [post], on_conflict: on_conflict, conflict_target: [:uuid]) ==
1853+
{1, nil}
1854+
assert TestRepo.all(from p in Post, select: p.title) == ["second"]
1855+
end
1856+
1857+
@tag :insert_select
1858+
@tag :with_conflict_target
1859+
test "on conflict query and insert select and conflict target" do
18431860
on_conflict = from p in Post, where: p.id > ^0, update: [set: [title: "second"]]
18441861
visits_value = from p in Post, where: p.public == ^true and p.id > ^0, select: p.visits, limit: 1
18451862
post = [title: "first", uuid: Ecto.UUID.generate(), visits: visits_value]

0 commit comments

Comments
 (0)