rich media: disable cachex in test mode
authorWilliam Pitcock <nenolod@dereferenced.org>
Fri, 4 Jan 2019 23:50:54 +0000 (23:50 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Fri, 4 Jan 2019 23:53:26 +0000 (23:53 +0000)
lib/pleroma/web/rich_media/parser.ex

index b88ed537103493eaa79075ec5ce6408240034054..3746feaf688b275b8a70cc5bb15ac91a40191b58 100644 (file)
@@ -1,14 +1,17 @@
 defmodule Pleroma.Web.RichMedia.Parser do
   @parsers [Pleroma.Web.RichMedia.Parsers.OGP]
 
-  def parse(url) do
-    Cachex.fetch!(:rich_media_cache, url, fn _ ->
-      {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url)
+  if Mix.env() == :test do
+    def parse(url), do: parse_url(url)
+  else
+    def parse(url),
+      do: {:commit, Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end)}
+  end
 
-      result = html |> maybe_parse() |> get_parsed_data()
+  defp parse_url(url) do
+    {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url)
 
-      {:commit, result}
-    end)
+    html |> maybe_parse() |> get_parsed_data()
   end
 
   defp maybe_parse(html) do