instance_actors_controller_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe InstanceActorsController do
  4. describe 'GET #show' do
  5. context 'with JSON' do
  6. let(:format) { 'json' }
  7. shared_examples 'shared behavior' do
  8. before do
  9. get :show, params: { format: format }
  10. end
  11. it 'returns http success with correct media type, headers, and session values' do
  12. expect(response)
  13. .to have_http_status(200)
  14. .and have_attributes(
  15. media_type: eq('application/activity+json'),
  16. cookies: be_empty
  17. )
  18. expect(response.headers)
  19. .to include('Cache-Control' => include('public'))
  20. .and not_include('Set-Cookies')
  21. expect(session).to be_empty
  22. expect(body_as_json)
  23. .to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
  24. end
  25. end
  26. before do
  27. allow(controller).to receive(:authorized_fetch_mode?).and_return(authorized_fetch_mode)
  28. end
  29. context 'without authorized fetch mode' do
  30. let(:authorized_fetch_mode) { false }
  31. it_behaves_like 'shared behavior'
  32. end
  33. context 'with authorized fetch mode' do
  34. let(:authorized_fetch_mode) { true }
  35. it_behaves_like 'shared behavior'
  36. end
  37. end
  38. end
  39. end