docbrown/spec/requests/poll_skips_spec.rb
Fabbri Paolo 89e893f157 Fix rubocop detected offenses (#4552)
* 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`
2019-10-24 11:53:03 -04:00

33 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