votes_controller_spec.rb 877 B

123456789101112131415161718192021222324252627282930313233343536
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::Polls::VotesController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. let(:scopes) { 'write:statuses' }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  8. before { allow(controller).to receive(:doorkeeper_token) { token } }
  9. describe 'POST #create' do
  10. let(:poll) { Fabricate(:poll) }
  11. before do
  12. post :create, params: { poll_id: poll.id, choices: %w(1) }
  13. end
  14. it 'returns http success' do
  15. expect(response).to have_http_status(200)
  16. end
  17. it 'creates a vote' do
  18. vote = poll.votes.where(account: user.account).first
  19. expect(vote).to_not be_nil
  20. expect(vote.choice).to eq 1
  21. end
  22. it 'updates poll tallies' do
  23. expect(poll.reload.cached_tallies).to eq [0, 1]
  24. end
  25. end
  26. end