This commit is contained in:
parent
9a3c8c5bda
commit
a6b5e64e15
11 changed files with 163 additions and 8 deletions
|
@ -2068,7 +2068,79 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
|
||||
context 'when mentions limit is set' do
|
||||
let(:post_mentions_max) { 2 }
|
||||
let(:post_mentions_max) { 3 }
|
||||
let(:post_stranger_mentions_max) { 0 }
|
||||
let(:custom_before) { true }
|
||||
let(:mention_recipient_alice) { Fabricate(:account) }
|
||||
let(:mention_recipient_bob) { Fabricate(:account) }
|
||||
let(:mention_recipient_ohagi) { Fabricate(:account) }
|
||||
let(:mention_recipient_ohagi_follow) { true }
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
tag: [
|
||||
{
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(mention_recipient_alice),
|
||||
},
|
||||
{
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(mention_recipient_bob),
|
||||
},
|
||||
{
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(mention_recipient_ohagi),
|
||||
},
|
||||
],
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
Form::AdminSettings.new(post_mentions_max: post_mentions_max, post_stranger_mentions_max: post_stranger_mentions_max).save
|
||||
|
||||
mention_recipient_alice.follow!(sender)
|
||||
mention_recipient_bob.follow!(sender)
|
||||
mention_recipient_ohagi.follow!(sender) if mention_recipient_ohagi_follow
|
||||
|
||||
subject.perform
|
||||
end
|
||||
|
||||
context 'when limit is enough' do
|
||||
it 'creates status' do
|
||||
expect(sender.statuses.first).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when limit is over' do
|
||||
let(:post_mentions_max) { 1 }
|
||||
|
||||
it 'creates status' do
|
||||
expect(sender.statuses.first).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when limit for stranger is over but normal limit is not reach' do
|
||||
let(:post_stranger_mentions_max) { 1 }
|
||||
|
||||
it 'creates status' do
|
||||
expect(sender.statuses.first).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when limit for stranger is over and following partically' do
|
||||
let(:post_stranger_mentions_max) { 1 }
|
||||
let(:mention_recipient_ohagi_follow) { false }
|
||||
|
||||
it 'creates status' do
|
||||
expect(sender.statuses.first).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when mentions limit for stranger is set' do
|
||||
let(:post_stranger_mentions_max) { 2 }
|
||||
let(:custom_before) { true }
|
||||
let(:object_json) do
|
||||
{
|
||||
|
@ -2089,7 +2161,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
|
||||
before do
|
||||
Form::AdminSettings.new(post_mentions_max: post_mentions_max).save
|
||||
Form::AdminSettings.new(post_stranger_mentions_max: post_stranger_mentions_max).save
|
||||
subject.perform
|
||||
end
|
||||
|
||||
|
@ -2100,7 +2172,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
|
||||
context 'when limit is over' do
|
||||
let(:post_mentions_max) { 1 }
|
||||
let(:post_stranger_mentions_max) { 1 }
|
||||
|
||||
it 'creates status' do
|
||||
expect(sender.statuses.first).to be_nil
|
||||
|
|
|
@ -742,9 +742,11 @@ RSpec.describe PostStatusService, type: :service do
|
|||
end
|
||||
|
||||
it 'using mentions under limit' do
|
||||
Fabricate(:account, username: 'a')
|
||||
Fabricate(:account, username: 'b')
|
||||
a = Fabricate(:account, username: 'a')
|
||||
b = Fabricate(:account, username: 'b')
|
||||
account = Fabricate(:account)
|
||||
a.follow!(account)
|
||||
b.follow!(account)
|
||||
text = '@a @b'
|
||||
Form::AdminSettings.new(post_mentions_max: 2).save
|
||||
|
||||
|
@ -755,11 +757,64 @@ RSpec.describe PostStatusService, type: :service do
|
|||
end
|
||||
|
||||
it 'using mentions over limit' do
|
||||
a = Fabricate(:account, username: 'a')
|
||||
b = Fabricate(:account, username: 'b')
|
||||
account = Fabricate(:account)
|
||||
a.follow!(account)
|
||||
b.follow!(account)
|
||||
text = '@a @b'
|
||||
Form::AdminSettings.new(post_mentions_max: 1).save
|
||||
|
||||
expect { subject.call(account, text: text) }.to raise_error Mastodon::ValidationError
|
||||
end
|
||||
|
||||
it 'using mentions for stranger under limit' do
|
||||
Fabricate(:account, username: 'a')
|
||||
Fabricate(:account, username: 'b')
|
||||
account = Fabricate(:account)
|
||||
text = '@a @b'
|
||||
Form::AdminSettings.new(post_mentions_max: 1).save
|
||||
Form::AdminSettings.new(post_stranger_mentions_max: 2).save
|
||||
|
||||
status = subject.call(account, text: text)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
end
|
||||
|
||||
it 'using mentions for stranger over limit' do
|
||||
Fabricate(:account, username: 'a')
|
||||
Fabricate(:account, username: 'b')
|
||||
account = Fabricate(:account)
|
||||
text = '@a @b'
|
||||
Form::AdminSettings.new(post_stranger_mentions_max: 1).save
|
||||
|
||||
expect { subject.call(account, text: text) }.to raise_error Mastodon::ValidationError
|
||||
end
|
||||
|
||||
it 'using mentions for stranger over limit but normal setting is under limit' do
|
||||
a = Fabricate(:account, username: 'a')
|
||||
b = Fabricate(:account, username: 'b')
|
||||
account = Fabricate(:account)
|
||||
a.follow!(account)
|
||||
b.follow!(account)
|
||||
text = '@a @b'
|
||||
Form::AdminSettings.new(post_mentions_max: 2, post_stranger_mentions_max: 1).save
|
||||
|
||||
status = subject.call(account, text: text)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
end
|
||||
|
||||
it 'using mentions for stranger over limit but normal setting is under limit when following one only' do
|
||||
a = Fabricate(:account, username: 'a')
|
||||
b = Fabricate(:account, username: 'b')
|
||||
Fabricate(:account, username: 'c')
|
||||
account = Fabricate(:account)
|
||||
a.follow!(account)
|
||||
b.follow!(account)
|
||||
text = '@a @b @c'
|
||||
Form::AdminSettings.new(post_mentions_max: 3, post_stranger_mentions_max: 2).save
|
||||
|
||||
expect { subject.call(account, text: text) }.to raise_error Mastodon::ValidationError
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue