diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2019-05-17 19:57:14 +0700 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2019-05-17 19:57:14 +0700 |
commit | 557f0e33a7de7ef89c72441ffc3a9c09c56fe9a7 (patch) | |
tree | 8044adbc3645ccd1c7dce13b396e7d23db51a0fb /test/tasks/database_test.exs | |
parent | f2936e0a0723956c167a06dc51518da172a508b2 (diff) | |
parent | e5b34f5e0544371603bc2b570c26ede3182c2f8b (diff) | |
download | pleroma-557f0e33a7de7ef89c72441ffc3a9c09c56fe9a7.tar.gz pleroma-557f0e33a7de7ef89c72441ffc3a9c09c56fe9a7.zip |
Merge remote-tracking branch 'pleroma/develop' into feature/addressable-lists
Diffstat (limited to 'test/tasks/database_test.exs')
-rw-r--r-- | test/tasks/database_test.exs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/tasks/database_test.exs b/test/tasks/database_test.exs new file mode 100644 index 000000000..579130b05 --- /dev/null +++ b/test/tasks/database_test.exs @@ -0,0 +1,49 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.DatabaseTest do + alias Pleroma.Repo + alias Pleroma.User + use Pleroma.DataCase + + import Pleroma.Factory + + setup_all do + Mix.shell(Mix.Shell.Process) + + on_exit(fn -> + Mix.shell(Mix.Shell.IO) + end) + + :ok + end + + describe "running update_users_following_followers_counts" do + test "following and followers count are updated" do + [user, user2] = insert_pair(:user) + {:ok, %User{following: following, info: info} = user} = User.follow(user, user2) + + assert length(following) == 2 + assert info.follower_count == 0 + + info_cng = Ecto.Changeset.change(info, %{follower_count: 3}) + + {:ok, user} = + user + |> Ecto.Changeset.change(%{following: following ++ following}) + |> Ecto.Changeset.put_embed(:info, info_cng) + |> Repo.update() + + assert length(user.following) == 4 + assert user.info.follower_count == 3 + + assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"]) + + user = User.get_by_id(user.id) + + assert length(user.following) == 2 + assert user.info.follower_count == 0 + end + end +end |