Add validation for before/after parameters to pagination concern

This commit is contained in:
Tom Hughes 2024-04-11 09:13:56 +01:00
parent 5d887a37bf
commit e3c43e4a1a
5 changed files with 89 additions and 0 deletions

View file

@ -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
@ -560,6 +572,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 +654,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)