1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserRolesTest < ActionDispatch::IntegrationTest
4 fixtures :users, :user_roles
7 check_fail(:grant, :public_user, :moderator)
8 check_fail(:grant, :moderator_user, :moderator)
9 check_success(:grant, :administrator_user, :moderator)
13 check_fail(:revoke, :public_user, :moderator)
14 check_fail(:revoke, :moderator_user, :moderator)
15 # this other user doesn't have moderator role, so this fails
16 check_fail(:revoke, :administrator_user, :moderator)
21 def check_fail(action, user, role)
23 assert_response :redirect
24 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
26 assert_response :success
27 post '/login', {'username' => users(user).email, 'password' => "test", :referer => "/"}
28 assert_response :redirect
30 assert_response :success
32 post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
33 assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name
38 def check_success(action, user, role)
40 assert_response :redirect
41 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
43 assert_response :success
44 post '/login', {'username' => users(user).email, 'password' => "test", :referer => "/"}
45 assert_response :redirect
47 assert_response :success
49 post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
50 assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name