Merge pull request #3757 from consul/fix_answers_given_order
Fix duplicate given order creating answers
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user