Skip to content

Commit d61b5e5

Browse files
committed
add some integration tests
1 parent 3d06fdb commit d61b5e5

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

integration_test/myxql/test_helper.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ excludes = [
113113
# MySQL doesn't support indexed parameters
114114
:placeholders,
115115
# MySQL doesn't support specifying columns for ON DELETE SET NULL
116-
:on_delete_nilify_column_list
116+
:on_delete_nilify_column_list,
117+
# MySQL doesnt' support anything except a single column in DISTINCT
118+
:multicolumn_distinct
117119
]
118120

119121
if Version.match?(version, ">= 8.0.0") do

integration_test/sql/subquery.exs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,34 @@ defmodule Ecto.Integration.SubQueryTest do
112112
select: fragment("? + ?", p.visits, ^1)
113113
assert [12, 12] = TestRepo.all(query)
114114
end
115+
116+
test "subqueries in order by" do
117+
TestRepo.insert!(%Post{visits: 10, title: "hello"})
118+
TestRepo.insert!(%Post{visits: 11, title: "hello"})
119+
120+
query = from p in Post, as: :p, order_by: [asc: exists(from p in Post, where: p.visits > parent_as(:p).visits)]
121+
122+
assert [%{visits: 11}, %{visits: 10}] = TestRepo.all(query)
123+
end
124+
125+
@tag :multicolumn_distinct
126+
test "subqueries in distinct" do
127+
TestRepo.insert!(%Post{visits: 10, title: "hello1"})
128+
TestRepo.insert!(%Post{visits: 10, title: "hello2"})
129+
TestRepo.insert!(%Post{visits: 11, title: "hello"})
130+
131+
query = from p in Post, as: :p, distinct: exists(from p in Post, where: p.visits > parent_as(:p).visits), order_by: [asc: :title]
132+
133+
assert [%{title: "hello"}, %{title: "hello1"}] = TestRepo.all(query)
134+
end
135+
136+
test "subqueries in group by" do
137+
TestRepo.insert!(%Post{visits: 10, title: "hello1"})
138+
TestRepo.insert!(%Post{visits: 10, title: "hello2"})
139+
TestRepo.insert!(%Post{visits: 11, title: "hello"})
140+
141+
query = from p in Post, as: :p, select: sum(p.visits), distinct: exists(from p in Post, where: p.visits > parent_as(:p).visits)
142+
143+
assert [20, 11] = TestRepo.all(query)
144+
end
115145
end

integration_test/tds/test_helper.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ ExUnit.start(
5757
# MSSQL can't reference aliased columns in ORDER BY expressions
5858
:selected_as_with_order_by_expression,
5959
# MSSQL doesn't support specifying columns for ON DELETE SET NULL
60-
:on_delete_nilify_column_list
60+
:on_delete_nilify_column_list,
61+
# MySQL doesnt' support anything except a single column in DISTINCT
62+
:multicolumn_distinct
6163
]
6264
)
6365

0 commit comments

Comments
 (0)