diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 7f8fc8e4d..18b9add0f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -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)) diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index 7514b85a4..ccbcf1abd 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -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 diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index d9d871249..177d5e66d 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -79,7 +79,7 @@
- <% @poll.questions.map(&:question_answers).flatten.each do |answer| %> + <% @poll_questions_answers.each do |answer| %>
@@ -128,7 +128,7 @@
<% end %>
- +
@@ -138,4 +138,4 @@
<%= render "comments" %>
- \ No newline at end of file + diff --git a/spec/features/admin/poll/questions/answers/answers_spec.rb b/spec/features/admin/poll/questions/answers/answers_spec.rb index 48c2017f4..8514f2f26 100644 --- a/spec/features/admin/poll/questions/answers/answers_spec.rb +++ b/spec/features/admin/poll/questions/answers/answers_spec.rb @@ -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) diff --git a/spec/features/polls/answers_spec.rb b/spec/features/polls/answers_spec.rb index 368597830..32b5732a0 100644 --- a/spec/features/polls/answers_spec.rb +++ b/spec/features/polls/answers_spec.rb @@ -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) @@ -56,4 +56,4 @@ feature 'Answers' do true end -end \ No newline at end of file +end diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index fc21e1e5f..90deca711 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -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)