]> git.openstreetmap.org Git - rails.git/blob - test/integration/user_blocks_test.rb
Update tests for changes to signup form
[rails.git] / test / integration / user_blocks_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class UserBlocksTest < ActionController::IntegrationTest
4   fixtures :users, :user_blocks, :user_roles
5
6   def auth_header(user, pass)
7     {"HTTP_AUTHORIZATION" => "Basic %s" % Base64.encode64("#{user}:#{pass}")}
8   end
9
10   def test_api_blocked
11     blocked_user = users(:public_user)
12
13     get "/api/#{API_VERSION}/user/details"
14     assert_response :unauthorized
15
16     get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
17     assert_response :success
18
19     # now block the user
20     UserBlock.create({
21       :user_id => blocked_user.id,
22       :creator_id => users(:moderator_user).id,
23       :reason => "testing",
24       :ends_at => Time.now.getutc + 5.minutes
25     }, :without_protection => true)
26     get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
27     assert_response :forbidden
28   end
29
30   def test_api_revoke
31     blocked_user = users(:public_user)
32     moderator = users(:moderator_user)
33
34     block = UserBlock.create({
35       :user_id => blocked_user.id,
36       :creator_id => moderator.id,
37       :reason => "testing",
38       :ends_at => Time.now.getutc + 5.minutes
39     }, :without_protection => true)
40     get "/api/#{API_VERSION}/user/details", nil, auth_header(blocked_user.display_name, "test")
41     assert_response :forbidden
42
43     # revoke the ban
44     get '/login'
45     assert_response :success
46     post '/login', {'username' => moderator.email, 'password' => "test", :referer => "/blocks/#{block.id}/revoke"}
47     assert_response :redirect
48     follow_redirect!
49     assert_response :success
50     assert_template 'user_blocks/revoke'
51     post "/blocks/#{block.id}/revoke", {'confirm' => "yes"}
52     assert_response :redirect
53     follow_redirect!
54     assert_response :success
55     assert_template 'user_blocks/show'
56     reset!
57
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
61   end
62 end