add_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Add do
  3. let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') }
  4. let(:status) { Fabricate(:status, account: sender) }
  5. let(:json) do
  6. {
  7. '@context': 'https://www.w3.org/ns/activitystreams',
  8. id: 'foo',
  9. type: 'Add',
  10. actor: ActivityPub::TagManager.instance.uri_for(sender),
  11. object: ActivityPub::TagManager.instance.uri_for(status),
  12. target: sender.featured_collection_url,
  13. }.with_indifferent_access
  14. end
  15. describe '#perform' do
  16. subject { described_class.new(json, sender) }
  17. it 'creates a pin' do
  18. subject.perform
  19. expect(sender.pinned?(status)).to be true
  20. end
  21. context 'when status was not known before' do
  22. let(:json) do
  23. {
  24. '@context': 'https://www.w3.org/ns/activitystreams',
  25. id: 'foo',
  26. type: 'Add',
  27. actor: ActivityPub::TagManager.instance.uri_for(sender),
  28. object: 'https://example.com/unknown',
  29. target: sender.featured_collection_url,
  30. }.with_indifferent_access
  31. end
  32. before do
  33. stub_request(:get, 'https://example.com/unknown').to_return(status: 410)
  34. end
  35. it 'fetches the status' do
  36. subject.perform
  37. expect(a_request(:get, 'https://example.com/unknown')).to have_been_made.at_least_once
  38. end
  39. end
  40. end
  41. end