]> git.openstreetmap.org Git - rails.git/blob - test/controllers/concerns/pagination_methods_test.rb
Merge pull request #7191 from CommanderStorm/fix-attribution-listener-leak
[rails.git] / test / controllers / concerns / pagination_methods_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class PaginationMethodsTest < ActiveSupport::TestCase
6   include PaginationMethods
7
8   test "#get_page_items can sort any records with compatible ids" do
9     n1 = create(:changeset_comment_notification)
10     n2 = create(:gpx_import_failure_notification)
11     items = Noticed::Notification.all
12
13     paged_items = get_page_items(items)
14
15     assert_equal [n2, n1], paged_items.items
16   end
17
18   test "#get_page_items can sort records by an arbitrary column" do
19     create(:user, :display_name => "Alba")
20     create(:user, :display_name => "Calle")
21     create(:user, :display_name => "Berhane")
22     items = User.all
23
24     paged_items = get_page_items(items, :cursor_column => :display_name)
25     actual_names = paged_items.items.map(&:display_name)
26     assert_equal %w[Calle Berhane Alba], actual_names
27   end
28
29   private
30
31   #
32   # Methods below are stubs for controller methods
33   # that the PaginationMethods concern requires to work.
34   #
35
36   def param!(*)
37     nil
38   end
39
40   def params
41     {}
42   end
43 end