Skip to content

Commit

Permalink
Move permission helper method closer to where it's used
Browse files Browse the repository at this point in the history
The `BatchInvitationPermissionsHelper#formatted_permission_name` method
is only used in `UsersHelper#items_for_permission_checkboxes` and so it
makes more sense to define it in `UsersHelper` closer to where it's
being used. We _could_ also make it private, but I decided it was worth
keeping the tests around it and so left it as public.
  • Loading branch information
floehopper committed Oct 9, 2023
1 parent d3991d5 commit d353421
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
9 changes: 0 additions & 9 deletions app/helpers/batch_invitation_permissions_helper.rb

This file was deleted.

8 changes: 8 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ def items_for_permission_checkboxes(application:, user: nil)
def supported_permission_checkbox_id(application, permission)
"user_application_#{application.id}_supported_permission_#{permission.id}"
end

def formatted_permission_name(application_name, permission_name)
if permission_name == SupportedPermission::SIGNIN_NAME
"Has access to #{application_name}?"
else
permission_name
end
end
end
13 changes: 0 additions & 13 deletions test/helpers/batch_invitation_permissions_helper_test.rb

This file was deleted.

12 changes: 10 additions & 2 deletions test/helpers/users_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class UsersHelperTest < ActionView::TestCase
end
end

include BatchInvitationPermissionsHelper

context "#items_for_permission_checkboxes" do
should "return permission options suitable for checkboxes component" do
application = create(:application)
Expand Down Expand Up @@ -114,4 +112,14 @@ class UsersHelperTest < ActionView::TestCase
assert_equal expected_items, items
end
end

context "#formatted_permission_name" do
should "return the permission name if permission is not the signin permission" do
assert_equal "Editor", formatted_permission_name("Whitehall", "Editor")
end

should "include the application name if permission is the signin permission" do
assert_equal "Has access to Whitehall?", formatted_permission_name("Whitehall", SupportedPermission::SIGNIN_NAME)
end
end
end

0 comments on commit d353421

Please sign in to comment.