-
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.
Move permissions_for to PermissionsHelper
In preparation for using this helper in the /account pages. There's nothing specific to batch invitations in this method and moving it won't break any existing functionality because we currently include all helpers into every view.
- Loading branch information
Showing
4 changed files
with
36 additions
and
32 deletions.
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
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,8 @@ | ||
module PermissionsHelper | ||
def permissions_for(application) | ||
all_permissions = application.supported_permissions.grantable_from_ui | ||
signin, others = all_permissions.partition(&:signin?) | ||
|
||
signin + others.sort_by(&:name) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "test_helper" | ||
|
||
class PermissionsHelperTest < ActionView::TestCase | ||
context "#permissions_for" do | ||
should "return all of the supported permissions that are grantable from the ui" do | ||
application = create(:application, | ||
name: "Whitehall", | ||
with_supported_permissions: ["Editor", SupportedPermission::SIGNIN_NAME], | ||
with_supported_permissions_not_grantable_from_ui: ["Not grantable"]) | ||
|
||
permission_names = permissions_for(application).map(&:name) | ||
|
||
assert permission_names.include?("Editor") | ||
assert permission_names.include?(SupportedPermission::SIGNIN_NAME) | ||
assert_not permission_names.include?("Not grantable") | ||
end | ||
|
||
should "sort the permissions alphabetically by name, but with the signin permission first" do | ||
application = create(:application, | ||
name: "Whitehall", | ||
with_supported_permissions: ["Writer", "Editor", SupportedPermission::SIGNIN_NAME]) | ||
|
||
permission_names = permissions_for(application).map(&:name) | ||
|
||
assert_equal [SupportedPermission::SIGNIN_NAME, "Editor", "Writer"], permission_names | ||
end | ||
end | ||
end |