##
# limit selected items to one page, get ids of first item before/after the page
def get_page_items(items, includes: [], limit: 20)
+ param! :before, Integer, :min => 1
+ param! :after, Integer, :min => 1
+
id_column = "#{items.table_name}.id"
page_items = if params[:before]
items.where("#{id_column} < ?", params[:before]).order(:id => :desc)
assert_select "li.page-item.disabled span.page-link", :text => "Newer Entries", :count => 1
end
+ def test_index_invalid_paged
+ # Try some invalid paged accesses
+ %w[-1 0 fred].each do |id|
+ get diary_entries_path(:before => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+
+ get diary_entries_path(:after => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+ end
+ end
+
def test_rss
create(:language, :code => "de")
create(:diary_entry, :language_code => "en")
assert_response :not_found
end
+ def test_comments_invalid_paged
+ user = create(:user)
+
+ %w[-1 0 fred].each do |id|
+ get diary_comments_path(:display_name => user.display_name, :before => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+
+ get diary_comments_path(:display_name => user.display_name, :after => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+ end
+ end
+
def test_subscribe_page
user = create(:user)
other_user = create(:user)
assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
end
+ def test_index_invalid_paged
+ # Try some invalid paged accesses
+ %w[-1 0 fred].each do |id|
+ get traces_path(:before => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+
+ get traces_path(:after => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+ end
+ end
+
# Check the RSS feed
def test_rss
user = create(:user)
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
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
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)
check_no_page_link "Older Users"
end
+ def test_index_get_invalid_paginated
+ session_for(create(:administrator_user))
+
+ %w[-1 0 fred].each do |id|
+ get users_path(:before => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+
+ get users_path(:after => id)
+ assert_redirected_to :controller => :errors, :action => :bad_request
+ end
+ end
+
private
def check_no_page_link(name)