From 64f42d412b8560a7d126935767da57c7a54e5068 Mon Sep 17 00:00:00 2001 From: miffigriffi Date: Wed, 18 Sep 2019 00:37:31 +0200 Subject: [PATCH] mix credo warnings in Mobilizon context --- lib/mobilizon/actors/actors.ex | 8 ++++++-- lib/mobilizon/events/events.ex | 8 ++++++-- test/mobilizon/events/events_test.exs | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index b58138648..66b53fa9c 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -115,7 +115,9 @@ defmodule Mobilizon.Actors do """ @spec get_actor_by_name(String.t(), atom | nil) :: Actor.t() | nil def get_actor_by_name(name, type \\ nil) do - from(a in Actor) + query = from(a in Actor) + + query |> filter_by_type(type) |> filter_by_name(String.split(name, "@")) |> Repo.one() @@ -126,7 +128,9 @@ defmodule Mobilizon.Actors do """ @spec get_local_actor_by_name(String.t()) :: Actor.t() | nil def get_local_actor_by_name(name) do - from(a in Actor) + query = from(a in Actor) + + query |> filter_by_name([name]) |> Repo.one() end diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 152ce813f..d85f88b51 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -293,7 +293,9 @@ defmodule Mobilizon.Events do is_unlisted \\ false, is_future \\ true ) do - from(e in Event, preload: [:organizer_actor, :participants]) + query = from(e in Event, preload: [:organizer_actor, :participants]) + + query |> Page.paginate(page, limit) |> sort(sort, direction) |> filter_future_events(is_future) @@ -779,8 +781,10 @@ defmodule Mobilizon.Events do @spec get_comment_from_url_with_preload(String.t()) :: {:ok, Comment.t()} | {:error, :comment_not_found} def get_comment_from_url_with_preload(url) do + query = from(c in Comment, where: c.url == ^url) + comment = - from(c in Comment, where: c.url == ^url) + query |> preload_for_comment() |> Repo.one() diff --git a/test/mobilizon/events/events_test.exs b/test/mobilizon/events/events_test.exs index 440c1029b..83e5dca53 100644 --- a/test/mobilizon/events/events_test.exs +++ b/test/mobilizon/events/events_test.exs @@ -419,7 +419,7 @@ defmodule Mobilizon.EventsTest do test "list_sessions_for_event/1 returns sessions for an event" do event = insert(:event) session = insert(:session, event: event) - assert Events.list_sessions_for_event(event) |> Enum.map(& &1.id) == [session.id] + assert event |> Events.list_sessions_for_event() |> Enum.map(& &1.id) == [session.id] end test "get_session!/1 returns the session with given id" do @@ -491,7 +491,7 @@ defmodule Mobilizon.EventsTest do event = insert(:event) track = insert(:track, event: event) session = insert(:session, track: track, event: event) - assert Events.list_sessions_for_track(track) |> Enum.map(& &1.id) == [session.id] + assert track |> Events.list_sessions_for_track() |> Enum.map(& &1.id) == [session.id] end test "get_track!/1 returns the track with given id" do