3 class UserRolesTest < ActionDispatch::IntegrationTest
9 check_fail(:grant, :user, :moderator)
10 check_fail(:grant, :moderator_user, :moderator)
11 check_success(:grant, :administrator_user, :moderator)
15 check_fail(:revoke, :user, :moderator)
16 check_fail(:revoke, :moderator_user, :moderator)
17 # this other user doesn't have moderator role, so this fails
18 check_fail(:revoke, :administrator_user, :moderator)
23 def check_fail(action, user, role)
25 assert_response :redirect
26 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
28 assert_response :success
29 post "/login", :params => { "username" => create(user).email, "password" => "test", :referer => "/" }
30 assert_response :redirect
32 assert_response :success
34 target_user = create(:user)
35 post "/user/#{ERB::Util.u(target_user.display_name)}/role/#{role}/#{action}"
36 assert_redirected_to user_path(target_user)
41 def check_success(action, user, role)
43 assert_response :redirect
44 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
46 assert_response :success
47 post "/login", :params => { "username" => create(user).email, "password" => "test", :referer => "/" }
48 assert_response :redirect
50 assert_response :success
52 target_user = create(:user)
53 post "/user/#{ERB::Util.u(target_user.display_name)}/role/#{role}/#{action}"
54 assert_redirected_to user_path(target_user)