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)
20 post '/login', {'user[email]' => users(user).email, 'user[password]' => "test", :referer => "/"}
21 assert_response :redirect
23 assert_response :success
25 get "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
26 assert_response :redirect
27 assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name
32 def check_success(action, user, role)
33 post '/login', {'user[email]' => users(user).email, 'user[password]' => "test", :referer => "/"}
34 assert_response :redirect
36 assert_response :success
38 get "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
39 assert_response :success
40 post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}", {:confirm => "yes", :nonce => session[:nonce]}
41 assert_response :redirect
42 assert_redirected_to :controller => 'user', :action => 'view', :display_name => users(:second_public_user).display_name