Added a confirmation step to the process of granting and revoking user roles.
[rails.git] / test / functional / user_roles_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class UserRolesControllerTest < ActionController::TestCase
4   fixtures :users, :user_roles
5
6   test "grant" do
7     check_forbidden(:grant, :public_user)
8     check_forbidden(:grant, :moderator_user)
9     check_success(:grant, :administrator_user)
10   end
11
12   test "revoke" do
13     check_forbidden(:revoke, :public_user)
14     check_forbidden(:revoke, :moderator_user)
15     check_success(:revoke, :administrator_user)
16   end
17
18   def check_forbidden(action, user)
19     UserRole::ALL_ROLES.each do |role|
20       u = users(user)
21       basic_authorization(u.email, "test")
22       
23       get(action, {:display_name => users(:second_public_user).display_name, :role => role}, {'user' => u.id})
24       assert_response :redirect
25       assert_redirected_to "/403.html"
26     end
27   end
28
29   def check_success(action, user)
30     UserRole::ALL_ROLES.each do |role|
31       u = users(user)
32       basic_authorization(u.email, "test")
33       
34       get(action, {:display_name => users(:second_public_user).display_name, :role => role}, {'user' => u.id})
35       assert_response :success
36     end
37   end
38 end