Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
308b35eb
Verified
Commit
308b35eb
authored
Jan 31, 2019
by
href
Browse files
User.follow_all: ensure its stays unique
parent
44913c10
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
308b35eb
...
...
@@ -315,7 +315,16 @@ def follow_all(follower, followeds) do
q
=
from
(
u
in
User
,
where:
u
.
id
==
^
follower
.
id
,
update:
[
set:
[
following:
fragment
(
"array_cat(?, ?)"
,
u
.
following
,
^
followed_addresses
)]]
update:
[
set:
[
following:
fragment
(
"array(select distinct unnest (array_cat(?, ?)))"
,
u
.
following
,
^
followed_addresses
)
]
]
)
{
1
,
[
follower
]}
=
Repo
.
update_all
(
q
,
[],
returning:
true
)
...
...
test/user_test.exs
View file @
308b35eb
...
...
@@ -65,6 +65,19 @@ test "follow_all follows mutliple users" do
refute
User
.
following?
(
user
,
not_followed
)
end
test
"follow_all follows mutliple users without duplicating"
do
user
=
insert
(
:user
)
followed_zero
=
insert
(
:user
)
followed_one
=
insert
(
:user
)
followed_two
=
insert
(
:user
)
{
:ok
,
user
}
=
User
.
follow_all
(
user
,
[
followed_zero
,
followed_one
])
assert
length
(
user
.
following
)
==
3
{
:ok
,
user
}
=
User
.
follow_all
(
user
,
[
followed_one
,
followed_two
])
assert
length
(
user
.
following
)
==
4
end
test
"follow takes a user and another user"
do
user
=
insert
(
:user
)
followed
=
insert
(
:user
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment