X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/1b7586c9288d694b2bc443d62f3c40502868ff77..d021f7b6254185d22a8d316acf09483b15ac0361:/test/controllers/user_blocks_controller_test.rb diff --git a/test/controllers/user_blocks_controller_test.rb b/test/controllers/user_blocks_controller_test.rb index 7be619c2a..326f2335a 100644 --- a/test/controllers/user_blocks_controller_test.rb +++ b/test/controllers/user_blocks_controller_test.rb @@ -73,6 +73,24 @@ class UserBlocksControllerTest < ActionController::TestCase end end + ## + # test the index action with multiple pages + def test_index_paged + create_list(:user_block, 50) + + get :index + assert_response :success + assert_select "table#block_list", :count => 1 do + assert_select "tr", :count => 21 + end + + get :index, :params => { :page => 2 } + assert_response :success + assert_select "table#block_list", :count => 1 do + assert_select "tr", :count => 21 + end + end + ## # test the show action def test_show @@ -127,8 +145,8 @@ class UserBlocksControllerTest < ActionController::TestCase # Check that normal users can't load the block creation page get :new, :params => { :display_name => target_user.display_name } - assert_redirected_to user_blocks_path - assert_equal "You need to be a moderator to perform that action.", flash[:error] + assert_response :redirect + assert_redirected_to :controller => "errors", :action => "forbidden" # Login as a moderator session[:user] = create(:moderator_user).id @@ -147,13 +165,13 @@ class UserBlocksControllerTest < ActionController::TestCase # We should get an error if no user is specified get :new assert_response :not_found - assert_template "user/no_such_user" + assert_template "users/no_such_user" assert_select "h1", "The user does not exist" # We should get an error if the user doesn't exist get :new, :params => { :display_name => "non_existent_user" } assert_response :not_found - assert_template "user/no_such_user" + assert_template "users/no_such_user" assert_select "h1", "The user non_existent_user does not exist" end @@ -164,15 +182,15 @@ class UserBlocksControllerTest < ActionController::TestCase # Check that the block edit page requires us to login get :edit, :params => { :id => active_block.id } - assert_redirected_to login_path(:referer => edit_user_block_path(:id => active_block.id)) + assert_redirected_to login_path(:referer => edit_user_block_path(active_block)) # Login as a normal user session[:user] = create(:user).id # Check that normal users can't load the block edit page get :edit, :params => { :id => active_block.id } - assert_redirected_to user_blocks_path - assert_equal "You need to be a moderator to perform that action.", flash[:error] + assert_response :redirect + assert_redirected_to :controller => "errors", :action => "forbidden" # Login as a moderator session[:user] = create(:moderator_user).id @@ -214,7 +232,8 @@ class UserBlocksControllerTest < ActionController::TestCase # Check that normal users can't create blocks post :create - assert_response :forbidden + assert_response :redirect + assert_redirected_to :controller => "errors", :action => "forbidden" # Login as a moderator session[:user] = moderator_user.id @@ -250,13 +269,13 @@ class UserBlocksControllerTest < ActionController::TestCase # We should get an error if no user is specified post :create assert_response :not_found - assert_template "user/no_such_user" + assert_template "users/no_such_user" assert_select "h1", "The user does not exist" # We should get an error if the user doesn't exist post :create, :params => { :display_name => "non_existent_user" } assert_response :not_found - assert_template "user/no_such_user" + assert_template "users/no_such_user" assert_select "h1", "The user non_existent_user does not exist" end @@ -276,7 +295,8 @@ class UserBlocksControllerTest < ActionController::TestCase # Check that normal users can't update blocks put :update, :params => { :id => active_block.id } - assert_response :forbidden + assert_response :redirect + assert_redirected_to :controller => "errors", :action => "forbidden" # Login as the wrong moderator session[:user] = second_moderator_user.id @@ -288,7 +308,7 @@ class UserBlocksControllerTest < ActionController::TestCase :user_block_period => "12", :user_block => { :needs_view => true, :reason => "Vandalism" } } end - assert_redirected_to edit_user_block_path(:id => active_block.id) + assert_redirected_to edit_user_block_path(active_block) assert_equal "Only the moderator who created this block can edit it.", flash[:error] # Login as the correct moderator @@ -300,7 +320,7 @@ class UserBlocksControllerTest < ActionController::TestCase :params => { :id => active_block.id, :user_block_period => "99" } end - assert_redirected_to edit_user_block_path(:id => active_block.id) + assert_redirected_to edit_user_block_path(active_block) assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error] # Check that updating a block works @@ -310,7 +330,7 @@ class UserBlocksControllerTest < ActionController::TestCase :user_block_period => "12", :user_block => { :needs_view => true, :reason => "Vandalism" } } end - assert_redirected_to user_block_path(:id => active_block.id) + assert_redirected_to user_block_path(active_block) assert_equal "Block updated.", flash[:notice] b = UserBlock.find(active_block.id) assert_in_delta Time.now, b.updated_at, 1 @@ -343,8 +363,8 @@ class UserBlocksControllerTest < ActionController::TestCase # Check that normal users can't load the block revoke page get :revoke, :params => { :id => active_block.id } - assert_redirected_to user_blocks_path - assert_equal "You need to be a moderator to perform that action.", flash[:error] + assert_response :redirect + assert_redirected_to :controller => "errors", :action => "forbidden" # Login as a moderator session[:user] = create(:moderator_user).id @@ -360,7 +380,7 @@ class UserBlocksControllerTest < ActionController::TestCase # Check that revoking a block works post :revoke, :params => { :id => active_block.id, :confirm => true } - assert_redirected_to user_block_path(:id => active_block.id) + assert_redirected_to user_block_path(active_block) b = UserBlock.find(active_block.id) assert_in_delta Time.now, b.ends_at, 1 @@ -394,7 +414,7 @@ class UserBlocksControllerTest < ActionController::TestCase # Asking for a list of blocks with a bogus user name should fail get :blocks_on, :params => { :display_name => "non_existent_user" } assert_response :not_found - assert_template "user/no_such_user" + assert_template "users/no_such_user" assert_select "h1", "The user non_existent_user does not exist" # Check the list of blocks for a user that has never been blocked @@ -421,6 +441,25 @@ class UserBlocksControllerTest < ActionController::TestCase end end + ## + # test the blocks_on action with multiple pages + def test_blocks_on_paged + user = create(:user) + create_list(:user_block, 50, :user => user) + + get :blocks_on, :params => { :display_name => user.display_name } + assert_response :success + assert_select "table#block_list", :count => 1 do + assert_select "tr", :count => 21 + end + + get :blocks_on, :params => { :display_name => user.display_name, :page => 2 } + assert_response :success + assert_select "table#block_list", :count => 1 do + assert_select "tr", :count => 21 + end + end + ## # test the blocks_by action def test_blocks_by @@ -439,7 +478,7 @@ class UserBlocksControllerTest < ActionController::TestCase # Asking for a list of blocks with a bogus user name should fail get :blocks_by, :params => { :display_name => "non_existent_user" } assert_response :not_found - assert_template "user/no_such_user" + assert_template "users/no_such_user" assert_select "h1", "The user non_existent_user does not exist" # Check the list of blocks given by one moderator @@ -465,4 +504,23 @@ class UserBlocksControllerTest < ActionController::TestCase assert_select "table#block_list", false assert_select "p", "#{normal_user.display_name} has not made any blocks yet." end + + ## + # test the blocks_by action with multiple pages + def test_blocks_by_paged + user = create(:moderator_user) + create_list(:user_block, 50, :creator => user) + + get :blocks_by, :params => { :display_name => user.display_name } + assert_response :success + assert_select "table#block_list", :count => 1 do + assert_select "tr", :count => 21 + end + + get :blocks_by, :params => { :display_name => user.display_name, :page => 2 } + assert_response :success + assert_select "table#block_list", :count => 1 do + assert_select "tr", :count => 21 + end + end end