polls_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(body_as_json).to match(
  20. a_hash_including(
  21. id: poll.id.to_s,
  22. voted: false,
  23. voters_count: poll.voters_count,
  24. votes_count: poll.votes_count
  25. )
  26. )
  27. end
  28. end
  29. context 'when parent status is private' do
  30. let(:visibility) { 'private' }
  31. it 'returns http not found' do
  32. subject
  33. expect(response).to have_http_status(404)
  34. end
  35. end
  36. end
  37. end