Don't allow changing answers if the poll has started
Just like we did with questions.
This commit is contained in:
committed by
Javi Martín
parent
7a812a82e2
commit
3a6e99cb8c
@@ -0,0 +1,88 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::Poll::Questions::AnswersController, :admin do
|
||||
let(:current_question) { create(:poll_question, poll: create(:poll)) }
|
||||
let(:future_question) { create(:poll_question, poll: create(:poll, :future)) }
|
||||
|
||||
describe "POST create" do
|
||||
it "is not possible for an already started poll" do
|
||||
post :create, params: {
|
||||
poll_question_answer: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
title: "Answer from started poll"
|
||||
}
|
||||
}
|
||||
},
|
||||
question_id: current_question
|
||||
}
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'create' on Answer."
|
||||
expect(Poll::Question::Answer.count).to eq 0
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
post :create, params: {
|
||||
poll_question_answer: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
title: "Answer from future poll"
|
||||
}
|
||||
}
|
||||
},
|
||||
question_id: future_question
|
||||
}
|
||||
|
||||
expect(response).to redirect_to admin_question_path(future_question)
|
||||
expect(Poll::Question::Answer.last.title).to eq "Answer from future poll"
|
||||
expect(Poll::Question::Answer.count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH update" do
|
||||
it "is not possible for an already started poll" do
|
||||
current_answer = create(:poll_question_answer, question: current_question, title: "Sample title")
|
||||
|
||||
patch :update, params: {
|
||||
poll_question_answer: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
title: "New title",
|
||||
id: current_answer.translations.first.id
|
||||
}
|
||||
}
|
||||
},
|
||||
question_id: current_question,
|
||||
id: current_answer
|
||||
}
|
||||
|
||||
expect(flash[:alert]).to eq "You do not have permission to carry out the action 'update' on Answer."
|
||||
expect(current_answer.reload.title).to eq "Sample title"
|
||||
end
|
||||
|
||||
it "is possible for a not started poll" do
|
||||
future_answer = create(:poll_question_answer, question: future_question)
|
||||
|
||||
patch :update, params: {
|
||||
poll_question_answer: {
|
||||
translations_attributes: {
|
||||
"0" => {
|
||||
locale: "en",
|
||||
title: "New title",
|
||||
id: future_answer.translations.first.id
|
||||
}
|
||||
}
|
||||
},
|
||||
question_id: future_question,
|
||||
id: future_answer
|
||||
}
|
||||
|
||||
expect(response).to redirect_to admin_question_path(future_question)
|
||||
expect(flash[:notice]).to eq "Changes saved"
|
||||
expect(future_answer.reload.title).to eq "New title"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user