reblog_service_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 'OStatus' do
  27. let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com') }
  28. let(:status) { Fabricate(:status, account: bob, uri: 'tag:example.com;something:something') }
  29. subject { ReblogService.new }
  30. before do
  31. stub_request(:post, 'http://salmon.example.com')
  32. subject.call(alice, status)
  33. end
  34. it 'creates a reblog' do
  35. expect(status.reblogs.count).to eq 1
  36. end
  37. end
  38. context 'ActivityPub' do
  39. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  40. let(:status) { Fabricate(:status, account: bob) }
  41. subject { ReblogService.new }
  42. before do
  43. stub_request(:post, bob.inbox_url)
  44. allow(ActivityPub::DistributionWorker).to receive(:perform_async)
  45. subject.call(alice, status)
  46. end
  47. it 'creates a reblog' do
  48. expect(status.reblogs.count).to eq 1
  49. end
  50. describe 'after_create_commit :store_uri' do
  51. it 'keeps consistent reblog count' do
  52. expect(status.reblogs.count).to eq 1
  53. end
  54. end
  55. it 'distributes to followers' do
  56. expect(ActivityPub::DistributionWorker).to have_received(:perform_async)
  57. end
  58. it 'sends an announce activity to the author' do
  59. expect(a_request(:post, bob.inbox_url)).to have_been_made.once
  60. end
  61. end
  62. end