Skip to content

Commit 44c0192

Browse files
committed
Add unit tests to placeholders
1 parent c38acca commit 44c0192

4 files changed

Lines changed: 26 additions & 18 deletions

File tree

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"deep_merge": {:hex, :deep_merge, "0.2.0", "c1050fa2edf4848b9f556fba1b75afc66608a4219659e3311d9c9427b5b680b3", [:mix], [], "hexpm", "e3bf435a54ed27b0ba3a01eb117ae017988804e136edcbe8a6a14c310daa966e"},
88
"earmark": {:hex, :earmark, "1.4.4", "4821b8d05cda507189d51f2caeef370cf1e18ca5d7dfb7d31e9cafe6688106a4", [:mix], [], "hexpm", "1f93aba7340574847c0f609da787f0d79efcab51b044bb6e242cae5aca9d264d"},
99
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
10-
"ecto": {:git, "https://github.com/un3qual/ecto.git", "b142dba16b6675e2870eeb96ab7ce4aa8635e924", [branch: "add_placeholders_initial"]},
10+
"ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "feea89d22a93a7b73a7dc00cd2d9a59874892042", []},
1111
"ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
1212
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
1313
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},

test/ecto/adapters/postgres_test.exs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,18 @@ defmodule Ecto.Adapters.PostgresTest do
5555
defp delete_all(query), do: query |> SQL.delete_all |> IO.iodata_to_binary()
5656
defp execute_ddl(query), do: query |> SQL.execute_ddl |> Enum.map(&IO.iodata_to_binary/1)
5757

58-
defp insert(prefx, table, header, rows, on_conflict, returning) do
59-
IO.iodata_to_binary SQL.insert(prefx, table, header, rows, on_conflict, returning, [])
58+
defp insert(prefx, table, header, rows, on_conflict, returning, placeholders \\ []) do
59+
IO.iodata_to_binary(
60+
SQL.insert(prefx, table, header, rows, on_conflict, returning, placeholders)
61+
)
6062
end
6163

6264
defp update(prefx, table, fields, filter, returning) do
63-
IO.iodata_to_binary SQL.update(prefx, table, fields, filter, returning)
65+
IO.iodata_to_binary(SQL.update(prefx, table, fields, filter, returning))
6466
end
6567

6668
defp delete(prefx, table, filter, returning) do
67-
IO.iodata_to_binary SQL.delete(prefx, table, filter, returning)
69+
IO.iodata_to_binary(SQL.delete(prefx, table, filter, returning))
6870
end
6971

7072
test "from" do
@@ -1095,6 +1097,9 @@ defmodule Ecto.Adapters.PostgresTest do
10951097
query = insert(nil, "schema", [:x, :y], [[:x, :y], [nil, :z]], {:raise, [], []}, [:id])
10961098
assert query == ~s{INSERT INTO "schema" ("x","y") VALUES ($1,$2),(DEFAULT,$3) RETURNING "id"}
10971099

1100+
query = insert(nil, "schema", [:x, :y], [[:x, :y], [nil, :z]], {:raise, [], []}, [:id], [1, 2])
1101+
assert query == ~s{INSERT INTO "schema" ("x","y") VALUES ($3,$4),(DEFAULT,$5) RETURNING "id"}
1102+
10981103
query = insert(nil, "schema", [], [[]], {:raise, [], []}, [:id])
10991104
assert query == ~s{INSERT INTO "schema" VALUES (DEFAULT) RETURNING "id"}
11001105

test/ecto/adapters/tds_test.exs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ defmodule Ecto.Adapters.TdsTest do
5959
defp delete_all(query), do: query |> SQL.delete_all() |> IO.iodata_to_binary()
6060
defp execute_ddl(query), do: query |> SQL.execute_ddl() |> Enum.map(&IO.iodata_to_binary/1)
6161

62-
defp insert(prefx, table, header, rows, on_conflict, returning) do
63-
IO.iodata_to_binary(SQL.insert(prefx, table, header, rows, on_conflict, returning, []))
62+
defp insert(prefx, table, header, rows, on_conflict, returning, placeholders \\ []) do
63+
IO.iodata_to_binary(
64+
SQL.insert(prefx, table, header, rows, on_conflict, returning, placeholders)
65+
)
6466
end
6567

6668
defp update(prefx, table, fields, filter, returning) do
@@ -1034,20 +1036,21 @@ defmodule Ecto.Adapters.TdsTest do
10341036
# Schema based
10351037

10361038
test "insert" do
1037-
# prefx, table, header, rows, on_conflict, returning
1038-
query = insert(nil, "schema", [:x, :y], [[:x, :y]], {:raise, [], []}, [])
1039-
assert query == ~s{INSERT INTO [schema] ([x],[y]) VALUES (@1, @2)}
1039+
# prefx, table, header, rows, on_conflict, returning, placeholders
1040+
assert insert(nil, "schema", [:x, :y], [[:x, :y]], {:raise, [], []}, []) ==
1041+
~s{INSERT INTO [schema] ([x],[y]) VALUES (@1, @2)}
10401042

1041-
query = insert(nil, "schema", [:x, :y], [[:x, :y], [nil, :y]], {:raise, [], []}, [:id])
1042-
1043-
assert query ==
1043+
assert insert(nil, "schema", [:x, :y], [[:x, :y], [nil, :y]], {:raise, [], []}, [:id]) ==
10441044
~s{INSERT INTO [schema] ([x],[y]) OUTPUT INSERTED.[id] VALUES (@1, @2),(DEFAULT, @3)}
10451045

1046-
query = insert(nil, "schema", [], [[]], {:raise, [], []}, [:id])
1047-
assert query == ~s{INSERT INTO [schema] OUTPUT INSERTED.[id] DEFAULT VALUES}
1046+
assert insert(nil, "schema", [:x, :y], [[:x, :y], [nil, :y]], {:raise, [], []}, [:id], [1, 2]) ==
1047+
~s{INSERT INTO [schema] ([x],[y]) OUTPUT INSERTED.[id] VALUES (@3, @4),(DEFAULT, @5)}
1048+
1049+
assert insert(nil, "schema", [], [[]], {:raise, [], []}, [:id]) ==
1050+
~s{INSERT INTO [schema] OUTPUT INSERTED.[id] DEFAULT VALUES}
10481051

1049-
query = insert("prefix", "schema", [], [[]], {:raise, [], []}, [:id])
1050-
assert query == ~s{INSERT INTO [prefix].[schema] OUTPUT INSERTED.[id] DEFAULT VALUES}
1052+
assert insert("prefix", "schema", [], [[]], {:raise, [], []}, [:id]) ==
1053+
~s{INSERT INTO [prefix].[schema] OUTPUT INSERTED.[id] DEFAULT VALUES}
10511054
end
10521055

10531056
test "insert with query" do

test/test_repo.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule EctoSQL.TestAdapter do
3535

3636
def checkout(_, _, _), do: raise "not implemented"
3737
def delete(_, _, _, _), do: raise "not implemented"
38-
def insert_all(_, _, _, _, _, _, _), do: raise "not implemented"
38+
def insert_all(_, _, _, _, _, _, _, _), do: raise "not implemented"
3939
def rollback(_, _), do: raise "not implemented"
4040
def stream(_, _, _, _, _), do: raise "not implemented"
4141
def update(_, _, _, _, _, _), do: raise "not implemented"

0 commit comments

Comments
 (0)