Skip to content

Commit

Permalink
test: Add a failing test for sorting on relationship (#324)
Browse files Browse the repository at this point in the history
* add a failing test for sorting on relationship

* fix relationship pattern match

* fix title sort
  • Loading branch information
shamanime authored Jun 13, 2024
1 parent 9531ffa commit 27837d1
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion test/sort_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule AshPostgres.SortTest do
@moduledoc false
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Comment, Post, PostLink}
alias AshPostgres.Test.{Comment, Post, PostLink, PostView}

require Ash.Query
require Ash.Sort
Expand Down Expand Up @@ -224,4 +224,46 @@ defmodule AshPostgres.SortTest do
|> Ash.Query.load(linked_posts: posts_query)
|> Ash.read!()
end

test "sorting on relationship attributes work" do

Check failure on line 228 in test/sort_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test sorting on relationship attributes work (AshPostgres.SortTest)

Check failure on line 228 in test/sort_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test sorting on relationship attributes work (AshPostgres.SortTest)

Check failure on line 228 in test/sort_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test sorting on relationship attributes work (AshPostgres.SortTest)
post1 =
Post
|> Ash.Changeset.for_create(:create, %{title: "aaa", score: 0})
|> Ash.create!()

view1 =
PostView
|> Ash.Changeset.for_action(:create, %{browser: :firefox, post_id: post1.id})
|> Ash.create!()

post2 =
Post
|> Ash.Changeset.for_create(:create, %{title: "bbb", score: 0})
|> Ash.create!()

view2 =
PostView
|> Ash.Changeset.for_action(:create, %{browser: :chrome, post_id: post2.id})
|> Ash.create!()

assert [
%{title: "aaa", views: [%{browser: :firefox}]},
%{title: "bbb", views: [%{browser: :chrome}]}
] =
Ash.read!(
Post
|> Ash.Query.load(:views)
|> Ash.Query.sort(title: :asc)
)

assert [
%{title: "bbb", views: [%{browser: :chrome}]},
%{title: "aaa", views: [%{browser: :firefox}]}
] =
Ash.read!(
Post
|> Ash.Query.load(:views)
|> Ash.Query.sort({Ash.Sort.expr_sort(views.time, :datetime), :desc}, title: :asc)
)
end
end

0 comments on commit 27837d1

Please sign in to comment.