Files
nairobi/spec/controllers/debates_controller_spec.rb
Javi Martín db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00

54 lines
1.4 KiB
Ruby

require "rails_helper"
describe DebatesController do
describe "POST create" do
before do
InvisibleCaptcha.timestamp_enabled = false
end
after do
InvisibleCaptcha.timestamp_enabled = true
end
it "creates an ahoy event" do
debate_attributes = {
terms_of_service: "1",
translations_attributes: {
"0" => {
title: "A sample debate",
description: "this is a sample debate",
locale: "en"
}
}
}
sign_in create(:user)
post :create, params: { debate: debate_attributes }
expect(Ahoy::Event.where(name: :debate_created).count).to eq 1
expect(Ahoy::Event.last.properties["debate_id"]).to eq Debate.last.id
end
end
describe "Vote with too many anonymous votes" do
it "allows vote if user is allowed" do
Setting["max_ratio_anon_votes_on_debates"] = 100
debate = create(:debate)
sign_in create(:user)
expect do
post :vote, xhr: true, params: { id: debate.id, value: "yes" }
end.to change { debate.reload.votes_for.size }.by(1)
end
it "does not allow vote if user is not allowed" do
Setting["max_ratio_anon_votes_on_debates"] = 0
debate = create(:debate, cached_votes_total: 1000)
sign_in create(:user)
expect do
post :vote, xhr: true, params: { id: debate.id, value: "yes" }
end.not_to change { debate.reload.votes_for.size }
end
end
end