Skip to content

Commit

Permalink
add some integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 28, 2024
1 parent 3d06fdb commit d61b5e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 3 additions & 1 deletion integration_test/myxql/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ excludes = [
# MySQL doesn't support indexed parameters
:placeholders,
# MySQL doesn't support specifying columns for ON DELETE SET NULL
:on_delete_nilify_column_list
:on_delete_nilify_column_list,
# MySQL doesnt' support anything except a single column in DISTINCT
:multicolumn_distinct
]

if Version.match?(version, ">= 8.0.0") do
Expand Down
30 changes: 30 additions & 0 deletions integration_test/sql/subquery.exs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,34 @@ defmodule Ecto.Integration.SubQueryTest do
select: fragment("? + ?", p.visits, ^1)
assert [12, 12] = TestRepo.all(query)
end

test "subqueries in order by" do
TestRepo.insert!(%Post{visits: 10, title: "hello"})
TestRepo.insert!(%Post{visits: 11, title: "hello"})

query = from p in Post, as: :p, order_by: [asc: exists(from p in Post, where: p.visits > parent_as(:p).visits)]

assert [%{visits: 11}, %{visits: 10}] = TestRepo.all(query)
end

@tag :multicolumn_distinct
test "subqueries in distinct" do
TestRepo.insert!(%Post{visits: 10, title: "hello1"})
TestRepo.insert!(%Post{visits: 10, title: "hello2"})
TestRepo.insert!(%Post{visits: 11, title: "hello"})

query = from p in Post, as: :p, distinct: exists(from p in Post, where: p.visits > parent_as(:p).visits), order_by: [asc: :title]

assert [%{title: "hello"}, %{title: "hello1"}] = TestRepo.all(query)
end

test "subqueries in group by" do
TestRepo.insert!(%Post{visits: 10, title: "hello1"})
TestRepo.insert!(%Post{visits: 10, title: "hello2"})
TestRepo.insert!(%Post{visits: 11, title: "hello"})

query = from p in Post, as: :p, select: sum(p.visits), distinct: exists(from p in Post, where: p.visits > parent_as(:p).visits)

assert [20, 11] = TestRepo.all(query)
end
end
4 changes: 3 additions & 1 deletion integration_test/tds/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ ExUnit.start(
# MSSQL can't reference aliased columns in ORDER BY expressions
:selected_as_with_order_by_expression,
# MSSQL doesn't support specifying columns for ON DELETE SET NULL
:on_delete_nilify_column_list
:on_delete_nilify_column_list,
# MySQL doesnt' support anything except a single column in DISTINCT
:multicolumn_distinct
]
)

Expand Down

0 comments on commit d61b5e5

Please sign in to comment.