docbrown/spec/requests/poll_skips_spec.rb
Ben Halpern 8ae057b06e
Beta polls feature (admin use only for now) (#3176)
* Initial poll features

* Add basic poll functionality

* Finish (maybe) beta poll functionality
2019-06-15 17:33:30 -04:00

32 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe "PollSkips", type: :request do
let(:user) { create(:user) }
let(:article) { create(:article) }
let(:poll) { create(:poll, article_id: article.id) }
before { sign_in user }
describe "POST /poll_votes" do
it "votes on behalf of current user" do
post "/poll_skips", params: {
poll_skip: { poll_id: poll.id }
}
expect(JSON.parse(response.body)["voting_data"]["votes_count"]).to eq(0)
expect(JSON.parse(response.body)["voting_data"]["votes_distribution"]).to include([poll.poll_options.first.id, 0])
expect(JSON.parse(response.body)["poll_id"]).to eq(poll.id)
expect(JSON.parse(response.body)["voted"]).to eq(false)
expect(user.poll_skips.size).to eq(1)
end
it "only allows one of vote or skip" do
post "/poll_skips", params: {
poll_skip: { poll_id: poll.id }
}
post "/poll_votes", params: {
poll_vote: { poll_option_id: poll.poll_options.first.id }
}
expect(user.poll_skips.size).to eq(1)
expect(user.poll_votes.size).to eq(0)
end
end
end