From 34a8b5cc5bd0810ab841d23277193dbab0e7c393 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Thu, 22 Jul 2021 11:03:40 -0400 Subject: [PATCH] improvement: add sort + select test --- test/sort_test.exs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/sort_test.exs b/test/sort_test.exs index 50c752a..d715968 100644 --- a/test/sort_test.exs +++ b/test/sort_test.exs @@ -63,7 +63,11 @@ defmodule AshPostgres.SortTest do Post |> Ash.Query.load([ :count_of_comments, - comments: Comment |> Ash.Query.sort([:title, :likes]) |> Ash.Query.limit(1) + comments: + Comment + |> Ash.Query.sort([:title, :likes]) + |> Ash.Query.select([:title, :likes]) + |> Ash.Query.limit(1) ]) |> Ash.Query.sort([:title, :score]) |> Api.read!() @@ -74,4 +78,29 @@ defmodule AshPostgres.SortTest do %{title: "bbb"} ] = posts end + + test "multicolumn sort works with a select statement" do + Post + |> Ash.Changeset.new(%{title: "aaa", score: 0}) + |> Api.create!() + + Post + |> Ash.Changeset.new(%{title: "aaa", score: 1}) + |> Api.create!() + + Post + |> Ash.Changeset.new(%{title: "bbb", score: 0}) + |> Api.create!() + + assert [ + %{title: "aaa", score: 0}, + %{title: "aaa", score: 1}, + %{title: "bbb"} + ] = + Api.read!( + Post + |> Ash.Query.sort(title: :asc, score: :asc) + |> Ash.Query.select([:title, :score]) + ) + end end