1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserBlocksTest < ActionController::IntegrationTest
4 fixtures :users, :user_blocks, :user_roles
6 def auth_header(user, pass)
7 {"HTTP_AUTHORIZATION" => "Basic %s" % Base64.encode64("#{user}:#{pass}")}
11 blocked_user = users(:public_user)
13 get "/api/#{API_VERSION}/user/details"
14 assert_response :unauthorized
16 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
17 assert_response :success
20 UserBlock.create(:user_id => blocked_user.id,
21 :creator_id => users(:moderator_user).id,
23 :ends_at => Time.now.getutc + 5.minutes)
24 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
25 assert_response :forbidden
29 blocked_user = users(:public_user)
30 moderator = users(:moderator_user)
32 block = UserBlock.create(:user_id => blocked_user.id,
33 :creator_id => moderator.id,
35 :ends_at => Time.now.getutc + 5.minutes)
36 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
37 assert_response :forbidden
41 assert_response :redirect
42 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
44 assert_response :success
45 post '/login', {'user[email]' => moderator.email, 'user[password]' => "test", :referer => "/blocks/#{block.id}/revoke"}
46 assert_response :redirect
48 assert_response :success
49 assert_template 'user_blocks/revoke'
50 post "/blocks/#{block.id}/revoke", {'confirm' => "yes"}
51 assert_response :redirect
53 assert_response :success
54 assert_template 'user_blocks/show'
57 # access the API again. this time it should work
58 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
59 assert_response :success