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.

107 lines
2.6 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Block 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: 'Block',
  10. actor: ActivityPub::TagManager.instance.uri_for(sender),
  11. object: ActivityPub::TagManager.instance.uri_for(recipient),
  12. }.with_indifferent_access
  13. end
  14. context 'when the recipient does not follow the sender' do
  15. describe '#perform' do
  16. subject { described_class.new(json, sender) }
  17. before do
  18. subject.perform
  19. end
  20. it 'creates a block from sender to recipient' do
  21. expect(sender.blocking?(recipient)).to be true
  22. end
  23. end
  24. end
  25. context 'when the recipient is already blocked' do
  26. before do
  27. sender.block!(recipient, uri: 'old')
  28. end
  29. describe '#perform' do
  30. subject { described_class.new(json, sender) }
  31. before do
  32. subject.perform
  33. end
  34. it 'creates a block from sender to recipient' do
  35. expect(sender.blocking?(recipient)).to be true
  36. end
  37. it 'sets the uri to that of last received block activity' do
  38. expect(sender.block_relationships.find_by(target_account: recipient).uri).to eq 'foo'
  39. end
  40. end
  41. end
  42. context 'when the recipient follows the sender' do
  43. before do
  44. recipient.follow!(sender)
  45. end
  46. describe '#perform' do
  47. subject { described_class.new(json, sender) }
  48. before do
  49. subject.perform
  50. end
  51. it 'creates a block from sender to recipient' do
  52. expect(sender.blocking?(recipient)).to be true
  53. end
  54. it 'ensures recipient is not following sender' do
  55. expect(recipient.following?(sender)).to be false
  56. end
  57. end
  58. end
  59. context 'when a matching undo has been received first' do
  60. let(:undo_json) do
  61. {
  62. '@context': 'https://www.w3.org/ns/activitystreams',
  63. id: 'bar',
  64. type: 'Undo',
  65. actor: ActivityPub::TagManager.instance.uri_for(sender),
  66. object: json,
  67. }.with_indifferent_access
  68. end
  69. before do
  70. recipient.follow!(sender)
  71. ActivityPub::Activity::Undo.new(undo_json, sender).perform
  72. end
  73. describe '#perform' do
  74. subject { described_class.new(json, sender) }
  75. before do
  76. subject.perform
  77. end
  78. it 'does not create a block from sender to recipient' do
  79. expect(sender.blocking?(recipient)).to be false
  80. end
  81. it 'ensures recipient is not following sender' do
  82. expect(recipient.following?(sender)).to be false
  83. end
  84. end
  85. end
  86. end