X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f75eb6fe9ef1e0a755c1a1810c5ca15ed58d9d08..cee9818dfc9ac3f6eae01cdb51df9093ae5d1322:/test/controllers/user_roles_controller_test.rb?ds=sidebyside diff --git a/test/controllers/user_roles_controller_test.rb b/test/controllers/user_roles_controller_test.rb index c2ebd3c47..73b4f0424 100644 --- a/test/controllers/user_roles_controller_test.rb +++ b/test/controllers/user_roles_controller_test.rb @@ -23,14 +23,14 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest super_user = create(:super_user) # Granting should fail when not logged in - post grant_role_path(:display_name => target_user.display_name, :role => "moderator") + post grant_role_path(target_user, "moderator") assert_response :forbidden # Login as an unprivileged user session_for(normal_user) # Granting should still fail - post grant_role_path(:display_name => target_user.display_name, :role => "moderator") + post grant_role_path(target_user, "moderator") assert_redirected_to :controller => :errors, :action => :forbidden # Login as an administrator @@ -39,7 +39,7 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest UserRole::ALL_ROLES.each do |role| # Granting a role to a non-existent user should fail assert_difference "UserRole.count", 0 do - post grant_role_path(:display_name => "non_existent_user", :role => role) + post grant_role_path("non_existent_user", role) end assert_response :not_found assert_template "users/no_such_user" @@ -47,20 +47,20 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest # Granting a role to a user that already has it should fail assert_no_difference "UserRole.count" do - post grant_role_path(:display_name => super_user.display_name, :role => role) + post grant_role_path(super_user, role) end assert_redirected_to user_path(super_user) assert_equal "The user already has role #{role}.", flash[:error] # Granting a role to a user that doesn't have it should work... assert_difference "UserRole.count", 1 do - post grant_role_path(:display_name => target_user.display_name, :role => role) + post grant_role_path(target_user, role) end assert_redirected_to user_path(target_user) # ...but trying a second time should fail assert_no_difference "UserRole.count" do - post grant_role_path(:display_name => target_user.display_name, :role => role) + post grant_role_path(target_user, role) end assert_redirected_to user_path(target_user) assert_equal "The user already has role #{role}.", flash[:error] @@ -68,7 +68,7 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest # Granting a non-existent role should fail assert_difference "UserRole.count", 0 do - post grant_role_path(:display_name => target_user.display_name, :role => "no_such_role") + post grant_role_path(target_user, "no_such_role") end assert_redirected_to user_path(target_user) assert_equal "The string `no_such_role' is not a valid role.", flash[:error] @@ -83,14 +83,14 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest super_user = create(:super_user) # Revoking should fail when not logged in - post revoke_role_path(:display_name => target_user.display_name, :role => "moderator") + post revoke_role_path(target_user, "moderator") assert_response :forbidden # Login as an unprivileged user session_for(normal_user) # Revoking should still fail - post revoke_role_path(:display_name => target_user.display_name, :role => "moderator") + post revoke_role_path(target_user, "moderator") assert_redirected_to :controller => :errors, :action => :forbidden # Login as an administrator @@ -99,7 +99,7 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest UserRole::ALL_ROLES.each do |role| # Removing a role from a non-existent user should fail assert_difference "UserRole.count", 0 do - post revoke_role_path(:display_name => "non_existent_user", :role => role) + post revoke_role_path("non_existent_user", role) end assert_response :not_found assert_template "users/no_such_user" @@ -107,20 +107,20 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest # Removing a role from a user that doesn't have it should fail assert_no_difference "UserRole.count" do - post revoke_role_path(:display_name => target_user.display_name, :role => role) + post revoke_role_path(target_user, role) end assert_redirected_to user_path(target_user) assert_equal "The user does not have role #{role}.", flash[:error] # Removing a role from a user that has it should work... assert_difference "UserRole.count", -1 do - post revoke_role_path(:display_name => super_user.display_name, :role => role) + post revoke_role_path(super_user, role) end assert_redirected_to user_path(super_user) # ...but trying a second time should fail assert_no_difference "UserRole.count" do - post revoke_role_path(:display_name => super_user.display_name, :role => role) + post revoke_role_path(super_user, role) end assert_redirected_to user_path(super_user) assert_equal "The user does not have role #{role}.", flash[:error] @@ -128,13 +128,13 @@ class UserRolesControllerTest < ActionDispatch::IntegrationTest # Revoking a non-existent role should fail assert_difference "UserRole.count", 0 do - post revoke_role_path(:display_name => target_user.display_name, :role => "no_such_role") + post revoke_role_path(target_user, "no_such_role") end assert_redirected_to user_path(target_user) assert_equal "The string `no_such_role' is not a valid role.", flash[:error] # Revoking administrator role from current user should fail - post revoke_role_path(:display_name => administrator_user.display_name, :role => "administrator") + post revoke_role_path(administrator_user, "administrator") assert_redirected_to user_path(administrator_user) assert_equal "Cannot revoke administrator role from current user.", flash[:error] end