* Run Inspecting 1050 files ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C..................................................................................................................................................................................................................................................................................................... Offenses: spec/models/article_spec.rb:195:7: C: RSpec/NestedGroups: Maximum example group nesting exceeded [4/3]. (http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NestedGroups) context "when description is empty" do ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1050 files inspected, 1 offense detected to fix autofixable errors * Refactor to correct test it was braking the rule RSpec/NestedGroups: Maximum example group nesting exceeded [4/3]. (http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NestedGroups) * Run `rubocop --auto-gen-config` to regenrate `.rubocop_todo.yml`
54 lines
2.3 KiB
Ruby
54 lines
2.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "PollVotes", type: :request do
|
|
let(:user) { create(:user) }
|
|
let(:article) { create(:article) }
|
|
let(:poll) { create(:poll, article_id: article.id) }
|
|
|
|
before { sign_in user }
|
|
|
|
describe "GET /poll_votes" do
|
|
it "returns proper results for poll" do
|
|
get "/poll_votes/#{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)
|
|
end
|
|
|
|
it "returns proper results for poll if voted" do
|
|
create(:poll_vote, user_id: user.id, poll_option_id: poll.poll_options.first.id, poll_id: poll.id)
|
|
get "/poll_votes/#{poll.id}"
|
|
expect(JSON.parse(response.body)["voting_data"]["votes_count"]).to eq(1)
|
|
expect(JSON.parse(response.body)["voting_data"]["votes_distribution"]).to include([poll.poll_options.first.id, 1])
|
|
expect(JSON.parse(response.body)["poll_id"]).to eq(poll.id)
|
|
expect(JSON.parse(response.body)["voted"]).to eq(true)
|
|
end
|
|
end
|
|
|
|
describe "POST /poll_votes" do
|
|
it "votes on behalf of current user" do
|
|
post "/poll_votes", params: {
|
|
poll_vote: { poll_option_id: poll.poll_options.first.id }
|
|
}
|
|
expect(JSON.parse(response.body)["voting_data"]["votes_count"]).to eq(1)
|
|
expect(JSON.parse(response.body)["voting_data"]["votes_distribution"]).to include([poll.poll_options.first.id, 1])
|
|
expect(JSON.parse(response.body)["poll_id"]).to eq(poll.id)
|
|
expect(JSON.parse(response.body)["voted"]).to eq(true)
|
|
expect(user.poll_votes.size).to eq(1)
|
|
end
|
|
|
|
it "votes on behalf of current user only once" do
|
|
post "/poll_votes", params: {
|
|
poll_vote: { poll_option_id: poll.poll_options.first.id }
|
|
}
|
|
post "/poll_votes", params: {
|
|
poll_vote: { poll_option_id: poll.poll_options.first.id }
|
|
}
|
|
expect(JSON.parse(response.body)["voting_data"]["votes_count"]).to eq(1)
|
|
expect(JSON.parse(response.body)["voting_data"]["votes_distribution"]).to include([poll.poll_options.first.id, 1])
|
|
expect(JSON.parse(response.body)["voted"]).to eq(true)
|
|
expect(user.poll_votes.size).to eq(1)
|
|
end
|
|
end
|
|
end
|