improvement: add sort + select test

This commit is contained in:
Zach Daniel 2021-07-22 11:03:40 -04:00
parent 9e4fce974f
commit 34a8b5cc5b

View file

@ -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