3 class UserBlocksTest < ActionDispatch::IntegrationTest
4 fixtures :users, :user_blocks, :user_roles
6 def auth_header(user, pass)
7 { "HTTP_AUTHORIZATION" => format("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
21 :user_id => blocked_user.id,
22 :creator_id => users(:moderator_user).id,
24 :ends_at => Time.now.getutc + 5.minutes
26 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
27 assert_response :forbidden
31 blocked_user = users(:public_user)
32 moderator = users(:moderator_user)
34 block = UserBlock.create(
35 :user_id => blocked_user.id,
36 :creator_id => moderator.id,
38 :ends_at => Time.now.getutc + 5.minutes
40 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
41 assert_response :forbidden
45 assert_response :success
46 post "/login", "username" => moderator.email, "password" => "test", :referer => "/blocks/#{block.id}/revoke"
47 assert_response :redirect
49 assert_response :success
50 assert_template "user_blocks/revoke"
51 post "/blocks/#{block.id}/revoke", "confirm" => "yes"
52 assert_response :redirect
54 assert_response :success
55 assert_template "user_blocks/show"
58 # access the API again. this time it should work
59 get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
60 assert_response :success