From: AkiraFukushima
Date: Fri, 19 Oct 2018 12:24:15 +0000 (+0900)
Subject: Add a test for List.get_lists_account_belongs
X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=a249cbf18724084d6bcb7fee0ba577241c1f6adb;p=akkoma
Add a test for List.get_lists_account_belongs
---
diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex
index a99e3245b..891c73f5a 100644
--- a/lib/pleroma/list.ex
+++ b/lib/pleroma/list.ex
@@ -72,11 +72,19 @@ defmodule Pleroma.List do
# Get lists to which the account belongs.
def get_lists_account_belongs(%User{} = owner, account_id) do
user = Repo.get(User, account_id)
+
query =
from(
l in Pleroma.List,
- where: l.user_id == ^owner.id and fragment("? = ANY(?)", ^user.follower_address, l.following)
+ where:
+ l.user_id == ^owner.id and
+ fragment(
+ "? = ANY(?)",
+ ^user.follower_address,
+ l.following
+ )
)
+
Repo.all(query)
end
diff --git a/test/list_test.exs b/test/list_test.exs
index da3b88024..3c07e56b2 100644
--- a/test/list_test.exs
+++ b/test/list_test.exs
@@ -90,4 +90,24 @@ defmodule Pleroma.ListTest do
assert list_two in lists
refute list_three in lists
end
+
+ test "getting onwered lists the user belongs" do
+ owner = insert(:user)
+ not_owner = insert(:user)
+ member_1 = insert(:user)
+ member_2 = insert(:user)
+ {:ok, ownered_list} = Pleroma.List.create("ownered", owner)
+ {:ok, not_ownered_list} = Pleroma.List.create("not ownered", not_owner)
+ {:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_1)
+ {:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_2)
+ {:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_1)
+ {:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_2)
+
+ lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id)
+ assert ownered_list in lists_1
+ refute not_ownered_list in lists_1
+ lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id)
+ assert ownered_list in lists_2
+ refute not_ownered_list in lists_2
+ end
end