From 4b043f22076626fd5e1bed17bc017f11d52fa8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 10 Apr 2020 20:36:17 +0200 Subject: [PATCH] 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. --- app/views/admin/legislation/proposals/_form.html.erb | 2 +- spec/features/admin/legislation/processes_spec.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/admin/legislation/proposals/_form.html.erb b/app/views/admin/legislation/proposals/_form.html.erb index 3e6ab0f8f..5d1a14370 100644 --- a/app/views/admin/legislation/proposals/_form.html.erb +++ b/app/views/admin/legislation/proposals/_form.html.erb @@ -3,7 +3,7 @@ <%= render "shared/errors", resource: @process %>
- <%= 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"), diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index b509fc95a..822240489 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -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