Skip to content

Commit

Permalink
Merge pull request #3076 from alphagov/update-users-application-polic…
Browse files Browse the repository at this point in the history
…y-tests

Update `Users::ApplicationPolicy` tests
  • Loading branch information
yndajas authored Aug 8, 2024
2 parents a46523c + 25d5c76 commit 387a3d7
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions test/policies/users/application_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ class Users::ApplicationPolicyTest < ActiveSupport::TestCase
@application = create(:application)
end

%i[show index view_permissions].each do |aliased_method|
context "##{aliased_method}?" do
setup { @args = [@current_user, { application: @application, user: @user }, aliased_method] }

context "when the current user can edit the given user" do
setup { stub_policy @current_user, @user, edit?: true }
should("be permitted") { assert permit?(*@args) }
end

context "when the current user cannot edit the given user" do
setup { stub_policy @current_user, @user, edit?: false }
should("be forbidden") { assert forbid?(*@args) }
end
end
end

%i[grant_signin_permission remove_signin_permission edit_permissions].each do |aliased_method|
context "##{aliased_method}?" do
setup do
Expand Down Expand Up @@ -85,24 +101,4 @@ class Users::ApplicationPolicyTest < ActiveSupport::TestCase
end
end
end

context "#view_permissions?" do
setup do
@args = [
@current_user,
{ application: @application, user: @user },
:view_permissions,
]
end

context "when the current user can edit the given user" do
setup { stub_policy @current_user, @user, edit?: true }
should("be permitted") { assert permit?(*@args) }
end

context "when the current user cannot edit the given user" do
setup { stub_policy @current_user, @user, edit?: false }
should("be forbidden") { assert forbid?(*@args) }
end
end
end

0 comments on commit 387a3d7

Please sign in to comment.