Skip to content

Commit

Permalink
Merge pull request #2426 from alphagov/improve-organisation-select-on…
Browse files Browse the repository at this point in the history
…-user-invite-page

Improve Organisation select on /users/invitation/new
  • Loading branch information
chrislo authored Oct 11, 2023
2 parents 696db11 + 47e466e commit dd376e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module UsersHelper
include Pundit::Authorization

def two_step_status(user)
user.two_step_status.humanize.capitalize
end
Expand Down Expand Up @@ -66,7 +68,7 @@ def options_for_role_select(selected: nil)
end

def options_for_organisation_select(selected: nil)
[{ text: "None", value: nil }] + policy_scope(Organisation).map do |organisation|
[{ text: "None", value: nil }] + policy_scope(Organisation).not_closed.order(:name).map do |organisation|
{ text: organisation.name_with_abbreviation, value: organisation.id }.tap do |option|
option[:selected] = true if option[:value] == selected
end
Expand Down
16 changes: 9 additions & 7 deletions test/helpers/users_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ class UsersHelperTest < ActionView::TestCase
end

context "#options_for_organisation_select" do
should "return organisation options suitable for select component" do
organisation1 = create(:organisation)
organisation2 = create(:organisation)
organisations = [organisation1, organisation2]
stubs(:policy_scope).with(Organisation).returns(organisations)
should "return organisation options suitable for select component, sorted alphabetically and exluding closed organisations" do
user = create(:admin_user)
stubs(:current_user).returns(user)

organisation1 = create(:organisation, name: "B Organisation")
organisation2 = create(:organisation, name: "A Organisation")
create(:organisation, name: "Closed Organisation", closed: true)

options = options_for_organisation_select(selected: organisation2.id)

expected_options = [
{ text: "None", value: nil },
{ text: organisation1.name, value: organisation1.id },
{ text: organisation2.name, value: organisation2.id, selected: true },
{ text: "A Organisation", value: organisation2.id, selected: true },
{ text: "B Organisation", value: organisation1.id },
]
assert_equal expected_options, options
end
Expand Down

0 comments on commit dd376e4

Please sign in to comment.