logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

block_domain_service_spec.rb (2043B)


  1. require 'rails_helper'
  2. RSpec.describe BlockDomainService 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. subject { BlockDomainService.new }
  8. before do
  9. bad_account
  10. bad_status1
  11. bad_status2
  12. bad_attachment
  13. end
  14. describe 'for a suspension' do
  15. before do
  16. subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend))
  17. end
  18. it 'creates a domain block' do
  19. expect(DomainBlock.blocked?('evil.org')).to be true
  20. end
  21. it 'removes remote accounts from that domain' do
  22. expect(Account.find_remote('badguy666', 'evil.org').suspended?).to be true
  23. end
  24. it 'removes the remote accounts\'s statuses and media attachments' do
  25. expect { bad_status1.reload }.to raise_exception ActiveRecord::RecordNotFound
  26. expect { bad_status2.reload }.to raise_exception ActiveRecord::RecordNotFound
  27. expect { bad_attachment.reload }.to raise_exception ActiveRecord::RecordNotFound
  28. end
  29. end
  30. describe 'for a silence with reject media' do
  31. before do
  32. subject.call(DomainBlock.create!(domain: 'evil.org', severity: :silence, reject_media: true))
  33. end
  34. it 'does not create a domain block' do
  35. expect(DomainBlock.blocked?('evil.org')).to be false
  36. end
  37. it 'silences remote accounts from that domain' do
  38. expect(Account.find_remote('badguy666', 'evil.org').silenced?).to be true
  39. end
  40. it 'leaves the domains status and attachements, but clears media' do
  41. expect { bad_status1.reload }.not_to raise_error
  42. expect { bad_status2.reload }.not_to raise_error
  43. expect { bad_attachment.reload }.not_to raise_error
  44. expect(bad_attachment.file.exists?).to be false
  45. end
  46. end
  47. end