Check if debate phase is open to create answers
This commit is contained in:
43
spec/controllers/legislation/answers_controller_spec.rb
Normal file
43
spec/controllers/legislation/answers_controller_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Legislation::AnswersController do
|
||||
|
||||
describe 'POST create' do
|
||||
before(:each) do
|
||||
InvisibleCaptcha.timestamp_enabled = false
|
||||
@process = create(:legislation_process, debate_start_date: Date.current - 3.day, debate_end_date: Date.current + 2.days)
|
||||
@question = create(:legislation_question, process: @process, title: "Question 1")
|
||||
@question_option = create(:legislation_question_option, question: @question, value: "Yes")
|
||||
@user = create(:user, :level_two)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
InvisibleCaptcha.timestamp_enabled = true
|
||||
end
|
||||
|
||||
it 'should create an ahoy event' do
|
||||
sign_in @user
|
||||
|
||||
post :create, process_id: @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 'should create an answer if the process debate phase is open' do
|
||||
sign_in @user
|
||||
|
||||
expect do
|
||||
xhr :post, :create, process_id: @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 'should not create an answer if the process debate phase is not open' do
|
||||
sign_in @user
|
||||
@process.update_attribute(:debate_end_date, Date.current - 1.day)
|
||||
|
||||
expect do
|
||||
xhr :post, :create, process_id: @process.id, question_id: @question.id, legislation_answer: { legislation_question_option_id: @question_option.id }
|
||||
end.to_not change { @question.reload.answers_count }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user