From 330d66027320b4475eb9cc5ed7bac0dd7cbbc342 Mon Sep 17 00:00:00 2001 From: Chris Lowis Date: Wed, 11 Oct 2023 14:49:54 +0100 Subject: [PATCH] Improve usability of organisation select on batch_invitations/new This makes it easier to select the organisation for a batch of users by excluding closed organisations and sorting the remaining ones alphabetically. We did something similar in #2426 and #2417 - there's enough subtle differences in those two select boxes (indicating a current organisation and adding a "None" option respectively) that I haven't attempted to extract the duplication. I think the new scopes are self-explanatory enough that I'm happy to keep them inline in this view. --- app/views/batch_invitations/new.html.erb | 2 +- test/controllers/batch_invitations_controller_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/batch_invitations/new.html.erb b/app/views/batch_invitations/new.html.erb index 80224afd6..19fcab1f0 100644 --- a/app/views/batch_invitations/new.html.erb +++ b/app/views/batch_invitations/new.html.erb @@ -73,7 +73,7 @@ id: "batch_invitation_organisation_id", name: "batch_invitation[organisation_id]", label: "Organisation", - options: policy_scope(Organisation).map { |organisation| { text: organisation.name_with_abbreviation, value: organisation.id } } + options: policy_scope(Organisation).not_closed.order(:name).map { |organisation| { text: organisation.name_with_abbreviation, value: organisation.id } } } %> <% end %> diff --git a/test/controllers/batch_invitations_controller_test.rb b/test/controllers/batch_invitations_controller_test.rb index 9f043554f..05b0850f6 100644 --- a/test/controllers/batch_invitations_controller_test.rb +++ b/test/controllers/batch_invitations_controller_test.rb @@ -25,6 +25,14 @@ def users_csv(filename = "users.csv") assert_select "#batch_invitation_organisation_id option", organisation.name end + + should "exclude closed organisations from select" do + create(:organisation) + create(:organisation, closed: true) + get :new + + assert_select "#batch_invitation_organisation_id option", 1 + end end context "POST create" do