-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathdelete_all_test.exs
More file actions
84 lines (69 loc) · 1.89 KB
/
delete_all_test.exs
File metadata and controls
84 lines (69 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
defmodule Ecto.Adapters.SQLite3.Connection.DeleteAllTest do
use ExUnit.Case, async: true
import Ecto.Query
import Ecto.Adapters.SQLite3.TestHelpers
alias Ecto.Queryable
alias EctoSQLite3.Schemas.Schema
alias EctoSQLite3.Schemas.Schema2
test "delete all with only the schema" do
query =
Schema
|> Queryable.to_query()
|> plan()
assert ~s{DELETE FROM "schema" AS s0} == delete_all(query)
end
test "delete all with filters" do
query =
from(e in Schema)
|> where([e], e.x == 123)
|> plan()
assert ~s{DELETE FROM "schema" AS s0 WHERE (s0."x" = 123)} == delete_all(query)
end
test "join in a delete is not supported" do
assert_raise ArgumentError, fn ->
Schema
|> join(:inner, [p], q in Schema2, on: p.x == q.z)
|> plan()
|> delete_all()
end
assert_raise ArgumentError, fn ->
from(e in Schema)
|> where([e], e.x == 123)
|> join(:inner, [e], q in Schema2, on: e.x == q.z)
|> plan()
|> delete_all()
end
assert_raise ArgumentError, fn ->
from(e in Schema,
where: e.x == 123,
join: assoc(e, :comments),
join: assoc(e, :permalink)
)
|> plan()
|> delete_all()
end
end
test "delete all with returning" do
query =
Schema
|> Queryable.to_query()
|> select([m], m)
|> plan()
assert ~s{DELETE FROM "schema" AS s0 RETURNING "id", "x", "y", "z", "w", "meta"} ==
delete_all(query)
end
test "delete all with prefix" do
query =
Schema
|> Ecto.Queryable.to_query()
|> Map.put(:prefix, "prefix")
|> plan()
assert ~s{DELETE FROM prefix.schema AS s0} == delete_all(query)
query =
Schema
|> from(prefix: "first")
|> Map.put(:prefix, "prefix")
|> plan()
assert ~s{DELETE FROM first.schema AS s0} == delete_all(query)
end
end