闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
914 B

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::Polls::VotesController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  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