Files
grecia/spec/controllers/debates_controller_spec.rb
Senén Rodero Rodríguez 51cda51155 Add debates translation interface
Also fix broken spec after removing translatable attributes from
strong_parameters definition. Now we need to send these attributes
as nested translations attributes.

Use activerecord.yml title attribute label so form helper could load it
from default location.
2019-06-27 09:19:36 +02:00

59 lines
1.5 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, 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
after do
Setting["max_ratio_anon_votes_on_debates"] = 50
end
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