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 :success
42 post '/login', {'username' => moderator.email, 'password' => "test", :referer => "/blocks/#{block.id}/revoke"}
43 assert_response :redirect
45 assert_response :success
46 assert_template 'user_blocks/revoke'
47 post "/blocks/#{block.id}/revoke", {'confirm' => "yes"}
48 assert_response :redirect
50 assert_response :success
51 assert_template 'user_blocks/show'
54 # access the API again. this time it should work
55 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
56 assert_response :success