diff options
author | Lain Soykaf <lain@lain.com> | 2025-02-23 17:51:25 +0400 |
---|---|---|
committer | Lain Soykaf <lain@lain.com> | 2025-02-23 17:51:25 +0400 |
commit | a92b1fbdedf1fafdc4a29993ffacd5bf70bfd84e (patch) | |
tree | cdfc6d3cc5a2a61432e89fe020e391186e7b9819 /lib | |
parent | 0d7d6ebebb2008bff3a0e6d11ba1795d12a3cb67 (diff) | |
download | pleroma-a92b1fbdedf1fafdc4a29993ffacd5bf70bfd84e.tar.gz pleroma-a92b1fbdedf1fafdc4a29993ffacd5bf70bfd84e.zip |
UserRelationshipTest: Don't use Mock.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/datetime.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/datetime/impl.ex | 6 | ||||
-rw-r--r-- | lib/pleroma/user_relationship.ex | 10 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/pleroma/datetime.ex b/lib/pleroma/datetime.ex new file mode 100644 index 000000000..d79cb848b --- /dev/null +++ b/lib/pleroma/datetime.ex @@ -0,0 +1,3 @@ +defmodule Pleroma.DateTime do + @callback utc_now() :: NaiveDateTime.t() +end diff --git a/lib/pleroma/datetime/impl.ex b/lib/pleroma/datetime/impl.ex new file mode 100644 index 000000000..102be047b --- /dev/null +++ b/lib/pleroma/datetime/impl.ex @@ -0,0 +1,6 @@ +defmodule Pleroma.DateTime.Impl do + @behaviour Pleroma.DateTime + + @impl true + def utc_now, do: NaiveDateTime.utc_now() +end diff --git a/lib/pleroma/user_relationship.ex b/lib/pleroma/user_relationship.ex index 82fcc1cdd..5b48d321a 100644 --- a/lib/pleroma/user_relationship.ex +++ b/lib/pleroma/user_relationship.ex @@ -55,9 +55,13 @@ defmodule Pleroma.UserRelationship do def user_relationship_mappings, do: Pleroma.UserRelationship.Type.__enum_map__() + def datetime_impl do + Application.get_env(:pleroma, :datetime_impl, Pleroma.DateTime.Impl) + end + def changeset(%UserRelationship{} = user_relationship, params \\ %{}) do user_relationship - |> cast(params, [:relationship_type, :source_id, :target_id, :expires_at]) + |> cast(params, [:relationship_type, :source_id, :target_id, :expires_at, :inserted_at]) |> validate_required([:relationship_type, :source_id, :target_id]) |> unique_constraint(:relationship_type, name: :user_relationships_source_id_relationship_type_target_id_index @@ -65,6 +69,7 @@ defmodule Pleroma.UserRelationship do |> validate_not_self_relationship() end + @spec exists?(any(), Pleroma.User.t(), Pleroma.User.t()) :: boolean() def exists?(relationship_type, %User{} = source, %User{} = target) do UserRelationship |> where(relationship_type: ^relationship_type, source_id: ^source.id, target_id: ^target.id) @@ -90,7 +95,8 @@ defmodule Pleroma.UserRelationship do relationship_type: relationship_type, source_id: source.id, target_id: target.id, - expires_at: expires_at + expires_at: expires_at, + inserted_at: datetime_impl().utc_now() }) |> Repo.insert( on_conflict: {:replace_all_except, [:id, :inserted_at]}, |