Skip to content

Commit

Permalink
Make ApplicationTableHelper tests more realistic
Browse files Browse the repository at this point in the history
You would usually use the account applications section to edit your own
permissions, and the user applications section to edit another user's
permissions. The tests were editing a single user's own permissions in
for both account- and user-related methods. This splits out the granter
and grantee for tests of user-related methods
  • Loading branch information
yndajas committed Jun 28, 2024
1 parent 2090ce5 commit e162e35
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions test/helpers/application_table_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ class ApplicationTableHelperTest < ActionView::TestCase
context "#users_applications_grant_access_link" do
setup do
@application = create(:application)
@grantee = create(:user)
end

should "generate a grant access button when the user can create user application permissions" do
user = create(:superadmin_user)
stubs(:current_user).returns(user)
granter = create(:superadmin_user)
stubs(:current_user).returns(granter)

assert_includes users_applications_grant_access_link(@application, user), "Grant access"
assert_includes users_applications_grant_access_link(@application, @grantee), "Grant access"
end

should "return an empty string when the user cannot create user application permissions" do
user = create(:user)
stubs(:current_user).returns(user)
granter = create(:user)
stubs(:current_user).returns(granter)

assert users_applications_grant_access_link(@application, user).empty?
assert users_applications_grant_access_link(@application, @grantee).empty?
end
end

Expand All @@ -62,20 +63,21 @@ class ApplicationTableHelperTest < ActionView::TestCase
context "#users_applications_remove_access_link" do
setup do
@application = create(:application, with_supported_permissions: %w[permission])
@grantee = create(:user)
end

should "generate a remove access link when the user can delete permissions" do
user = create(:superadmin_user)
stubs(:current_user).returns(user)
granter = create(:superadmin_user)
stubs(:current_user).returns(granter)

assert_includes users_applications_remove_access_link(@application, user), "Remove access"
assert_includes users_applications_remove_access_link(@application, @grantee), "Remove access"
end

should "return an empty string when the user cannot delete permissions" do
user = create(:user)
stubs(:current_user).returns(user)
granter = create(:user)
stubs(:current_user).returns(granter)

assert users_applications_remove_access_link(@application, user).empty?
assert users_applications_remove_access_link(@application, @grantee).empty?
end
end

Expand Down Expand Up @@ -105,30 +107,32 @@ class ApplicationTableHelperTest < ActionView::TestCase
context "#users_applications_permissions_link" do
setup do
@application = create(:application, with_supported_permissions: %w[permission])
@grantee = create(:user)
end

should "generate an update link when the user can edit permissions" do
user = create(:superadmin_user)
stubs(:current_user).returns(user)
granter = create(:superadmin_user)
stubs(:current_user).returns(granter)

assert_includes users_applications_permissions_link(@application, user), "Update permissions"
assert_includes users_applications_permissions_link(@application, @grantee), "Update permissions"
end

should "generate a view link when the user cannot edit permissions" do
user = create(:user)
stubs(:current_user).returns(user)
granter = create(:user)
stubs(:current_user).returns(granter)

assert_includes users_applications_permissions_link(@application, user), "View permissions"
assert_includes users_applications_permissions_link(@application, @grantee), "View permissions"
end
end

context "#api_users_applications_permissions_link" do
should "generate an update link when the user can edit permissions" do
application = create(:application, with_supported_permissions: %w[permission])
user = create(:superadmin_user)
stubs(:current_user).returns(user)
granter = create(:superadmin_user)
grantee = create(:api_user)
stubs(:current_user).returns(granter)

assert_includes api_users_applications_permissions_link(application, user), "Update permissions"
assert_includes api_users_applications_permissions_link(application, grantee), "Update permissions"
end
end

Expand Down

0 comments on commit e162e35

Please sign in to comment.