3 class UserRolesTest < ActionDispatch::IntegrationTest
4 fixtures :users, :user_roles
11 check_fail(:grant, :public_user, :moderator)
12 check_fail(:grant, :moderator_user, :moderator)
13 check_success(:grant, :administrator_user, :moderator)
17 check_fail(:revoke, :public_user, :moderator)
18 check_fail(:revoke, :moderator_user, :moderator)
19 # this other user doesn't have moderator role, so this fails
20 check_fail(:revoke, :administrator_user, :moderator)
25 def check_fail(action, user, role)
27 assert_response :redirect
28 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
30 assert_response :success
31 post "/login", "username" => users(user).email, "password" => "test", :referer => "/"
32 assert_response :redirect
34 assert_response :success
36 post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
37 assert_redirected_to :controller => "user", :action => "view", :display_name => users(:second_public_user).display_name
42 def check_success(action, user, role)
44 assert_response :redirect
45 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
47 assert_response :success
48 post "/login", "username" => users(user).email, "password" => "test", :referer => "/"
49 assert_response :redirect
51 assert_response :success
53 post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
54 assert_redirected_to :controller => "user", :action => "view", :display_name => users(:second_public_user).display_name