Order legislation process tags alphabetically

The method `tag_list_on` doesn't add an `ORDER_BY` clause to the SQL
query it generates, and so results may come in any order.

However, in the tests we were assuming the tags were ordered by ID in
descending order. Since that isn't always the case, the tests were
failing sometimes.

Ordering the tags alphabetically solves the problem. We could also use
the same order admins used when adding the tags:

```
@process.customs.order("taggings.created_at").pluck(:name).join(", ")
```

However, I'm not sure it improves the user experience, and it makes the
code more complicated.
benefit to administratos.
This commit is contained in:
Javi Martín
2020-04-10 20:36:17 +02:00
parent c9a95c1818
commit 4b043f2207
2 changed files with 6 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
<%= render "shared/errors", resource: @process %>
<div class="small-12 medium-8 column">
<%= f.text_field :custom_list, value: @process.tag_list_on(:customs).to_s,
<%= f.text_field :custom_list, value: @process.tag_list_on(:customs).sort.join(", "),
label: t("admin.legislation.proposals.form.custom_categories"),
hint: t("admin.legislation.proposals.form.custom_categories_description"),
placeholder: t("admin.legislation.proposals.form.custom_categories_placeholder"),

View File

@@ -244,18 +244,20 @@ describe "Admin collaborative legislation" do
visit edit_admin_legislation_process_path(process)
within(".admin-content") { click_link "Proposals" }
fill_in "Categories", with: "recycling,bicycles"
fill_in "Categories", with: "recycling,bicycles,pollution"
click_button "Save changes"
visit admin_legislation_process_proposals_path(process)
expect(page).to have_field("Categories", with: "bicycles, recycling")
expect(page).to have_field("Categories", with: "bicycles, pollution, recycling")
within(".admin-content") { click_link "Information" }
fill_in "Summary", with: "Summarizing the process"
click_button "Save changes"
visit admin_legislation_process_proposals_path(process)
expect(page).to have_field("Categories", with: "bicycles, recycling")
expect(page).to have_field("Categories", with: "bicycles, pollution, recycling")
end
scenario "Edit milestones summary", :js do