votes_controller_spec.rb 865 B

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