The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

77 lines
3.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe BlockDomainService, type: :service do
  3. let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
  4. let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') }
  5. let!(:bad_status2) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
  6. let!(:bad_attachment) { Fabricate(:media_attachment, account: bad_account, status: bad_status2, file: attachment_fixture('attachment.jpg')) }
  7. let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) }
  8. subject { BlockDomainService.new }
  9. describe 'for a suspension' do
  10. before do
  11. subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend))
  12. end
  13. it 'creates a domain block' do
  14. expect(DomainBlock.blocked?('evil.org')).to be true
  15. end
  16. it 'removes remote accounts from that domain' do
  17. expect(Account.find_remote('badguy666', 'evil.org').suspended?).to be true
  18. end
  19. it 'records suspension date appropriately' do
  20. expect(Account.find_remote('badguy666', 'evil.org').suspended_at).to eq DomainBlock.find_by(domain: 'evil.org').created_at
  21. end
  22. it 'keeps already-banned accounts banned' do
  23. expect(Account.find_remote('badguy', 'evil.org').suspended?).to be true
  24. end
  25. it 'does not overwrite suspension date of already-banned accounts' do
  26. expect(Account.find_remote('badguy', 'evil.org').suspended_at).to_not eq DomainBlock.find_by(domain: 'evil.org').created_at
  27. end
  28. it 'removes the remote accounts\'s statuses and media attachments' do
  29. expect { bad_status1.reload }.to raise_exception ActiveRecord::RecordNotFound
  30. expect { bad_status2.reload }.to raise_exception ActiveRecord::RecordNotFound
  31. expect { bad_attachment.reload }.to raise_exception ActiveRecord::RecordNotFound
  32. end
  33. end
  34. describe 'for a silence with reject media' do
  35. before do
  36. subject.call(DomainBlock.create!(domain: 'evil.org', severity: :silence, reject_media: true))
  37. end
  38. it 'does not create a domain block' do
  39. expect(DomainBlock.blocked?('evil.org')).to be false
  40. end
  41. it 'silences remote accounts from that domain' do
  42. expect(Account.find_remote('badguy666', 'evil.org').silenced?).to be true
  43. end
  44. it 'records suspension date appropriately' do
  45. expect(Account.find_remote('badguy666', 'evil.org').silenced_at).to eq DomainBlock.find_by(domain: 'evil.org').created_at
  46. end
  47. it 'keeps already-banned accounts banned' do
  48. expect(Account.find_remote('badguy', 'evil.org').silenced?).to be true
  49. end
  50. it 'does not overwrite suspension date of already-banned accounts' do
  51. expect(Account.find_remote('badguy', 'evil.org').silenced_at).to_not eq DomainBlock.find_by(domain: 'evil.org').created_at
  52. end
  53. it 'leaves the domains status and attachements, but clears media' do
  54. expect { bad_status1.reload }.not_to raise_error
  55. expect { bad_status2.reload }.not_to raise_error
  56. expect { bad_attachment.reload }.not_to raise_error
  57. expect(bad_attachment.file.exists?).to be false
  58. end
  59. end
  60. end