Files
grecia/spec/controllers/legislation/answers_controller_spec.rb
Javi Martín 8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00

59 lines
2.0 KiB
Ruby

require "rails_helper"
describe Legislation::AnswersController do
describe "POST create" do
let(:legal_process) do
create(:legislation_process, debate_start_date: Date.current - 3.days,
debate_end_date: Date.current + 2.days)
end
let(:question) { create(:legislation_question, process: legal_process, title: "Question 1") }
let(:question_option) { create(:legislation_question_option, question: question, value: "Yes") }
let(:user) { create(:user, :level_two) }
it "creates an ahoy event" do
sign_in user
post :create, params: {
process_id: legal_process.id,
question_id: question.id,
legislation_answer: {
legislation_question_option_id: question_option.id
}
}
expect(Ahoy::Event.where(name: :legislation_answer_created).count).to eq 1
expect(Ahoy::Event.last.properties["legislation_answer_id"]).to eq Legislation::Answer.last.id
end
it "creates an answer if the process debate phase is open" do
sign_in user
expect do
post :create, xhr: true,
params: {
process_id: legal_process.id,
question_id: question.id,
legislation_answer: {
legislation_question_option_id: question_option.id
}
}
end.to change { question.reload.answers_count }.by(1)
end
it "does not create an answer if the process debate phase is not open" do
sign_in user
legal_process.update!(debate_end_date: Date.current - 1.day)
expect do
post :create, xhr: true,
params: {
process_id: legal_process.id,
question_id: question.id,
legislation_answer: {
legislation_question_option_id: question_option.id
}
}
end.not_to change { question.reload.answers_count }
end
end
end