From dde27f492f157dd10a5acf6105b9fddaedf0ecaf Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Fri, 18 Oct 2024 09:53:32 -0400 Subject: [PATCH] add tests --- test/ecto/adapters/myxql_test.exs | 6 ++++++ test/ecto/adapters/postgres_test.exs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/test/ecto/adapters/myxql_test.exs b/test/ecto/adapters/myxql_test.exs index 48466be3..edff7926 100644 --- a/test/ecto/adapters/myxql_test.exs +++ b/test/ecto/adapters/myxql_test.exs @@ -416,6 +416,12 @@ defmodule Ecto.Adapters.MyXQLTest do assert all(query) == ~s{SELECT coalesce(s0.`x`, 5) FROM `schema` AS s0} end + test "coalesce with subquery" do + squery = from s in Schema, select: s.x + query = Schema |> select([s], coalesce(subquery(squery), 5)) |> plan() + assert all(query) == ~s{SELECT coalesce((SELECT ss0.`x` AS `x` FROM `schema` AS ss0), 5) FROM `schema` AS s0} + end + test "where" do query = Schema |> where([r], r.x == 42) |> where([r], r.y != 43) |> select([r], r.x) |> plan() diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index 617f59ff..4bb0a2e4 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -584,6 +584,12 @@ defmodule Ecto.Adapters.PostgresTest do assert all(query) == ~s{SELECT coalesce(s0."x", 5) FROM "schema" AS s0} end + test "coalesce with subquery" do + squery = from s in Schema, select: s.x + query = Schema |> select([s], coalesce(subquery(squery), 5)) |> plan() + assert all(query) == ~s{SELECT coalesce((SELECT ss0."x" AS "x" FROM "schema" AS ss0), 5) FROM "schema" AS s0} + end + test "where" do query = Schema |> where([r], r.x == 42) |> where([r], r.y != 43) |> select([r], r.x) |> plan()