follow_spec.rb 5.5 KB

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