diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-02-13 16:36:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-13 16:36:29 +0100 |
commit | d6930b3847405dc9f8c1a54fb74d488a3c9a775e (patch) | |
tree | feb3e7aa1713113cd8792c739cdd8ad8456560ed /spec/services/post_status_service_spec.rb | |
parent | c84f38abc4b82d77c5d832399d5746fe51de3c67 (diff) |
Add API parameter to safeguard unexpect mentions in new posts (#18350)
Diffstat (limited to 'spec/services/post_status_service_spec.rb')
-rw-r--r-- | spec/services/post_status_service_spec.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index d21270c79..28f20e9c7 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -138,7 +138,26 @@ RSpec.describe PostStatusService, type: :service do status = subject.call(account, text: "test status update") expect(ProcessMentionsService).to have_received(:new) - expect(mention_service).to have_received(:call).with(status) + expect(mention_service).to have_received(:call).with(status, save_records: false) + end + + it 'safeguards mentions' do + account = Fabricate(:account) + mentioned_account = Fabricate(:account, username: 'alice') + unexpected_mentioned_account = Fabricate(:account, username: 'bob') + + expect do + subject.call(account, text: '@alice hm, @bob is really annoying lately', allowed_mentions: [mentioned_account.id]) + end.to raise_error(an_instance_of(PostStatusService::UnexpectedMentionsError).and having_attributes(accounts: [unexpected_mentioned_account])) + end + + it 'processes duplicate mentions correctly' do + account = Fabricate(:account) + mentioned_account = Fabricate(:account, username: 'alice') + + expect do + subject.call(account, text: '@alice @alice @alice hey @alice') + end.not_to raise_error end it 'processes hashtags' do |