From 56bacc90d1f401f8867e4ca7a052f7d15e18a304 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 2 May 2017 10:43:35 +0200 Subject: [PATCH] Fix specs, add local marker to actitivies. --- lib/pleroma/activity.ex | 1 + .../20170502083023_add_local_field_to_activities.exs | 11 +++++++++++ test/support/builders/activity_builder.ex | 4 ++-- test/web/twitter_api/twitter_api_test.exs | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20170502083023_add_local_field_to_activities.exs diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 80d96d0f2..d77c88997 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Activity do schema "activities" do field :data, :map + field :local, :boolean, default: true timestamps() end diff --git a/priv/repo/migrations/20170502083023_add_local_field_to_activities.exs b/priv/repo/migrations/20170502083023_add_local_field_to_activities.exs new file mode 100644 index 000000000..088d68f67 --- /dev/null +++ b/priv/repo/migrations/20170502083023_add_local_field_to_activities.exs @@ -0,0 +1,11 @@ +defmodule Pleroma.Repo.Migrations.AddLocalFieldToActivities do + use Ecto.Migration + + def change do + alter table(:activities) do + add :local, :boolean, default: true + end + + create index(:activities, [:local]) + end +end diff --git a/test/support/builders/activity_builder.ex b/test/support/builders/activity_builder.ex index 0f9cd0d15..16011edbf 100644 --- a/test/support/builders/activity_builder.ex +++ b/test/support/builders/activity_builder.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Builders.ActivityBuilder do def build(data \\ %{}, opts \\ %{}) do user = opts[:user] || Pleroma.Factory.insert(:user) activity = %{ - "id" => 1, + "id" => Pleroma.Web.ActivityPub.ActivityPub.generate_object_id, "actor" => user.ap_id, "to" => ["https://www.w3.org/ns/activitystreams#Public"], "object" => %{ @@ -23,7 +23,7 @@ defmodule Pleroma.Builders.ActivityBuilder do def insert_list(times, data \\ %{}, opts \\ %{}) do Enum.map(1..times, fn (n) -> - {:ok, activity} = insert(Map.merge(data, %{"id" => n})) + {:ok, activity} = insert(data) activity end) end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 207d9d12a..57dcddd4c 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -40,6 +40,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert Enum.member?(get_in(activity.data, ["to"]), User.ap_followers(user)) assert Enum.member?(get_in(activity.data, ["to"]), "https://www.w3.org/ns/activitystreams#Public") assert Enum.member?(get_in(activity.data, ["to"]), "shp") + assert activity.local == true # Add a context assert is_binary(get_in(activity.data, ["context"]))