Small fixes for Poll Question Answer ordering
This commit is contained in:
@@ -15,6 +15,7 @@ class PollsController < ApplicationController
|
||||
def show
|
||||
@questions = @poll.questions.for_render.sort_for_list
|
||||
@token = poll_voter_token(@poll, current_user)
|
||||
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
|
||||
|
||||
@answers_by_question_id = {}
|
||||
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
||||
|
||||
@@ -25,11 +25,10 @@ class Poll::Question::Answer < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def set_order
|
||||
next_position = self.class.last_position(question_id) + 1
|
||||
self.given_order = next_position
|
||||
self.given_order = self.class.last_position(question_id) + 1
|
||||
end
|
||||
|
||||
def self.last_position(question_id)
|
||||
where(question_id: question_id).maximum("given_order") || 0
|
||||
where(question_id: question_id).maximum('given_order') || 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<div class="expanded poll-more-info-answers">
|
||||
<div class="row padding">
|
||||
|
||||
<% @poll.questions.map(&:question_answers).flatten.each do |answer| %>
|
||||
<% @poll_questions_answers.each do |answer| %>
|
||||
<div class="small-12 medium-6 column end" id="answer_<%= answer.id %>"
|
||||
data-toggler="medium-6 answer-divider">
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ feature 'Answers' do
|
||||
|
||||
scenario 'Update' do
|
||||
question = create(:poll_question)
|
||||
answer = create(:poll_question_answer, question: question, title: "Answer title", given_order: 1)
|
||||
answer2 = create(:poll_question_answer, question: question, title: "Another title", given_order: 2)
|
||||
answer = create(:poll_question_answer, question: question, title: "Answer title", given_order: 2)
|
||||
answer2 = create(:poll_question_answer, question: question, title: "Another title", given_order: 1)
|
||||
|
||||
visit admin_answer_path(answer)
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ feature 'Answers' do
|
||||
|
||||
scenario "Index" do
|
||||
question = create(:poll_question)
|
||||
answer1 = create(:poll_question_answer, question: question, given_order: 1)
|
||||
answer2 = create(:poll_question_answer, question: question, given_order: 2)
|
||||
answer1 = create(:poll_question_answer, question: question, given_order: 2)
|
||||
answer2 = create(:poll_question_answer, question: question, given_order: 1)
|
||||
|
||||
visit admin_question_path(question)
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ feature 'Polls' do
|
||||
|
||||
scenario "Question answers appear in the given order" do
|
||||
question = create(:poll_question, poll: poll)
|
||||
answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 1)
|
||||
answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 2)
|
||||
answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 2)
|
||||
answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 1)
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
@@ -92,8 +92,8 @@ feature 'Polls' do
|
||||
|
||||
scenario "More info answers appear in the given order" do
|
||||
question = create(:poll_question, poll: poll)
|
||||
answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 1)
|
||||
answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 2)
|
||||
answer1 = create(:poll_question_answer, title: 'First', question: question, given_order: 2)
|
||||
answer2 = create(:poll_question_answer, title: 'Second', question: question, given_order: 1)
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user