X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/134f9e2df1b3d3c797e7fbb1cf2de3d76a018330..eb0f95b6aeec77058395975d7e9b0aba076d71c1:/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 a7ab02c75..b6aaf4ca8 100644 --- a/test/controllers/user_blocks_controller_test.rb +++ b/test/controllers/user_blocks_controller_test.rb @@ -115,6 +115,18 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest check_no_page_link "Older Blocks" end + ## + # test the index action with invalid pages + def test_index_invalid_paged + %w[-1 0 fred].each do |id| + get user_blocks_path(:before => id) + assert_redirected_to :controller => :errors, :action => :bad_request + + get user_blocks_path(:after => id) + assert_redirected_to :controller => :errors, :action => :bad_request + end + end + ## # test the show action def test_show @@ -232,6 +244,34 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest assert_select "p", "Sorry, the user block with ID 99999 could not be found." end + ## + # test the edit action when the remaining block duration doesn't match the available select options + def test_edit_duration + moderator_user = create(:moderator_user) + + freeze_time do + active_block = create(:user_block, :creator => moderator_user, :ends_at => Time.now.utc + 96.hours) + + session_for(moderator_user) + get edit_user_block_path(active_block) + + assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do + assert_select "select#user_block_period", :count => 1 do + assert_select "option[value='96'][selected]", :count => 1 + end + end + + travel 2.hours + get edit_user_block_path(active_block) + + assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do + assert_select "select#user_block_period", :count => 1 do + assert_select "option[value='96'][selected]", :count => 1 + end + end + end + end + ## # test the create action def test_create @@ -560,6 +600,20 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest check_no_page_link "Older Blocks" end + ## + # test the blocks_on action with invalid pages + def test_blocks_on_invalid_paged + user = create(:user) + + %w[-1 0 fred].each do |id| + get user_blocks_on_path(user, :before => id) + assert_redirected_to :controller => :errors, :action => :bad_request + + get user_blocks_on_path(user, :after => id) + assert_redirected_to :controller => :errors, :action => :bad_request + end + end + ## # test the blocks_by action def test_blocks_by @@ -628,6 +682,20 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest check_no_page_link "Older Blocks" end + ## + # test the blocks_by action with invalid pages + def test_blocks_by_invalid_paged + user = create(:moderator_user) + + %w[-1 0 fred].each do |id| + get user_blocks_by_path(user, :before => id) + assert_redirected_to :controller => :errors, :action => :bad_request + + get user_blocks_by_path(user, :after => id) + assert_redirected_to :controller => :errors, :action => :bad_request + end + end + private def check_user_blocks_table(user_blocks)