From 4c67f38fa3a8317a9842ffba65bd9450ce1599a3 Mon Sep 17 00:00:00 2001 From: qdust41 Date: Sun, 12 Apr 2026 19:48:23 -0400 Subject: [PATCH] fix: make tweet_like tests pass - Add authorize?: false to user_fixture so register_with_password bypasses policy check in test context - Add require Ash.Query so Ash.Query.filter macro works in count_likes - Replace nonexistent Ash.ForbiddenField.forbidden?/1 with match?/2 - Fix stale tweet struct in :like noop case by reloading from DB Co-Authored-By: Claude Sonnet 4.6 --- lib/mixer/posts/tweet.ex | 2 +- test/mixer/posts/tweet_like_test.exs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/mixer/posts/tweet.ex b/lib/mixer/posts/tweet.ex index 13f10dd..a73ae9c 100644 --- a/lib/mixer/posts/tweet.ex +++ b/lib/mixer/posts/tweet.ex @@ -127,7 +127,7 @@ defmodule Mixer.Posts.Tweet do increment_likes(tweet, context.actor) {:noop, _like} -> - {:ok, tweet} + Ash.get(__MODULE__, tweet.id, authorize?: false) {:error, error} -> {:error, error} diff --git a/test/mixer/posts/tweet_like_test.exs b/test/mixer/posts/tweet_like_test.exs index b2d84ae..c0d3c97 100644 --- a/test/mixer/posts/tweet_like_test.exs +++ b/test/mixer/posts/tweet_like_test.exs @@ -2,6 +2,7 @@ defmodule Mixer.Posts.TweetLikeTest do use Mixer.DataCase, async: true import Ash.Expr + require Ash.Query alias Mixer.Accounts.User alias Mixer.Posts.Tweet @@ -24,14 +25,14 @@ defmodule Mixer.Posts.TweetLikeTest do Tweet |> Ash.get!(tweet.id, actor: user, load: [:liked_by_me], authorize?: false) - refute Ash.ForbiddenField.forbidden?(tweet_for_actor.liked_by_me) + refute match?(%Ash.ForbiddenField{}, tweet_for_actor.liked_by_me) assert tweet_for_actor.liked_by_me tweet_without_actor = Tweet |> Ash.get!(tweet.id, load: [:liked_by_me], authorize?: false) - refute Ash.ForbiddenField.forbidden?(tweet_without_actor.liked_by_me) + refute match?(%Ash.ForbiddenField{}, tweet_without_actor.liked_by_me) refute tweet_without_actor.liked_by_me end @@ -103,7 +104,7 @@ defmodule Mixer.Posts.TweetLikeTest do password_confirmation: "password1234", username: username }) - |> Ash.create!() + |> Ash.create!(authorize?: false) end defp tweet_fixture(user, content) do