Skip to content

Commit

Permalink
Merge pull request #2504 from alphagov/use-assert-not-authorised-to-d…
Browse files Browse the repository at this point in the history
…ry-up-assertions

Use TestHelper#assert_not_authorised to DRY up tests
  • Loading branch information
floehopper authored Nov 9, 2023
2 parents 848c9cb + 71d6cda commit e2e88de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
18 changes: 9 additions & 9 deletions test/controllers/invitations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
get :new

assert_redirected_to root_path
assert_not_authorised
end
end

Expand All @@ -147,7 +147,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
get :new

assert_redirected_to root_path
assert_not_authorised
end
end

Expand All @@ -159,7 +159,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
get :new

assert_redirected_to root_path
assert_not_authorised
end
end

Expand Down Expand Up @@ -452,7 +452,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
post :create, params: { user: { name: "invitee", email: "invitee@gov.uk" } }

assert_redirected_to root_path
assert_not_authorised
end
end

Expand All @@ -464,7 +464,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
post :create, params: { user: { name: "org-admin-invitee", email: "org-admin-invitee@gov.uk" } }

assert_redirected_to root_path
assert_not_authorised
end
end

Expand All @@ -476,7 +476,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
post :create, params: { user: { name: "super-org-admin-invitee", email: "super-org-admin-invitee@gov.uk" } }

assert_redirected_to root_path
assert_not_authorised
end
end

Expand Down Expand Up @@ -516,7 +516,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
post :resend, params: { id: @user_to_resend_for }

assert_redirected_to root_path
assert_not_authorised
end
end

Expand All @@ -528,7 +528,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
post :resend, params: { id: @user_to_resend_for }

assert_redirected_to root_path
assert_not_authorised
end
end

Expand All @@ -540,7 +540,7 @@ class InvitationsControllerTest < ActionController::TestCase
should "disallow access" do
post :resend, params: { id: @user_to_resend_for }

assert_redirected_to root_path
assert_not_authorised
end
end

Expand Down
14 changes: 5 additions & 9 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class UsersControllerTest < ActionController::TestCase

should "disallow access" do
get :index
assert_redirected_to root_path
assert_not_authorised
end
end
end
Expand Down Expand Up @@ -303,8 +303,7 @@ class UsersControllerTest < ActionController::TestCase

get :edit, params: { id: superadmin.id }

assert_redirected_to root_path
assert_match(/You do not have permission to perform this action./, flash[:alert])
assert_not_authorised
end

should "can give permissions to all applications" do
Expand Down Expand Up @@ -579,8 +578,7 @@ class UsersControllerTest < ActionController::TestCase

get :edit, params: { id: another_user }

assert_redirected_to root_path
assert_equal "You do not have permission to perform this action.", flash[:alert]
assert_not_authorised
end
end
end
Expand All @@ -598,8 +596,7 @@ class UsersControllerTest < ActionController::TestCase

put :edit, params: { id: superadmin.id, user: { email: "normal_user@example.com" } }

assert_redirected_to root_path
assert_match(/You do not have permission to perform this action./, flash[:alert])
assert_not_authorised
end

should "update the user's organisation" do
Expand Down Expand Up @@ -736,8 +733,7 @@ class UsersControllerTest < ActionController::TestCase

put :update, params: { id: user.id, user: { organisation_id: @organisation_admin.organisation.id } }

assert_redirected_to root_path
assert_match(/You do not have permission to perform this action./, flash[:alert])
assert_not_authorised
end

should "redisplay the form if save fails" do
Expand Down

0 comments on commit e2e88de

Please sign in to comment.