mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
test: add failing test to demonstrate error using ref (#282)
Filtering on ref in this manner worked up until Ash 3.0. Now, it gives the following error: 1) test filter with ref (AshPostgres.FilterTest) test/filter_test.exs:1076 ** (FunctionClauseError) no function clause matching in Ash.Filter.check_filterable/2 The following arguments were given to Ash.Filter.check_filterable/2: # 1 AshPostgres.Test.Organization # 2 :id Attempted function clauses (showing 2 out of 2): defp check_filterable(_resource, []) defp check_filterable(resource, [relationship | rest]) code: |> Ash.Query.filter(^ref(:id, [:posts, :comments]) == ^comment.id) stacktrace: (ash 3.0.1) lib/ash/filter/filter.ex:2944: Ash.Filter.check_filterable/2 (ash 3.0.1) lib/ash/filter/filter.ex:2933: anonymous fn/2 in Ash.Filter.validate_filterable_relationship_paths/2 (elixir 1.16.2) lib/enum.ex:4316: Enum.find_value_list/3 (ash 3.0.1) lib/ash/filter/filter.ex:2923: Ash.Filter.validate_refs/3 (ash 3.0.1) lib/ash/filter/filter.ex:3015: Ash.Filter.resolve_call/2 (ash 3.0.1) lib/ash/filter/filter.ex:2489: Ash.Filter.add_expression_part/3 (ash 3.0.1) lib/ash/filter/filter.ex:2427: anonymous fn/3 in Ash.Filter.parse_expression/2 (elixir 1.16.2) lib/enum.ex:4839: Enumerable.List.reduce/3 (elixir 1.16.2) lib/enum.ex:2582: Enum.reduce_while/3 (ash 3.0.1) lib/ash/filter/filter.ex:334: Ash.Filter.parse/3 (ash 3.0.1) lib/ash/query/query.ex:2574: Ash.Query.do_filter/3 test/filter_test.exs:1095: (test)
This commit is contained in:
parent
6d825792b3
commit
3f00dcbe8e
1 changed files with 28 additions and 2 deletions
|
@ -1,10 +1,11 @@
|
||||||
defmodule AshPostgres.FilterTest do
|
defmodule AshPostgres.FilterTest do
|
||||||
alias AshPostgres.Test.Organization
|
|
||||||
use AshPostgres.RepoCase, async: false
|
use AshPostgres.RepoCase, async: false
|
||||||
alias AshPostgres.Test.{Author, Comment, Post}
|
|
||||||
|
alias AshPostgres.Test.{Author, Comment, Post, Organization}
|
||||||
alias AshPostgres.Test.ComplexCalculations.{Channel, ChannelMember}
|
alias AshPostgres.Test.ComplexCalculations.{Channel, ChannelMember}
|
||||||
|
|
||||||
require Ash.Query
|
require Ash.Query
|
||||||
|
import Ash.Expr
|
||||||
|
|
||||||
describe "with no filter applied" do
|
describe "with no filter applied" do
|
||||||
test "with no data" do
|
test "with no data" do
|
||||||
|
@ -1070,4 +1071,29 @@ defmodule AshPostgres.FilterTest do
|
||||||
)
|
)
|
||||||
|> Ash.read!()
|
|> Ash.read!()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "filter with ref" do
|
||||||
|
organization =
|
||||||
|
Organization
|
||||||
|
|> Ash.Changeset.for_create(:create, %{name: "foo"})
|
||||||
|
|> Ash.create!()
|
||||||
|
|
||||||
|
post =
|
||||||
|
Post
|
||||||
|
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id})
|
||||||
|
|> Ash.create!()
|
||||||
|
|
||||||
|
comment =
|
||||||
|
Comment
|
||||||
|
|> Ash.Changeset.for_create(:create, %{title: "not match"})
|
||||||
|
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|
||||||
|
|> Ash.create!()
|
||||||
|
|
||||||
|
fetched_org =
|
||||||
|
Organization
|
||||||
|
|> Ash.Query.filter(^ref(:id, [:posts, :comments]) == ^comment.id)
|
||||||
|
|> Ash.read_one!()
|
||||||
|
|
||||||
|
assert fetched_org.id == organization.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue