Always show order poll questions by created at

PostgreSQL doesn't guarantee the order of the records, so we have to
specify it if we want the questions to be displayed in a consistent
order.
This commit is contained in:
decabeza
2021-08-01 00:33:27 +02:00
committed by Javi Martín
parent 25aa77c4c3
commit 9709b267a2
3 changed files with 20 additions and 2 deletions

View File

@@ -15,7 +15,7 @@
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<% @poll.questions.each do |question| %>
<% @poll.questions.sort_for_list.each do |question| %>
<tr id="<%= dom_id(question) %>">
<td>
<strong><%= question.title %></strong>

View File

@@ -37,7 +37,7 @@
<%= poll_dates(poll) %>
<ul class="margin-top">
<% poll.questions.each do |question| %>
<% poll.questions.sort_for_list.each do |question| %>
<li><%= question.title %></li>
<% end %>
</ul>

View File

@@ -173,6 +173,24 @@ describe "Polls" do
expect(page).to have_content(proposal_question.title)
end
scenario "Questions appear by created at order" do
question = create(:poll_question, poll: poll, title: "First question")
create(:poll_question, poll: poll, title: "Second question")
create(:poll_question, poll: poll, title: "Third question")
question.update!(title: "First question edited")
visit polls_path
expect("First question edited").to appear_before("Second question")
expect("Second question").to appear_before("Third question")
visit poll_path(poll)
expect("First question edited").to appear_before("Second question")
expect("Second question").to appear_before("Third question")
end
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: 2)