2018-12-23 15:11:29 -05:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-12-11 07:31:52 -05:00
|
|
|
defmodule Pleroma.Tests.Helpers do
|
|
|
|
@moduledoc """
|
|
|
|
Helpers for use in tests.
|
|
|
|
"""
|
|
|
|
|
|
|
|
defmacro __using__(_opts) do
|
|
|
|
quote do
|
2019-07-05 00:22:08 -04:00
|
|
|
def collect_ids(collection) do
|
|
|
|
collection
|
|
|
|
|> Enum.map(& &1.id)
|
|
|
|
|> Enum.sort()
|
|
|
|
end
|
|
|
|
|
2018-12-11 07:31:52 -05:00
|
|
|
def refresh_record(%{id: id, __struct__: model} = _),
|
|
|
|
do: refresh_record(model, %{id: id})
|
|
|
|
|
|
|
|
def refresh_record(model, %{id: id} = _) do
|
|
|
|
Pleroma.Repo.get_by(model, id: id)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Used for comparing json rendering during tests.
|
|
|
|
def render_json(view, template, assigns) do
|
|
|
|
assigns = Map.new(assigns)
|
|
|
|
|
|
|
|
view.render(template, assigns)
|
|
|
|
|> Poison.encode!()
|
|
|
|
|> Poison.decode!()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|