-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2885 from manyfold3d/post-comments-with-activitypub
Post ActivityPub Notes for new, updated, and deleted comments
- Loading branch information
Showing
6 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
module CommentsHelper | ||
def url_for_comment(comment) | ||
url_for([comment.commentable, comment, {only_path: false}]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Comments become Notes in ActvityPub world | ||
json.set! "@context", "https://www.w3.org/ns/activitystreams" | ||
json.id url_for_comment(@comment) | ||
json.id @comment.federated_url | ||
json.type "Note" | ||
json.content markdownify(@comment.comment) | ||
json.context url_for([@comment.commentable, only_path: false]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
FactoryBot.define do | ||
factory :comment do | ||
text { Faker::Lorem.paragraph } | ||
comment { Faker::Lorem.paragraph } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Comment do | ||
it "needs tests" | ||
let!(:model) { create(:model) } | ||
let!(:comment) { create(:comment, commenter: model, commentable: model) } | ||
|
||
it "posts a Federails Activity on creation" do # rubocop:disable RSpec/MultipleExpectations | ||
expect { create(:comment, commenter: model, commentable: model) }.to change(Federails::Activity, :count).by(1) | ||
expect(Federails::Activity.last.action).to eq "Create" | ||
end | ||
|
||
it "posts a Federails Activity on update" do # rubocop:disable RSpec/MultipleExpectations | ||
expect { comment.update(comment: "test") }.to change(Federails::Activity, :count).by(1) | ||
expect(Federails::Activity.last.action).to eq "Update" | ||
end | ||
|
||
it "posts a Federails Activity on deletion" do # rubocop:disable RSpec/MultipleExpectations | ||
expect { comment.destroy }.to change(Federails::Activity, :count).by(1) | ||
expect(Federails::Activity.last.action).to eq "Delete" | ||
end | ||
|
||
it "has a federated_url method" do | ||
expect(comment.federated_url).to eq "http://localhost:3214/models/#{model.public_id}/comments/#{comment.public_id}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters