Skip to content

Commit

Permalink
better test tags, and remove tests that don't produce valid SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 28, 2024
1 parent 4b51f0a commit 0550a3b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
3 changes: 3 additions & 0 deletions integration_test/sql/subquery.exs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ defmodule Ecto.Integration.SubQueryTest do
assert [12, 12] = TestRepo.all(query)
end

@tag :subquery_in_order_by
test "subqueries in order by" do
TestRepo.insert!(%Post{visits: 10, title: "hello"})
TestRepo.insert!(%Post{visits: 11, title: "hello"})
Expand All @@ -123,6 +124,7 @@ defmodule Ecto.Integration.SubQueryTest do
end

@tag :multicolumn_distinct
@tag :subquery_in_distinct
test "subqueries in distinct" do
TestRepo.insert!(%Post{visits: 10, title: "hello1"})
TestRepo.insert!(%Post{visits: 10, title: "hello2"})
Expand All @@ -133,6 +135,7 @@ defmodule Ecto.Integration.SubQueryTest do
assert [%{title: "hello"}, %{title: "hello1"}] = TestRepo.all(query)
end

@tag :subquery_in_group_by
test "subqueries in group by" do
TestRepo.insert!(%Post{visits: 10, title: "hello1"})
TestRepo.insert!(%Post{visits: 10, title: "hello2"})
Expand Down
8 changes: 6 additions & 2 deletions integration_test/tds/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ ExUnit.start(
:selected_as_with_order_by_expression,
# MSSQL doesn't support specifying columns for ON DELETE SET NULL
:on_delete_nilify_column_list,
# MySQL doesnt' support anything except a single column in DISTINCT
:multicolumn_distinct
# MSSQL doesnt' support anything except a single column in DISTINCT
:multicolumn_distinct,
# MSSQL doesnt' support subqueries in group by or in distinct
:subquery_in_group_by,
:subquery_in_distinct,
:subquery_in_order_by
]
)

Expand Down
31 changes: 0 additions & 31 deletions test/ecto/adapters/tds_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,6 @@ defmodule Ecto.Adapters.TdsTest do
query = Schema |> order_by([r], []) |> select([r], r.x) |> plan()
assert all(query) == ~s{SELECT s0.[x] FROM [schema] AS s0}

query =
from(row in Schema, as: :r)
|> order_by(
asc:
exists(
from other_schema in "schema",
where: other_schema.x == parent_as(:r).x,
select: [other_schema.x]
)
)
|> select([r], r.x)
|> plan()

assert all(query) ==
~s{SELECT s0.[x] FROM [schema] AS s0 ORDER BY exists(SELECT ss0.[x] AS [result] FROM [schema] AS ss0 WHERE (ss0.[x] = s0.[x]))}

for dir <- [:asc_nulls_first, :asc_nulls_last, :desc_nulls_first, :desc_nulls_last] do
assert_raise Ecto.QueryError, ~r"#{dir} is not supported in ORDER BY in MSSQL", fn ->
Schema |> order_by([r], [{^dir, r.x}]) |> select([r], r.x) |> plan() |> all()
Expand Down Expand Up @@ -887,21 +871,6 @@ defmodule Ecto.Adapters.TdsTest do

query = Schema |> group_by([r], []) |> select([r], r.x) |> plan()
assert all(query) == ~s{SELECT s0.[x] FROM [schema] AS s0}

query =
from(row in Schema, as: :r, select: row.x)
|> group_by(
[r],
exists(
from other_schema in "schema",
where: other_schema.x == parent_as(:r).x,
select: [other_schema.x]
)
)
|> plan()

assert all(query) ==
~s{SELECT s0.[x] FROM [schema] AS s0 GROUP BY exists(SELECT ss0.[x] AS [result] FROM [schema] AS ss0 WHERE (ss0.[x] = s0.[x]))}
end

test "interpolated values" do
Expand Down

0 comments on commit 0550a3b

Please sign in to comment.