1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserRolesControllerTest < ActionController::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)
19 def check_fail(action, user, role)
21 assert_response :redirect
22 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
24 assert_response :success
25 post '/login', {'username' => users(user).email, 'password' => "test", :referer => "/"}
26 assert_response :redirect
28 assert_response :success
30 get "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
31 assert_response :redirect
32 assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name
37 def check_success(action, user, role)
39 assert_response :redirect
40 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
42 assert_response :success
43 post '/login', {'username' => users(user).email, 'password' => "test", :referer => "/"}
44 assert_response :redirect
46 assert_response :success
48 get "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
49 assert_response :success
50 post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}", {:confirm => "yes", :nonce => session[:nonce]}
51 assert_response :redirect
52 assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name