public
Rubygem
Fork of mislav/will_paginate
Description: Most awesome pagination solution for Rails
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/chriseppstein/will_paginate.git
Search Repo:
big refactoring in view tests; rewrite most of them in much nicer way to 
test/view_test.rb
mislav (author)
Sun Apr 06 12:40:59 -0700 2008
commit  efe2c81322301bc0b1b62e211f199b7959b0dca3
tree    526996b892969741d2df0fe1f56b5c241fd84b53
parent  b00a298c02df8ab68e18bc107e41ce35533e1af1
...
21
22
23
24
 
25
26
27
...
21
22
23
 
24
25
26
27
0
@@ -21,7 +21,7 @@ module WillPaginate
0
       require 'will_paginate/view_helpers'
0
       ActionView::Base.class_eval { include ViewHelpers }
0
 
0
- if ActionController::Base.respond_to? :rescue_responses
0
+ if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
0
         ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
0
       end
0
     end
...
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0
@@ -13,6 +13,18 @@ class Test::Unit::TestCase
0
       [method.to_s, method.to_sym].each { |m| assert_respond_to object, m }
0
     end
0
   end
0
+
0
+ def collect_deprecations
0
+ old_behavior = WillPaginate::Deprecation.behavior
0
+ deprecations = []
0
+ WillPaginate::Deprecation.behavior = Proc.new do |message, callstack|
0
+ deprecations << message
0
+ end
0
+ result = yield
0
+ [result, deprecations]
0
+ ensure
0
+ WillPaginate::Deprecation.behavior = old_behavior
0
+ end
0
 end
0
 
0
 # Wrap tests that use Mocha and skip if unavailable.
...
1
2
3
4
5
6
7
8
9
10
11
12
 
13
14
15
...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
...
1
 
 
 
 
 
 
 
 
 
 
 
2
3
4
5
...
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
...
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
...
81
82
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
85
86
...
108
109
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
0
@@ -1,15 +1,5 @@
0
 require 'helper'
0
-require 'action_controller'
0
-require 'lib/html_inner_text'
0
-
0
-ActionController::Routing::Routes.draw do |map|
0
- map.connect ':controller/:action/:id'
0
-end
0
-
0
-ActionController::Base.perform_caching = false
0
-
0
-require 'will_paginate'
0
-WillPaginate.enable_actionpack
0
+require 'lib/view_test_process'
0
 
0
 class PaginationTest < Test::Unit::TestCase
0
   
0
@@ -25,24 +15,6 @@ class PaginationTest < Test::Unit::TestCase
0
       render :inline => '<%= will_paginate @developers, @options %>'
0
     end
0
 
0
- def guess_collection_name
0
- @developers = session[:wp]
0
- @options = session[:wp_options]
0
-
0
- render :inline => '<%= will_paginate @options %>'
0
- end
0
-
0
- def paginated_section
0
- @developers = session[:wp]
0
- @options = session[:wp_options]
0
-
0
- render :inline => <<-ERB
0
- <% paginated_section @options do %>
0
- <%= content_tag :div, '', :id => "developers" %>
0
- <% end %>
0
- ERB
0
- end
0
-
0
     protected
0
       def rescue_errors(e) raise e end
0
       def rescue_action(e) raise e end
0
@@ -54,66 +26,6 @@ class PaginationTest < Test::Unit::TestCase
0
     @response = ActionController::TestResponse.new
0
     super
0
   end
0
-
0
- def test_will_paginate
0
- get :list_developers
0
-
0
- entries = assigns :developers
0
- assert entries
0
- assert_equal 4, entries.size
0
-
0
- assert_select 'div.pagination', 1, 'no main DIV' do |pagination|
0
- assert_select 'a[href]', 3 do |elements|
0
- validate_page_numbers [2,3,2], elements
0
- assert_select elements.last, ':last-child', "Next &raquo;"
0
- end
0
- assert_select 'span', 2
0
- assert_select 'span.disabled:first-child', "&laquo; Previous"
0
- assert_select 'span.current', entries.current_page.to_s
0
- assert_equal '&laquo; Previous 1 2 3 Next &raquo;', pagination.first.inner_text
0
- end
0
- end
0
-
0
- def test_will_paginate_with_options
0
- get :list_developers, { :page => 2 }, :wp => {
0
- :class => 'will_paginate', :prev_label => 'Prev', :next_label => 'Next'
0
- }
0
- assert_response :success
0
-
0
- entries = assigns :developers
0
- assert entries
0
- assert_equal 4, entries.size
0
-
0
- assert_select 'div.will_paginate', 1, 'no main DIV' do
0
- assert_select 'a[href]', 4 do |elements|
0
- validate_page_numbers [1,1,3,3], elements
0
- # test rel attribute values:
0
- assert_select elements[1], 'a', '1' do |link|
0
- assert_equal 'prev start', link.first['rel']
0
- end
0
- assert_select elements.first, 'a', "Prev" do |link|
0
- assert_equal 'prev start', link.first['rel']
0
- end
0
- assert_select elements.last, 'a', "Next" do |link|
0
- assert_equal 'next', link.first['rel']
0
- end
0
- end
0
- assert_select 'span.current', entries.current_page.to_s
0
- end
0
- end
0
-
0
- def test_will_paginate_without_container
0
- get :list_developers, {}, :wp => { :container => false }
0
- assert_select 'div.pagination', 0, 'no main DIV'
0
- assert_select 'a[href]', 3
0
- end
0
-
0
- def test_will_paginate_without_page_links
0
- get :list_developers, { :page => 2 }, :wp => { :page_links => false }
0
- assert_select 'a[href]', 2 do |elements|
0
- validate_page_numbers [1,3], elements
0
- end
0
- end
0
   
0
   def test_will_paginate_preserves_parameters_on_get
0
     get :list_developers, :foo => { :bar => 'baz' }
0
@@ -169,110 +81,6 @@ class PaginationTest < Test::Unit::TestCase
0
       assert_select 'span.current', entries.current_page.to_s
0
     end
0
   end
0
-
0
- def test_will_paginate_windows
0
- get :list_developers, { :page => 6, :per_page => 1 }, :wp => { :inner_window => 1 }
0
- assert_response :success
0
-
0
- entries = assigns :developers
0
- assert entries
0
- assert_equal 1, entries.size
0
-
0
- assert_select 'div.pagination', 1, 'no main DIV' do |pagination|
0
- assert_select 'a[href]', 8 do |elements|
0
- validate_page_numbers [5,1,2,5,7,10,11,7], elements
0
- assert_select elements.first, 'a', "&laquo; Previous"
0
- assert_select elements.last, 'a', "Next &raquo;"
0
- end
0
- assert_select 'span.current', entries.current_page.to_s
0
- assert_equal '&laquo; Previous 1 2 &hellip; 5 6 7 &hellip; 10 11 Next &raquo;', pagination.first.inner_text
0
- end
0
- end
0
-
0
- def test_will_paginate_eliminates_small_gaps
0
- get :list_developers, { :page => 6, :per_page => 1 }, :wp => { :inner_window => 2 }
0
- assert_response :success
0
-
0
- assert_select 'div.pagination', 1, 'no main DIV' do
0
- assert_select 'a[href]', 12 do |elements|
0
- validate_page_numbers [5,1,2,3,4,5,7,8,9,10,11,7], elements
0
- end
0
- end
0
- end
0
-
0
- def test_no_pagination
0
- get :list_developers, :per_page => 12
0
- entries = assigns :developers
0
- assert_equal 1, entries.total_pages
0
- assert_equal 11, entries.size
0
-
0
- assert_equal '', @response.body
0
- end
0
-
0
- def test_faulty_input_raises_error
0
- assert_raise WillPaginate::InvalidPage do
0
- get :list_developers, :page => 'foo'
0
- end
0
- end
0
-
0
- class LegacyCollection < WillPaginate::Collection
0
- alias :page_count :total_pages
0
- undef :total_pages
0
- end
0
-
0
- uses_mocha 'helper internals' do
0
- def test_collection_name_can_be_guessed
0
- collection = mock
0
- collection.expects(:total_pages).returns(1)
0
- get :guess_collection_name, {}, :wp => collection
0
- end
0
-
0
- def test_deprecation_notices_with_page_count
0
- collection = LegacyCollection.new 1, 1, 2
0
-
0
- assert_deprecated collection.class.name do
0
- get :guess_collection_name, {}, :wp => collection
0
- end
0
- end
0
- end
0
-
0
- def test_inferred_collection_name_raises_error_when_nil
0
- ex = assert_raise ArgumentError do
0
- get :guess_collection_name, {}, :wp => nil
0
- end
0
- assert ex.message.include?('@developers')
0
- end
0
-
0
- def test_setting_id_for_container
0
- get :list_developers
0
- assert_select 'div.pagination', 1 do |div|
0
- assert_nil div.first['id']
0
- end
0
- # magic ID
0
- get :list_developers, {}, :wp => { :id => true }
0
- assert_select 'div.pagination', 1 do |div|
0
- assert_equal 'fixnums_pagination', div.first['id']
0
- end
0
- # explicit ID
0
- get :list_developers, {}, :wp => { :id => 'custom_id' }
0
- assert_select 'div.pagination', 1 do |div|
0
- assert_equal 'custom_id', div.first['id']
0
- end
0
- end
0
-
0
- if ActionController::Base.respond_to? :rescue_responses
0
- def test_rescue_response_hook_presence
0
- assert_equal :not_found,
0
- DevelopersController.rescue_responses['WillPaginate::InvalidPage']
0
- end
0
- end
0
-
0
- def test_paginated_section
0
- collection = WillPaginate::Collection.new 1, 1, 2
0
- get :paginated_section, {}, :wp => collection, :wp_options => { :class => 'will_paginate' }
0
- assert_select 'div.will_paginate', 2
0
- assert_select 'div.will_paginate + div#developers', 1
0
- end
0
   
0
 protected
0
 
0
@@ -300,31 +108,4 @@ protected
0
       end
0
     end
0
   end
0
-
0
- def collect_deprecations
0
- old_behavior = WillPaginate::Deprecation.behavior
0
- deprecations = []
0
- WillPaginate::Deprecation.behavior = Proc.new do |message, callstack|
0
- deprecations << message
0
- end
0
- result = yield
0
- [result, deprecations]
0
- ensure
0
- WillPaginate::Deprecation.behavior = old_behavior
0
- end
0
-end
0
-
0
-class ViewHelpersTest < Test::Unit::TestCase
0
- include WillPaginate::ViewHelpers
0
-
0
- def test_page_entries_info
0
- arr = ('a'..'z').to_a
0
- collection = arr.paginate :page => 2, :per_page => 5
0
- assert_equal %{Displaying entries <b>6&nbsp;-&nbsp;10</b> of <b>26</b> in total},
0
- page_entries_info(collection)
0
-
0
- collection = arr.paginate :page => 7, :per_page => 4
0
- assert_equal %{Displaying entries <b>25&nbsp;-&nbsp;26</b> of <b>26</b> in total},
0
- page_entries_info(collection)
0
- end
0
 end

Comments

    No one has commented yet.