* Change: #538 NGワード「フォローしていないアカウントへのメンションで利用できないキーワード」を、参照投稿にも適用する * Update create.rb * Update create.rb * Update create.rb * Fix test
This commit is contained in:
parent
5c543c602b
commit
76b5d4f2c6
13 changed files with 265 additions and 41 deletions
|
@ -1978,6 +1978,50 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with references' do
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
let!(:target_status) { Fabricate(:status, account: recipient) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'ohagi is bad',
|
||||
references: {
|
||||
id: 'target_status',
|
||||
type: 'Collection',
|
||||
first: {
|
||||
type: 'CollectionPage',
|
||||
next: nil,
|
||||
partOf: 'target_status',
|
||||
items: [
|
||||
ActivityPub::TagManager.instance.uri_for(target_status),
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
context 'with a simple case' do
|
||||
it 'creates status' do
|
||||
expect(sender.statuses.first).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with following' do
|
||||
let(:custom_before_sub) { true }
|
||||
|
||||
before do
|
||||
recipient.follow!(sender)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
expect(sender.statuses.first).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when hashtags limit is set' do
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FetchReferencesService, type: :service do
|
||||
subject { described_class.new.call(status, payload) }
|
||||
subject { described_class.new.call(status.account, payload) }
|
||||
|
||||
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
|
||||
let(:status) { Fabricate(:status, account: actor) }
|
||||
|
|
|
@ -29,7 +29,8 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
|
|||
tag: json_tags,
|
||||
}
|
||||
end
|
||||
let(:json) { Oj.load(Oj.dump(payload)) }
|
||||
let(:payload_override) { {} }
|
||||
let(:json) { Oj.load(Oj.dump(payload.merge(payload_override))) }
|
||||
|
||||
let(:alice) { Fabricate(:account) }
|
||||
let(:bob) { Fabricate(:account) }
|
||||
|
@ -601,6 +602,49 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when hit ng words for reference' do
|
||||
let!(:target_status) { Fabricate(:status, account: alice) }
|
||||
let(:payload_override) do
|
||||
{
|
||||
references: {
|
||||
id: 'target_status',
|
||||
type: 'Collection',
|
||||
first: {
|
||||
type: 'CollectionPage',
|
||||
next: nil,
|
||||
partOf: 'target_status',
|
||||
items: [
|
||||
ActivityPub::TagManager.instance.uri_for(target_status),
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
let(:content) { 'ng word test' }
|
||||
|
||||
it 'update status' do
|
||||
Form::AdminSettings.new(ng_words_for_stranger_mention: 'test', stranger_mention_from_local_ng: '1').save
|
||||
|
||||
subject.call(status, json, json)
|
||||
expect(status.reload.text).to_not eq content
|
||||
expect(status.references.pluck(:id)).to_not include target_status.id
|
||||
end
|
||||
|
||||
context 'when alice follows sender' do
|
||||
before do
|
||||
alice.follow!(status.account)
|
||||
end
|
||||
|
||||
it 'update status' do
|
||||
Form::AdminSettings.new(ng_words_for_stranger_mention: 'test').save
|
||||
|
||||
subject.call(status, json, json)
|
||||
expect(status.reload.text).to eq content
|
||||
expect(status.references.pluck(:id)).to include target_status.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using hashtag under limit' do
|
||||
let(:json_tags) do
|
||||
[
|
||||
|
|
|
@ -684,6 +684,43 @@ RSpec.describe PostStatusService, type: :service do
|
|||
expect(status.text).to eq text
|
||||
end
|
||||
|
||||
it 'with a reference' do
|
||||
target_status = Fabricate(:status)
|
||||
account = Fabricate(:account)
|
||||
Fabricate(:account, username: 'ohagi', domain: nil)
|
||||
text = "ref BT: #{ActivityPub::TagManager.instance.uri_for(target_status)}"
|
||||
|
||||
status = subject.call(account, text: text)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
expect(status.references.pluck(:id)).to include target_status.id
|
||||
end
|
||||
|
||||
it 'hit ng words for reference' do
|
||||
target_status = Fabricate(:status)
|
||||
account = Fabricate(:account)
|
||||
Fabricate(:account, username: 'ohagi', domain: nil)
|
||||
text = "ng word test BT: #{ActivityPub::TagManager.instance.uri_for(target_status)}"
|
||||
Form::AdminSettings.new(ng_words_for_stranger_mention: 'test', stranger_mention_from_local_ng: '1').save
|
||||
|
||||
expect { subject.call(account, text: text) }.to raise_error(Mastodon::ValidationError)
|
||||
end
|
||||
|
||||
it 'hit ng words for reference to follower' do
|
||||
target_status = Fabricate(:status)
|
||||
account = Fabricate(:account)
|
||||
target_status.account.follow!(account)
|
||||
Fabricate(:account, username: 'ohagi', domain: nil)
|
||||
text = "ng word test BT: #{ActivityPub::TagManager.instance.uri_for(target_status)}"
|
||||
Form::AdminSettings.new(ng_words_for_stranger_mention: 'test', stranger_mention_from_local_ng: '1').save
|
||||
|
||||
status = subject.call(account, text: text)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
end
|
||||
|
||||
it 'using hashtag under limit' do
|
||||
account = Fabricate(:account)
|
||||
text = '#a #b'
|
||||
|
|
|
@ -344,6 +344,43 @@ RSpec.describe UpdateStatusService, type: :service do
|
|||
expect(status.text).to eq text
|
||||
end
|
||||
|
||||
it 'add reference' do
|
||||
target_status = Fabricate(:status)
|
||||
text = "ng word test BT: #{ActivityPub::TagManager.instance.uri_for(target_status)}"
|
||||
|
||||
status = PostStatusService.new.call(account, text: 'hello')
|
||||
|
||||
status = subject.call(status, status.account_id, text: text)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
expect(status.references.pluck(:id)).to include target_status.id
|
||||
end
|
||||
|
||||
it 'hit ng words for reference' do
|
||||
target_status = Fabricate(:status)
|
||||
text = "ng word test BT: #{ActivityPub::TagManager.instance.uri_for(target_status)}"
|
||||
Form::AdminSettings.new(ng_words_for_stranger_mention: 'test', stranger_mention_from_local_ng: '1').save
|
||||
|
||||
status = PostStatusService.new.call(account, text: 'hello')
|
||||
|
||||
expect { subject.call(status, status.account_id, text: text) }.to raise_error(Mastodon::ValidationError)
|
||||
end
|
||||
|
||||
it 'hit ng words for reference to follower' do
|
||||
target_status = Fabricate(:status)
|
||||
target_status.account.follow!(status.account)
|
||||
text = "ng word test BT: #{ActivityPub::TagManager.instance.uri_for(target_status)}"
|
||||
Form::AdminSettings.new(ng_words_for_stranger_mention: 'test', stranger_mention_from_local_ng: '1').save
|
||||
|
||||
status = PostStatusService.new.call(account, text: 'hello')
|
||||
|
||||
status = subject.call(status, status.account_id, text: text)
|
||||
|
||||
expect(status).to be_persisted
|
||||
expect(status.text).to eq text
|
||||
end
|
||||
|
||||
it 'using hashtag under limit' do
|
||||
text = '#a #b'
|
||||
Form::AdminSettings.new(post_hash_tags_max: 2).save
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue