summaryrefslogtreecommitdiff
path: root/vendor/plugins/will_paginate/test/collection_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/plugins/will_paginate/test/collection_test.rb')
-rw-r--r--vendor/plugins/will_paginate/test/collection_test.rb143
1 files changed, 0 insertions, 143 deletions
diff --git a/vendor/plugins/will_paginate/test/collection_test.rb b/vendor/plugins/will_paginate/test/collection_test.rb
deleted file mode 100644
index a9336bb..0000000
--- a/vendor/plugins/will_paginate/test/collection_test.rb
+++ /dev/null
@@ -1,143 +0,0 @@
1require 'helper'
2require 'will_paginate/array'
3
4class ArrayPaginationTest < Test::Unit::TestCase
5
6 def setup ; end
7
8 def test_simple
9 collection = ('a'..'e').to_a
10
11 [{ :page => 1, :per_page => 3, :expected => %w( a b c ) },
12 { :page => 2, :per_page => 3, :expected => %w( d e ) },
13 { :page => 1, :per_page => 5, :expected => %w( a b c d e ) },
14 { :page => 3, :per_page => 5, :expected => [] },
15 ].
16 each do |conditions|
17 expected = conditions.delete :expected
18 assert_equal expected, collection.paginate(conditions)
19 end
20 end
21
22 def test_defaults
23 result = (1..50).to_a.paginate
24 assert_equal 1, result.current_page
25 assert_equal 30, result.size
26 end
27
28 def test_deprecated_api
29 assert_raise(ArgumentError) { [].paginate(2) }
30 assert_raise(ArgumentError) { [].paginate(2, 10) }
31 end
32
33 def test_total_entries_has_precedence
34 result = %w(a b c).paginate :total_entries => 5
35 assert_equal 5, result.total_entries
36 end
37
38 def test_argument_error_with_params_and_another_argument
39 assert_raise ArgumentError do
40 [].paginate({}, 5)
41 end
42 end
43
44 def test_paginated_collection
45 entries = %w(a b c)
46 collection = create(2, 3, 10) do |pager|
47 assert_equal entries, pager.replace(entries)
48 end
49
50 assert_equal entries, collection
51 assert_respond_to_all collection, %w(total_pages each offset size current_page per_page total_entries)
52 assert_kind_of Array, collection
53 assert_instance_of Array, collection.entries
54 assert_equal 3, collection.offset
55 assert_equal 4, collection.total_pages
56 assert !collection.out_of_bounds?
57 end
58
59 def test_previous_next_pages
60 collection = create(1, 1, 3)
61 assert_nil collection.previous_page
62 assert_equal 2, collection.next_page
63
64 collection = create(2, 1, 3)
65 assert_equal 1, collection.previous_page
66 assert_equal 3, collection.next_page
67
68 collection = create(3, 1, 3)
69 assert_equal 2, collection.previous_page
70 assert_nil collection.next_page
71 end
72
73 def test_out_of_bounds
74 entries = create(2, 3, 2){}
75 assert entries.out_of_bounds?
76
77 entries = create(1, 3, 2){}
78 assert !entries.out_of_bounds?
79 end
80
81 def test_guessing_total_count
82 entries = create do |pager|
83 # collection is shorter than limit
84 pager.replace array
85 end
86 assert_equal 8, entries.total_entries
87
88 entries = create(2, 5, 10) do |pager|
89 # collection is shorter than limit, but we have an explicit count
90 pager.replace array
91 end
92 assert_equal 10, entries.total_entries
93
94 entries = create do |pager|
95 # collection is the same as limit; we can't guess
96 pager.replace array(5)
97 end
98 assert_equal nil, entries.total_entries
99
100 entries = create do |pager|
101 # collection is empty; we can't guess
102 pager.replace array(0)
103 end
104 assert_equal nil, entries.total_entries
105
106 entries = create(1) do |pager|
107 # collection is empty and we're on page 1,
108 # so the whole thing must be empty, too
109 pager.replace array(0)
110 end
111 assert_equal 0, entries.total_entries
112 end
113
114 def test_invalid_page
115 bad_inputs = [0, -1, nil, '', 'Schnitzel']
116
117 bad_inputs.each do |bad|
118 assert_raise(WillPaginate::InvalidPage) { create bad }
119 end
120 end
121
122 def test_invalid_per_page_setting
123 assert_raise(ArgumentError) { create(1, -1) }
124 end
125
126 def test_page_count_was_removed
127 assert_raise(NoMethodError) { create.page_count }
128 # It's `total_pages` now.
129 end
130
131 private
132 def create(page = 2, limit = 5, total = nil, &block)
133 if block_given?
134 WillPaginate::Collection.create(page, limit, total, &block)
135 else
136 WillPaginate::Collection.new(page, limit, total)
137 end
138 end
139
140 def array(size = 3)
141 Array.new(size)
142 end
143end