Skip to content

Commit

Permalink
test: update tests & fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Feb 6, 2025
1 parent 1f35fff commit 219771a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/ash/filter/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ defmodule Ash.Filter do
"""
def get_filter(resource, id) do
primary_key = Ash.Resource.Info.primary_key(resource)
keyval? = Keyword.keyword?(id) || is_map(id)
keyval? = Keyword.keyword?(id) || (is_map(id) and not is_struct(id))

case {primary_key, id} do
{[field], [{field, value}]} ->
Expand Down
1 change: 1 addition & 0 deletions lib/ash/notifier/pub_sub/verifiers/verify_action_names.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Ash.Notifier.PubSub.Verifiers.VerifyActionNames do
@moduledoc "Verifies action names in configured publications"
use Spark.Dsl.Verifier

def verify(dsl) do
Expand Down
25 changes: 14 additions & 11 deletions test/actions/has_many_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ defmodule Ash.Test.Actions.HasManyTest do
attributes do
uuid_primary_key :id

attribute :last_post_id, :uuid, public?: true
attribute :last_post_id, :ci_string, public?: true
attribute :user_id, :uuid, public?: true
end

Expand All @@ -144,7 +144,6 @@ defmodule Ash.Test.Actions.HasManyTest do
end
end


defmodule User do
@moduledoc false
use Ash.Resource,
Expand Down Expand Up @@ -179,12 +178,7 @@ defmodule Ash.Test.Actions.HasManyTest do
destination_attribute :tenant_id
public?(true)

# This is eventually what I want to do, but it results in no matches
# filter expr(inserted_at > parent(post_view.last_post.inserted_at))

# After some experimentation, I found that this works
# filter expr(id != parent(post_view.last_post_id))
# But this doesn't
# This is evenn't
filter expr(id != parent(post_view.last_post.id))
end
end
Expand Down Expand Up @@ -295,19 +289,28 @@ defmodule Ash.Test.Actions.HasManyTest do
_first_read_post =
Post
|> Ash.Changeset.for_create(:create, %{title: "Read Post 1", tenant_id: tenant_id})
|> Ash.Changeset.force_change_attribute(:inserted_at, DateTime.utc_now() |> DateTime.add(-10, :second))
|> Ash.Changeset.force_change_attribute(
:inserted_at,
DateTime.utc_now() |> DateTime.add(-10, :second)
)
|> Ash.create!()

last_read_post =
Post
|> Ash.Changeset.for_create(:create, %{title: "Read Post 2", tenant_id: tenant_id})
|> Ash.Changeset.force_change_attribute(:inserted_at, DateTime.utc_now() |> DateTime.add(-9, :second))
|> Ash.Changeset.force_change_attribute(
:inserted_at,
DateTime.utc_now() |> DateTime.add(-9, :second)
)
|> Ash.create!()

_unread_post =
Post
|> Ash.Changeset.for_create(:create, %{title: "Unread Post", tenant_id: tenant_id})
|> Ash.Changeset.force_change_attribute(:inserted_at, DateTime.utc_now() |> DateTime.add(-8, :second))
|> Ash.Changeset.force_change_attribute(
:inserted_at,
DateTime.utc_now() |> DateTime.add(-8, :second)
)
|> Ash.create!()

# Track which post was read last
Expand Down

0 comments on commit 219771a

Please sign in to comment.