8000 Don't repeat activities within 5 minutes by Floppy · Pull Request #2538 · manyfold3d/manyfold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't repeat activities within 5 minutes #2538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


8000 Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GIT

GIT
remote: https://gitlab.com/manyfold3d/federails.git
revision: df6de7ed21eb6efae1ff0a68d997d51ec5019fcd
revision: 168de5edffdbb30905395868cb892db886806cc6
branch: polymorphic_actor_relationship
specs:
federails (0.0.1)
Expand Down
3 changes: 3 additions & 0 deletions app/models/concerns/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Followable
extend ActiveSupport::Concern
include FederailsCommon

TIMEOUT = 5

included do
delegate :following_followers, to: :actor
after_create :post_creation_activity
Expand Down Expand Up @@ -30,6 +32,7 @@ def post_creation_activity
end

def post_update_activity
return if actor.activities_as_entity.where(created_at: TIMEOUT.minutes.ago..).count > 0
default_user = User.with_role(:administrator).first
return if default_user.nil?
Federails::Activity.create!(
Expand Down
45 changes: 37 additions & 8 deletions spec/models/concerns/followable_shared.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
shared_examples "Followable" do
let(:follower) { create(:user) }
let(:target) { create(described_class.to_s.underscore.to_sym) }
context "when being followed" do
let(:follower) { create(:user) }
let(:target) { create(described_class.to_s.underscore.to_sym) }

before do
follower.follow(target)
before do
follower.follow(target)
end

it "shows as being followed by follower" do
expect(target.followed_by?(follower)).to be true
end

it "gets follower count" do
expect(target.followers.count).to eq 1
end
end

it "shows as being followed by follower" do
expect(target.followed_by?(follower)).to be true
context "when being created" do
before do
create(:admin)
end

it "posts an activity" do
expect { create(described_class.to_s.underscore.to_sym) }.to change(Federails::Activity, :count).by(1)
end
end

it "gets follower count" do
expect(target.followers.count).to eq 1
context "when being updated" do
let!(:entity) { create(described_class.to_s.underscore.to_sym) }

before do
create(:admin)
end

it "posts an activity after update" do
expect { entity.update caption: "test" }.to change(Federails::Activity, :count).by(1)
end

it "doesn't posts an activity after update if there's already been one recently" do
entity.update caption: "change"
expect { entity.update caption: "test" }.not_to change(Federails::Activity, :count)
end
end
end
Loading
0