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.

188 lines
5.4 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Follow do
  3. let(:sender) { Fabricate(:account) }
  4. let(:recipient) { Fabricate(:account) }
  5. let(:json) do
  6. {
  7. '@context': 'https://www.w3.org/ns/activitystreams',
  8. id: 'foo',
  9. type: 'Follow',
  10. actor: ActivityPub::TagManager.instance.uri_for(sender),
  11. object: ActivityPub::TagManager.instance.uri_for(recipient),
  12. }.with_indifferent_access
  13. end
  14. describe '#perform' do
  15. subject { described_class.new(json, sender) }
  16. context 'with no prior follow' do
  17. context 'unlocked account' do
  18. before do
  19. subject.perform
  20. end
  21. it 'creates a follow from sender to recipient' do
  22. expect(sender.following?(recipient)).to be true
  23. expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
  24. end
  25. it 'does not create a follow request' do
  26. expect(sender.requested?(recipient)).to be false
  27. end
  28. end
  29. context 'silenced account following an unlocked account' do
  30. before do
  31. sender.touch(:silenced_at)
  32. subject.perform
  33. end
  34. it 'does not create a follow from sender to recipient' do
  35. expect(sender.following?(recipient)).to be false
  36. end
  37. it 'creates a follow request' do
  38. expect(sender.requested?(recipient)).to be true
  39. expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
  40. end
  41. end
  42. context 'unlocked account muting the sender' do
  43. before do
  44. recipient.mute!(sender)
  45. subject.perform
  46. end
  47. it 'creates a follow from sender to recipient' do
  48. expect(sender.following?(recipient)).to be true
  49. expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
  50. end
  51. it 'does not create a follow request' do
  52. expect(sender.requested?(recipient)).to be false
  53. end
  54. end
  55. context 'locked account' do
  56. before do
  57. recipient.update(locked: true)
  58. subject.perform
  59. end
  60. it 'does not create a follow from sender to recipient' do
  61. expect(sender.following?(recipient)).to be false
  62. end
  63. it 'creates a follow request' do
  64. expect(sender.requested?(recipient)).to be true
  65. expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
  66. end
  67. end
  68. end
  69. context 'when a follow relationship already exists' do
  70. before do
  71. sender.active_relationships.create!(target_account: recipient, uri: 'bar')
  72. end
  73. context 'unlocked account' do
  74. before do
  75. subject.perform
  76. end
  77. it 'correctly sets the new URI' do
  78. expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
  79. end
  80. it 'does not create a follow request' do
  81. expect(sender.requested?(recipient)).to be false
  82. end
  83. end
  84. context 'silenced account following an unlocked account' do
  85. before do
  86. sender.touch(:silenced_at)
  87. subject.perform
  88. end
  89. it 'correctly sets the new URI' do
  90. expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
  91. end
  92. it 'does not create a follow request' do
  93. expect(sender.requested?(recipient)).to be false
  94. end
  95. end
  96. context 'unlocked account muting the sender' do
  97. before do
  98. recipient.mute!(sender)
  99. subject.perform
  100. end
  101. it 'correctly sets the new URI' do
  102. expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
  103. end
  104. it 'does not create a follow request' do
  105. expect(sender.requested?(recipient)).to be false
  106. end
  107. end
  108. context 'locked account' do
  109. before do
  110. recipient.update(locked: true)
  111. subject.perform
  112. end
  113. it 'correctly sets the new URI' do
  114. expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
  115. end
  116. it 'does not create a follow request' do
  117. expect(sender.requested?(recipient)).to be false
  118. end
  119. end
  120. end
  121. context 'when a follow request already exists' do
  122. before do
  123. sender.follow_requests.create!(target_account: recipient, uri: 'bar')
  124. end
  125. context 'silenced account following an unlocked account' do
  126. before do
  127. sender.touch(:silenced_at)
  128. subject.perform
  129. end
  130. it 'does not create a follow from sender to recipient' do
  131. expect(sender.following?(recipient)).to be false
  132. end
  133. it 'correctly sets the new URI' do
  134. expect(sender.requested?(recipient)).to be true
  135. expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
  136. end
  137. end
  138. context 'locked account' do
  139. before do
  140. recipient.update(locked: true)
  141. subject.perform
  142. end
  143. it 'does not create a follow from sender to recipient' do
  144. expect(sender.following?(recipient)).to be false
  145. end
  146. it 'correctly sets the new URI' do
  147. expect(sender.requested?(recipient)).to be true
  148. expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
  149. end
  150. end
  151. end
  152. end
  153. end