-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2417 from alphagov/improve-organisation-select-on…
…-role-organisations-page Improve organisation select on role organisations page
- Loading branch information
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module RoleOrganisationsHelper | ||
def options_for_your_organisation_select(current_user) | ||
organisations = Pundit.policy_scope(current_user, Organisation).not_closed.order(:name) | ||
|
||
organisations.map do |organisation| | ||
{ text: organisation.name_with_abbreviation, | ||
value: organisation.id, | ||
selected: current_user.organisation == organisation } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "test_helper" | ||
|
||
class RoleOrganisationsHelperTest < ActionView::TestCase | ||
context "#options_for_your_organisation_select" do | ||
setup do | ||
@user_organisation = create(:organisation, name: "User Organisation", abbreviation: "UO") | ||
@other_organisation = create(:organisation, name: "Other Organisation") | ||
@closed_organisation = create(:organisation, name: "Closed Organisation", closed: true) | ||
@user = create(:admin_user, organisation: @user_organisation) | ||
end | ||
|
||
should "return options suitable for select component with users organisation selected" do | ||
options = options_for_your_organisation_select(@user) | ||
|
||
expected_options = [ | ||
{ | ||
text: "Other Organisation", | ||
value: @other_organisation.id, | ||
selected: false, | ||
}, | ||
{ | ||
text: "User Organisation – UO", | ||
value: @user_organisation.id, | ||
selected: true, | ||
}, | ||
] | ||
|
||
assert_equal expected_options, options | ||
end | ||
|
||
should "sort by organisation name alphabetically" do | ||
options = options_for_your_organisation_select(@user) | ||
|
||
assert_equal ["Other Organisation", "User Organisation – UO"], (options.map { |o| o[:text] }) | ||
end | ||
|
||
should "not include closed organisations" do | ||
closed_organisation_option = options_for_your_organisation_select(@user).detect { |o| o[:value] == @closed_organisation.id } | ||
|
||
assert_not closed_organisation_option | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters