Mercurial > hg > soundsoftware-site
comparison test/unit/lib/redmine/pagination_test.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../../../test_helper', __FILE__) | |
19 | |
20 class Redmine::PaginationTest < ActiveSupport::TestCase | |
21 | |
22 def setup | |
23 @klass = Redmine::Pagination::Paginator | |
24 end | |
25 | |
26 def test_count_is_zero | |
27 p = @klass.new 0, 10, 1 | |
28 | |
29 assert_equal 0, p.offset | |
30 assert_equal 10, p.per_page | |
31 %w(first_page previous_page next_page last_page).each do |method| | |
32 assert_nil p.send(method), "#{method} was not nil" | |
33 end | |
34 assert_equal 0, p.first_item | |
35 assert_equal 0, p.last_item | |
36 assert_equal [], p.linked_pages | |
37 end | |
38 | |
39 def test_count_is_less_than_per_page | |
40 p = @klass.new 7, 10, 1 | |
41 | |
42 assert_equal 0, p.offset | |
43 assert_equal 10, p.per_page | |
44 assert_equal 1, p.first_page | |
45 assert_nil p.previous_page | |
46 assert_nil p.next_page | |
47 assert_equal 1, p.last_page | |
48 assert_equal 1, p.first_item | |
49 assert_equal 7, p.last_item | |
50 assert_equal [], p.linked_pages | |
51 end | |
52 | |
53 def test_count_is_equal_to_per_page | |
54 p = @klass.new 10, 10, 1 | |
55 | |
56 assert_equal 0, p.offset | |
57 assert_equal 10, p.per_page | |
58 assert_equal 1, p.first_page | |
59 assert_nil p.previous_page | |
60 assert_nil p.next_page | |
61 assert_equal 1, p.last_page | |
62 assert_equal 1, p.first_item | |
63 assert_equal 10, p.last_item | |
64 assert_equal [], p.linked_pages | |
65 end | |
66 | |
67 def test_2_pages | |
68 p = @klass.new 16, 10, 1 | |
69 | |
70 assert_equal 0, p.offset | |
71 assert_equal 10, p.per_page | |
72 assert_equal 1, p.first_page | |
73 assert_nil p.previous_page | |
74 assert_equal 2, p.next_page | |
75 assert_equal 2, p.last_page | |
76 assert_equal 1, p.first_item | |
77 assert_equal 10, p.last_item | |
78 assert_equal [1, 2], p.linked_pages | |
79 end | |
80 | |
81 def test_many_pages | |
82 p = @klass.new 155, 10, 1 | |
83 | |
84 assert_equal 0, p.offset | |
85 assert_equal 10, p.per_page | |
86 assert_equal 1, p.first_page | |
87 assert_nil p.previous_page | |
88 assert_equal 2, p.next_page | |
89 assert_equal 16, p.last_page | |
90 assert_equal 1, p.first_item | |
91 assert_equal 10, p.last_item | |
92 assert_equal [1, 2, 3, 16], p.linked_pages | |
93 end | |
94 end |