Files
nairobi/spec/controllers/legislation/answers_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

59 lines
2.1 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_attribute(: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