Skip to content

Commit d45d282

Browse files
committed
fix assertions for prefixed queries
1 parent 8bf5fd7 commit d45d282

File tree

5 files changed

+41
-46
lines changed

5 files changed

+41
-46
lines changed

test/ecto/adapters/sqlite3/connection/delete_all_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ defmodule Ecto.Adapters.SQLite3.Connection.DeleteAllTest do
6565
end
6666

6767
test "delete all with prefix" do
68-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
68+
query =
6969
Schema
7070
|> Ecto.Queryable.to_query()
7171
|> Map.put(:prefix, "prefix")
7272
|> plan()
73-
|> delete_all()
74-
end
7573

76-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
74+
assert ~s{DELETE FROM prefix.schema AS s0} == delete_all(query)
75+
76+
query =
7777
Schema
7878
|> from(prefix: "first")
7979
|> Map.put(:prefix, "prefix")
8080
|> plan()
81-
|> delete_all()
82-
end
81+
82+
assert ~s{DELETE FROM first.schema AS s0} == delete_all(query)
8383
end
8484
end

test/ecto/adapters/sqlite3/connection/insert_test.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ defmodule Ecto.Adapters.SQLite3.Connection.InsertTest do
2525
query = insert(nil, "schema", [], [[]], {:raise, [], []}, [])
2626
assert query == ~s{INSERT INTO "schema" DEFAULT VALUES}
2727

28-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
29-
insert("prefix", "schema", [], [[]], {:raise, [], []}, [])
30-
end
28+
query = insert("prefix", "schema", [], [[]], {:raise, [], []}, [])
29+
assert query == ~s{INSERT INTO prefix.schema DEFAULT VALUES}
3130

3231
query = insert(nil, "schema", [:x, :y], [[:x, :y]], {:raise, [], []}, [:id])
3332
assert query == ~s{INSERT INTO "schema" ("x","y") VALUES (?1,?2) RETURNING "id"}

test/ecto/adapters/sqlite3/connection/join_test.exs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,27 @@ defmodule Ecto.Adapters.SQLite3.Connection.JoinTest do
114114
~s{) AS s1 ON 1} == all(query)
115115
end
116116

117-
test "join with prefix is not supported" do
118-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
117+
test "join with prefix" do
118+
query =
119119
Schema
120120
|> join(:inner, [p], q in Schema2, on: p.x == q.z)
121121
|> select([], true)
122122
|> Map.put(:prefix, "prefix")
123123
|> plan()
124-
|> all()
125-
end
126124

127-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
125+
assert ~s{SELECT 1 FROM prefix.schema AS s0 INNER JOIN prefix.schema2 AS s1 ON s0."x" = s1."z"} ==
126+
all(query)
127+
128+
query =
128129
Schema
129130
|> from(prefix: "first")
130131
|> join(:inner, [p], q in Schema2, on: p.x == q.z, prefix: "second")
131132
|> select([], true)
132133
|> Map.put(:prefix, "prefix")
133134
|> plan()
134-
|> all()
135-
end
135+
136+
assert ~s{SELECT 1 FROM first.schema AS s0 INNER JOIN second.schema2 AS s1 ON s0."x" = s1."z"} ==
137+
all(query)
136138
end
137139

138140
test "join with values" do

test/ecto/adapters/sqlite3/connection/migration_test.exs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ defmodule Ecto.Adapters.SQLite3.Connection.MigrationTest do
4343
{:create, table(:posts, prefix: :foo),
4444
[{:add, :category_0, %Reference{table: :categories}, []}]}
4545

46-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
47-
execute_ddl(create)
48-
end
46+
assert execute_ddl(create) == [
47+
"""
48+
CREATE TABLE foo.posts ("category_0" INTEGER CONSTRAINT "posts_category_0_fkey" REFERENCES foo.categories("id"))
49+
"""
50+
|> remove_newlines
51+
]
4952
end
5053

5154
test "create table with references" do
@@ -295,10 +298,7 @@ defmodule Ecto.Adapters.SQLite3.Connection.MigrationTest do
295298

296299
test "drop table with prefix" do
297300
drop = {:drop, table(:posts, prefix: :foo)}
298-
299-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
300-
execute_ddl(drop)
301-
end
301+
assert execute_ddl(drop) == [~s|DROP TABLE foo.posts|]
302302
end
303303

304304
test "alter table" do
@@ -328,9 +328,9 @@ defmodule Ecto.Adapters.SQLite3.Connection.MigrationTest do
328328
{:alter, table(:posts, prefix: :foo),
329329
[{:add, :author_id, %Reference{table: :author}, []}]}
330330

331-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
332-
execute_ddl(alter)
333-
end
331+
assert execute_ddl(alter) == [
332+
~s|ALTER TABLE foo.posts ADD COLUMN "author_id" INTEGER CONSTRAINT "posts_author_id_fkey" REFERENCES foo.author("id")|
333+
]
334334
end
335335

336336
test "alter table with serial primary key" do
@@ -374,16 +374,16 @@ defmodule Ecto.Adapters.SQLite3.Connection.MigrationTest do
374374
test "create index with prefix" do
375375
create = {:create, index(:posts, [:category_id, :permalink], prefix: :foo)}
376376

377-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
378-
execute_ddl(create)
379-
end
377+
assert execute_ddl(create) == [
378+
~s|CREATE INDEX "posts_category_id_permalink_index" ON foo.posts ("category_id", "permalink")|
379+
]
380380

381381
create =
382382
{:create, index(:posts, ["lower(permalink)"], name: "posts$main", prefix: :foo)}
383383

384-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
385-
execute_ddl(create)
386-
end
384+
assert execute_ddl(create) == [
385+
~s|CREATE INDEX "posts$main" ON foo.posts (lower(permalink))|
386+
]
387387
end
388388

389389
test "create index with comment" do
@@ -470,10 +470,7 @@ defmodule Ecto.Adapters.SQLite3.Connection.MigrationTest do
470470

471471
test "drop index with prefix" do
472472
drop = {:drop, index(:posts, [:id], name: "posts$main", prefix: :foo), :restrict}
473-
474-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
475-
execute_ddl(drop)
476-
end
473+
assert execute_ddl(drop) == [~s|DROP INDEX foo.posts$main|]
477474
end
478475

479476
test "drop index concurrently not supported" do
@@ -516,10 +513,7 @@ defmodule Ecto.Adapters.SQLite3.Connection.MigrationTest do
516513

517514
test "rename table with prefix" do
518515
rename = {:rename, table(:posts, prefix: :foo), table(:new_posts, prefix: :foo)}
519-
520-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
521-
execute_ddl(rename)
522-
end
516+
assert execute_ddl(rename) == [~s|ALTER TABLE foo.posts RENAME TO "new_posts"|]
523517
end
524518

525519
test "rename column" do
@@ -533,9 +527,9 @@ defmodule Ecto.Adapters.SQLite3.Connection.MigrationTest do
533527
test "rename column in prefixed table" do
534528
rename = {:rename, table(:posts, prefix: :foo), :given_name, :first_name}
535529

536-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
537-
execute_ddl(rename)
538-
end
530+
assert execute_ddl(rename) == [
531+
~s|ALTER TABLE foo.posts RENAME COLUMN "given_name" TO "first_name"|
532+
]
539533
end
540534

541535
test "autoincrement support" do

test/ecto/adapters/sqlite3/connection/update_all_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ defmodule Ecto.Adapters.SQLite3.Connection.UpdateAllTest do
123123
end
124124

125125
test "update all with prefix" do
126-
assert_raise ArgumentError, "SQLite3 does not support table prefixes", fn ->
126+
query =
127127
from(m in Schema, update: [set: [x: 0]])
128128
|> Map.put(:prefix, "prefix")
129129
|> plan(:update_all)
130-
|> update_all()
131-
end
130+
131+
assert ~s{UPDATE prefix.schema AS s0 SET "x" = 0} == update_all(query)
132132
end
133133

134134
test "update all with left join" do

0 commit comments

Comments
 (0)