Merge pull request #3757 from consul/fix_answers_given_order

Fix duplicate given order creating answers
This commit is contained in:
Javier Martín
2019-10-10 20:56:27 +02:00
committed by GitHub
2 changed files with 12 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ class Polls::AnswersController < ApplicationController
if @question.votation_type.open? && !check_question_answer_exist
@question.question_answers.create(
title: params[:answer],
given_order: @question.question_answers.count + 1,
given_order: @question.question_answers.maximum(:given_order).to_i + 1,
hidden: false
)
flash.now[:notice] = t("dashboard.polls.index.succesfull")

View File

@@ -320,6 +320,17 @@ describe "Poll Votation Type" do
expect(page).to have_link "Added answer", class: "answered"
end
end
scenario "existing given order is bigger than the number of answers", :js do
answer1.update(given_order: question.question_answers.count + 1)
visit poll_path(poll_current)
fill_in "answer", with: "Added answer"
click_button "Add answer"
expect(page).to have_link "Added answer"
end
end
context "Answers set" do