polls_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Polls' do
  4. let(:user) { Fabricate(:user) }
  5. let(:scopes) { 'read:statuses' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. describe 'GET /api/v1/polls/:id' do
  9. subject do
  10. get "/api/v1/polls/#{poll.id}", headers: headers
  11. end
  12. let(:poll) { Fabricate(:poll, status: Fabricate(:status, visibility: visibility)) }
  13. let(:visibility) { 'public' }
  14. it_behaves_like 'forbidden for wrong scope', 'write write:statuses'
  15. context 'when parent status is public' do
  16. it 'returns the poll data successfully', :aggregate_failures do
  17. subject
  18. expect(response).to have_http_status(200)
  19. expect(response.content_type)
  20. .to start_with('application/json')
  21. expect(response.parsed_body).to match(
  22. a_hash_including(
  23. id: poll.id.to_s,
  24. voted: false,
  25. voters_count: poll.voters_count,
  26. votes_count: poll.votes_count
  27. )
  28. )
  29. end
  30. end
  31. context 'when parent status is private' do
  32. let(:visibility) { 'private' }
  33. it 'returns http not found' do
  34. subject
  35. expect(response).to have_http_status(404)
  36. expect(response.content_type)
  37. .to start_with('application/json')
  38. end
  39. end
  40. end
  41. end