reblog_service_spec.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. require 'rails_helper'
  2. RSpec.describe ReblogService, type: :service do
  3. let(:alice) { Fabricate(:account, username: 'alice') }
  4. context 'creates a reblog with appropriate visibility' do
  5. let(:visibility) { :public }
  6. let(:reblog_visibility) { :public }
  7. let(:status) { Fabricate(:status, account: alice, visibility: visibility) }
  8. subject { ReblogService.new }
  9. before do
  10. subject.call(alice, status, visibility: reblog_visibility)
  11. end
  12. describe 'boosting privately' do
  13. let(:reblog_visibility) { :private }
  14. it 'reblogs privately' do
  15. expect(status.reblogs.first.visibility).to eq 'private'
  16. end
  17. end
  18. describe 'public reblogs of private toots should remain private' do
  19. let(:visibility) { :private }
  20. let(:reblog_visibility) { :public }
  21. it 'reblogs privately' do
  22. expect(status.reblogs.first.visibility).to eq 'private'
  23. end
  24. end
  25. end
  26. context 'when the reblogged status is discarded in the meantime' do
  27. let(:status) { Fabricate(:status, account: alice, visibility: :public) }
  28. before do
  29. status.discard
  30. end
  31. it 'raises an exception' do
  32. expect { subject.call(alice, status) }.to raise_error ActiveRecord::ActiveRecordError
  33. end
  34. end
  35. context 'ActivityPub' do
  36. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  37. let(:status) { Fabricate(:status, account: bob) }
  38. subject { ReblogService.new }
  39. before do
  40. stub_request(:post, bob.inbox_url)
  41. allow(ActivityPub::DistributionWorker).to receive(:perform_async)
  42. subject.call(alice, status)
  43. end
  44. it 'creates a reblog' do
  45. expect(status.reblogs.count).to eq 1
  46. end
  47. describe 'after_create_commit :store_uri' do
  48. it 'keeps consistent reblog count' do
  49. expect(status.reblogs.count).to eq 1
  50. end
  51. end
  52. it 'distributes to followers' do
  53. expect(ActivityPub::DistributionWorker).to have_received(:perform_async)
  54. end
  55. end
  56. end