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:
@@ -15,7 +15,7 @@
|
|||||||
<th><%= t("admin.actions.actions") %></th>
|
<th><%= t("admin.actions.actions") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<% @poll.questions.each do |question| %>
|
<% @poll.questions.sort_for_list.each do |question| %>
|
||||||
<tr id="<%= dom_id(question) %>">
|
<tr id="<%= dom_id(question) %>">
|
||||||
<td>
|
<td>
|
||||||
<strong><%= question.title %></strong>
|
<strong><%= question.title %></strong>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
<%= poll_dates(poll) %>
|
<%= poll_dates(poll) %>
|
||||||
|
|
||||||
<ul class="margin-top">
|
<ul class="margin-top">
|
||||||
<% poll.questions.each do |question| %>
|
<% poll.questions.sort_for_list.each do |question| %>
|
||||||
<li><%= question.title %></li>
|
<li><%= question.title %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -173,6 +173,24 @@ describe "Polls" do
|
|||||||
expect(page).to have_content(proposal_question.title)
|
expect(page).to have_content(proposal_question.title)
|
||||||
end
|
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
|
scenario "Question answers appear in the given order" do
|
||||||
question = create(:poll_question, poll: poll)
|
question = create(:poll_question, poll: poll)
|
||||||
answer1 = create(:poll_question_answer, title: "First", question: question, given_order: 2)
|
answer1 = create(:poll_question_answer, title: "First", question: question, given_order: 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user