block_spec.rb 2.6 KB

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