X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/49c3af4a32b38eaebdd9f819bf288a9b80495c12..870e9e41e3c2b23b8b5e6730d91ea9ad1c89463d:/test/controllers/user_roles_controller_test.rb diff --git a/test/controllers/user_roles_controller_test.rb b/test/controllers/user_roles_controller_test.rb index ef1a57cbe..f73fc9056 100644 --- a/test/controllers/user_roles_controller_test.rb +++ b/test/controllers/user_roles_controller_test.rb @@ -20,21 +20,17 @@ class UserRolesControllerTest < ActionController::TestCase target_user = create(:user) normal_user = create(:user) administrator_user = create(:administrator_user) - # Create a super user which has all known roles - super_user = create(:user) - UserRole::ALL_ROLES.each do |role| - create(:user_role, :user => super_user, :granter => administrator_user, :role => role) - end + super_user = create(:super_user) # Granting should fail when not logged in - post :grant, :display_name => target_user.display_name, :role => "moderator" + post :grant, :params => { :display_name => target_user.display_name, :role => "moderator" } assert_response :forbidden # Login as an unprivileged user session[:user] = normal_user.id # Granting should still fail - post :grant, :display_name => target_user.display_name, :role => "moderator" + post :grant, :params => { :display_name => target_user.display_name, :role => "moderator" } assert_redirected_to user_path(target_user.display_name) assert_equal "Only administrators can perform user role management, and you are not an administrator.", flash[:error] @@ -44,7 +40,7 @@ class UserRolesControllerTest < ActionController::TestCase UserRole::ALL_ROLES.each do |role| # Granting a role to a non-existent user should fail assert_difference "UserRole.count", 0 do - post :grant, :display_name => "non_existent_user", :role => role + post :grant, :params => { :display_name => "non_existent_user", :role => role } end assert_response :not_found assert_template "user/no_such_user" @@ -52,20 +48,20 @@ class UserRolesControllerTest < ActionController::TestCase # Granting a role to a user that already has it should fail assert_no_difference "UserRole.count" do - post :grant, :display_name => super_user.display_name, :role => role + post :grant, :params => { :display_name => super_user.display_name, :role => role } end assert_redirected_to user_path(super_user.display_name) 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, :display_name => target_user.display_name, :role => role + post :grant, :params => { :display_name => target_user.display_name, :role => role } end assert_redirected_to user_path(target_user.display_name) # ...but trying a second time should fail assert_no_difference "UserRole.count" do - post :grant, :display_name => target_user.display_name, :role => role + post :grant, :params => { :display_name => target_user.display_name, :role => role } end assert_redirected_to user_path(target_user.display_name) assert_equal "The user already has role #{role}.", flash[:error] @@ -73,7 +69,7 @@ class UserRolesControllerTest < ActionController::TestCase # Granting a non-existent role should fail assert_difference "UserRole.count", 0 do - post :grant, :display_name => target_user.display_name, :role => "no_such_role" + post :grant, :params => { :display_name => target_user.display_name, :role => "no_such_role" } end assert_redirected_to user_path(target_user.display_name) assert_equal "The string `no_such_role' is not a valid role.", flash[:error] @@ -85,21 +81,17 @@ class UserRolesControllerTest < ActionController::TestCase target_user = create(:user) normal_user = create(:user) administrator_user = create(:administrator_user) - # Create a super user which has all known roles - super_user = create(:user) - UserRole::ALL_ROLES.each do |role| - create(:user_role, :user => super_user, :granter => administrator_user, :role => role) - end + super_user = create(:super_user) # Revoking should fail when not logged in - post :revoke, :display_name => target_user.display_name, :role => "moderator" + post :revoke, :params => { :display_name => target_user.display_name, :role => "moderator" } assert_response :forbidden # Login as an unprivileged user session[:user] = normal_user.id # Revoking should still fail - post :revoke, :display_name => target_user.display_name, :role => "moderator" + post :revoke, :params => { :display_name => target_user.display_name, :role => "moderator" } assert_redirected_to user_path(target_user.display_name) assert_equal "Only administrators can perform user role management, and you are not an administrator.", flash[:error] @@ -109,7 +101,7 @@ class UserRolesControllerTest < ActionController::TestCase UserRole::ALL_ROLES.each do |role| # Removing a role from a non-existent user should fail assert_difference "UserRole.count", 0 do - post :revoke, :display_name => "non_existent_user", :role => role + post :revoke, :params => { :display_name => "non_existent_user", :role => role } end assert_response :not_found assert_template "user/no_such_user" @@ -117,20 +109,20 @@ class UserRolesControllerTest < ActionController::TestCase # Removing a role from a user that doesn't have it should fail assert_no_difference "UserRole.count" do - post :revoke, :display_name => target_user.display_name, :role => role + post :revoke, :params => { :display_name => target_user.display_name, :role => role } end assert_redirected_to user_path(target_user.display_name) 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, :display_name => super_user.display_name, :role => role + post :revoke, :params => { :display_name => super_user.display_name, :role => role } end assert_redirected_to user_path(super_user.display_name) # ...but trying a second time should fail assert_no_difference "UserRole.count" do - post :revoke, :display_name => super_user.display_name, :role => role + post :revoke, :params => { :display_name => super_user.display_name, :role => role } end assert_redirected_to user_path(super_user.display_name) assert_equal "The user does not have role #{role}.", flash[:error] @@ -138,7 +130,7 @@ class UserRolesControllerTest < ActionController::TestCase # Revoking a non-existent role should fail assert_difference "UserRole.count", 0 do - post :revoke, :display_name => target_user.display_name, :role => "no_such_role" + post :revoke, :params => { :display_name => target_user.display_name, :role => "no_such_role" } end assert_redirected_to user_path(target_user.display_name) assert_equal "The string `no_such_role' is not a valid role.", flash[:error]