Merge branch 'fix/replace-ws' into 'develop'
[akkoma] / test / support / helpers.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Tests.Helpers do
6 @moduledoc """
7 Helpers for use in tests.
8 """
9
10 defmacro __using__(_opts) do
11 quote do
12 def refresh_record(%{id: id, __struct__: model} = _),
13 do: refresh_record(model, %{id: id})
14
15 def refresh_record(model, %{id: id} = _) do
16 Pleroma.Repo.get_by(model, id: id)
17 end
18
19 # Used for comparing json rendering during tests.
20 def render_json(view, template, assigns) do
21 assigns = Map.new(assigns)
22
23 view.render(template, assigns)
24 |> Poison.encode!()
25 |> Poison.decode!()
26 end
27 end
28 end
29 end