will_paginate 3.2.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -5
  3. data/lib/will_paginate/active_record.rb +3 -3
  4. data/lib/will_paginate/i18n.rb +3 -3
  5. data/lib/will_paginate/locale/en.yml +2 -0
  6. data/lib/will_paginate/page_number.rb +1 -2
  7. data/lib/will_paginate/railtie.rb +2 -2
  8. data/lib/will_paginate/version.rb +2 -2
  9. data/lib/will_paginate/view_helpers/action_view.rb +7 -3
  10. data/lib/will_paginate/view_helpers/link_renderer.rb +7 -5
  11. data/lib/will_paginate.rb +0 -12
  12. metadata +12 -49
  13. data/lib/will_paginate/data_mapper.rb +0 -100
  14. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  15. data/spec/collection_spec.rb +0 -139
  16. data/spec/console +0 -12
  17. data/spec/console_fixtures.rb +0 -28
  18. data/spec/database.yml +0 -29
  19. data/spec/fake_rubygems.rb +0 -18
  20. data/spec/finders/active_record_spec.rb +0 -417
  21. data/spec/finders/activerecord_test_connector.rb +0 -140
  22. data/spec/finders/data_mapper_spec.rb +0 -114
  23. data/spec/finders/data_mapper_test_connector.rb +0 -54
  24. data/spec/finders/mongoid_spec.rb +0 -145
  25. data/spec/finders/sequel_spec.rb +0 -65
  26. data/spec/finders/sequel_test_connector.rb +0 -15
  27. data/spec/fixtures/admin.rb +0 -3
  28. data/spec/fixtures/developer.rb +0 -9
  29. data/spec/fixtures/developers_projects.yml +0 -13
  30. data/spec/fixtures/project.rb +0 -13
  31. data/spec/fixtures/projects.yml +0 -6
  32. data/spec/fixtures/replies.yml +0 -29
  33. data/spec/fixtures/reply.rb +0 -8
  34. data/spec/fixtures/schema.rb +0 -38
  35. data/spec/fixtures/topic.rb +0 -8
  36. data/spec/fixtures/topics.yml +0 -30
  37. data/spec/fixtures/user.rb +0 -2
  38. data/spec/fixtures/users.yml +0 -35
  39. data/spec/matchers/deprecation_matcher.rb +0 -27
  40. data/spec/matchers/phrase_matcher.rb +0 -19
  41. data/spec/matchers/query_count_matcher.rb +0 -36
  42. data/spec/page_number_spec.rb +0 -82
  43. data/spec/per_page_spec.rb +0 -41
  44. data/spec/spec_helper.rb +0 -46
  45. data/spec/view_helpers/action_view_spec.rb +0 -480
  46. data/spec/view_helpers/base_spec.rb +0 -143
  47. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  48. data/spec/view_helpers/view_example_group.rb +0 -146
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- require 'will_paginate/per_page'
3
-
4
- describe WillPaginate::PerPage do
5
-
6
- class MyModel
7
- extend WillPaginate::PerPage
8
- end
9
-
10
- it "has the default value" do
11
- MyModel.per_page.should == 30
12
-
13
- WillPaginate.per_page = 10
14
- begin
15
- MyModel.per_page.should == 10
16
- ensure
17
- WillPaginate.per_page = 30
18
- end
19
- end
20
-
21
- it "casts values to int" do
22
- WillPaginate.per_page = '10'
23
- begin
24
- MyModel.per_page.should == 10
25
- ensure
26
- WillPaginate.per_page = 30
27
- end
28
- end
29
-
30
- it "has an explicit value" do
31
- MyModel.per_page = 12
32
- begin
33
- MyModel.per_page.should == 12
34
- subclass = Class.new(MyModel)
35
- subclass.per_page.should == 12
36
- ensure
37
- MyModel.send(:remove_instance_variable, '@per_page')
38
- end
39
- end
40
-
41
- end
data/spec/spec_helper.rb DELETED
@@ -1,46 +0,0 @@
1
- require 'rspec'
2
- require 'view_helpers/view_example_group'
3
- begin
4
- require 'ruby-debug'
5
- rescue LoadError
6
- # no debugger available
7
- end
8
-
9
- Dir[File.expand_path('../matchers/*_matcher.rb', __FILE__)].each { |matcher| require matcher }
10
-
11
- RSpec.configure do |config|
12
- config.include Module.new {
13
- protected
14
-
15
- def include_phrase(string)
16
- PhraseMatcher.new(string)
17
- end
18
-
19
- def have_deprecation(msg)
20
- DeprecationMatcher.new(msg)
21
- end
22
-
23
- def run_queries(num)
24
- QueryCountMatcher.new(num)
25
- end
26
-
27
- def ignore_deprecation
28
- ActiveSupport::Deprecation.silence { yield }
29
- end
30
-
31
- def show_queries(&block)
32
- counter = QueryCountMatcher.new(nil)
33
- counter.run block
34
- ensure
35
- queries = counter.performed_queries
36
- if queries.any?
37
- puts queries
38
- else
39
- puts "no queries"
40
- end
41
- end
42
- }
43
-
44
- config.mock_with :mocha
45
- config.backtrace_clean_patterns << /view_example_group/
46
- end
@@ -1,480 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'active_support/rescuable' # needed for Ruby 1.9.1
4
- require 'action_controller'
5
- require 'action_view'
6
- require 'will_paginate/view_helpers/action_view'
7
- require 'will_paginate/collection'
8
-
9
- Routes = ActionDispatch::Routing::RouteSet.new
10
-
11
- Routes.draw do
12
- get 'dummy/page/:page' => 'dummy#index'
13
- get 'dummy/dots/page.:page' => 'dummy#dots'
14
- get 'ibocorp(/:page)' => 'ibocorp#index',
15
- :constraints => { :page => /\d+/ }, :defaults => { :page => 1 }
16
-
17
- get 'foo/bar' => 'foo#bar'
18
- get 'baz/list' => 'baz#list'
19
- end
20
-
21
- describe WillPaginate::ActionView do
22
-
23
- before(:all) do
24
- I18n.load_path.concat WillPaginate::I18n.load_path
25
- I18n.enforce_available_locales = false
26
- end
27
-
28
- before(:each) do
29
- I18n.reload!
30
- end
31
-
32
- before(:each) do
33
- @assigns = {}
34
- @controller = DummyController.new
35
- @request = @controller.request
36
- @template = '<%= will_paginate collection, options %>'
37
- end
38
-
39
- attr_reader :assigns, :controller, :request
40
-
41
- def render(locals)
42
- lookup_context = []
43
- if defined? ActionView::LookupContext
44
- lookup_context = ActionView::LookupContext.new(lookup_context)
45
- end
46
-
47
- klass = ActionView::Base
48
- klass = klass.with_empty_template_cache if klass.respond_to?(:with_empty_template_cache)
49
- @view = klass.new(lookup_context, @assigns, @controller)
50
- @view.request = @request
51
- @view.singleton_class.send(:include, @controller._routes.url_helpers)
52
- @view.render(:inline => @template, :locals => locals)
53
- end
54
-
55
- ## basic pagination ##
56
-
57
- it "should render" do
58
- paginate do |pagination|
59
- assert_select 'a[href]', 3 do |elements|
60
- validate_page_numbers [2,3,2], elements
61
- text(elements[2]).should == 'Next →'
62
- end
63
- assert_select 'span', 1 do |spans|
64
- spans[0]['class'].should == 'previous_page disabled'
65
- text(spans[0]).should == '← Previous'
66
- end
67
- assert_select 'em.current', '1'
68
- text(pagination[0]).should == '← Previous 1 2 3 Next →'
69
- end
70
- end
71
-
72
- it "should override existing page param value" do
73
- request.params :page => 1
74
- paginate do |pagination|
75
- assert_select 'a[href]', 3 do |elements|
76
- validate_page_numbers [2,3,2], elements
77
- end
78
- end
79
- end
80
-
81
- it "should render nothing when there is only 1 page" do
82
- paginate(:per_page => 30).should be_empty
83
- end
84
-
85
- it "should paginate with options" do
86
- paginate({ :page => 2 }, :class => 'will_paginate', :previous_label => 'Prev', :next_label => 'Next') do
87
- assert_select 'a[href]', 4 do |elements|
88
- validate_page_numbers [1,1,3,3], elements
89
- # test rel attribute values:
90
- text(elements[0]).should == 'Prev'
91
- elements[0]['rel'].should == 'prev'
92
- text(elements[1]).should == '1'
93
- elements[1]['rel'].should == 'prev'
94
- text(elements[3]).should == 'Next'
95
- elements[3]['rel'].should == 'next'
96
- end
97
- assert_select '.current', '2'
98
- end
99
- end
100
-
101
- it "should paginate using a custom renderer class" do
102
- paginate({}, :renderer => AdditionalLinkAttributesRenderer) do
103
- assert_select 'a[default=true]', 3
104
- end
105
- end
106
-
107
- it "should paginate using a custom renderer instance" do
108
- renderer = WillPaginate::ActionView::LinkRenderer.new
109
- def renderer.gap() '<span class="my-gap">~~</span>' end
110
-
111
- paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0, :renderer => renderer) do
112
- assert_select 'span.my-gap', '~~'
113
- end
114
-
115
- renderer = AdditionalLinkAttributesRenderer.new(:title => 'rendered')
116
- paginate({}, :renderer => renderer) do
117
- assert_select 'a[title=rendered]', 3
118
- end
119
- end
120
-
121
- it "should have classnames on previous/next links" do
122
- paginate do |pagination|
123
- assert_select 'span.disabled.previous_page:first-child'
124
- assert_select 'a.next_page[href]:last-child'
125
- end
126
- end
127
-
128
- it "should match expected markup" do
129
- paginate
130
- expected = <<-HTML
131
- <div class="pagination" role="navigation" aria-label="Pagination"><span class="previous_page disabled">&#8592; Previous</span>
132
- <em class="current" aria-label="Page 1" aria-current="page">1</em>
133
- <a href="/foo/bar?page=2" aria-label="Page 2" rel="next">2</a>
134
- <a href="/foo/bar?page=3" aria-label="Page 3">3</a>
135
- <a href="/foo/bar?page=2" class="next_page" rel="next">Next &#8594;</a></div>
136
- HTML
137
- expected.strip!.gsub!(/\s{2,}/, ' ')
138
- expected_dom = parse_html_document(expected)
139
-
140
- if expected_dom.respond_to?(:canonicalize)
141
- html_document.canonicalize.should == expected_dom.canonicalize
142
- else
143
- html_document.root.should == expected_dom.root
144
- end
145
- end
146
-
147
- it "should output escaped URLs" do
148
- paginate({:page => 1, :per_page => 1, :total_entries => 2},
149
- :page_links => false, :params => { :tag => '<br>' })
150
-
151
- assert_select 'a[href]', 1 do |links|
152
- query = links.first['href'].split('?', 2)[1]
153
- parts = query.gsub('&amp;', '&').split('&').sort
154
- parts.should == %w(page=2 tag=%3Cbr%3E)
155
- end
156
- end
157
-
158
- ## advanced options for pagination ##
159
-
160
- it "should be able to render without container" do
161
- paginate({}, :container => false)
162
- assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t'
163
- assert_select 'a[href]', 3
164
- end
165
-
166
- it "should be able to render without page links" do
167
- paginate({ :page => 2 }, :page_links => false) do
168
- assert_select 'a[href]', 2 do |elements|
169
- validate_page_numbers [1,3], elements
170
- end
171
- end
172
- end
173
-
174
- ## other helpers ##
175
-
176
- it "should render a paginated section" do
177
- @template = <<-ERB
178
- <%= paginated_section collection, options do %>
179
- <%= content_tag :div, '', :id => "developers" %>
180
- <% end %>
181
- ERB
182
-
183
- paginate
184
- assert_select 'div.pagination', 2
185
- assert_select 'div.pagination + div#developers', 1
186
- end
187
-
188
- it "should not render a paginated section with a single page" do
189
- @template = <<-ERB
190
- <%= paginated_section collection, options do %>
191
- <%= content_tag :div, '', :id => "developers" %>
192
- <% end %>
193
- ERB
194
-
195
- paginate(:total_entries => 1)
196
- assert_select 'div.pagination', 0
197
- assert_select 'div#developers', 1
198
- end
199
-
200
- ## parameter handling in page links ##
201
-
202
- it "should preserve parameters on GET" do
203
- request.params :foo => { :bar => 'baz' }
204
- paginate
205
- assert_links_match /foo\[bar\]=baz/
206
- end
207
-
208
- it "doesn't allow tampering with host, port, protocol" do
209
- request.params :host => 'disney.com', :port => '99', :protocol => 'ftp'
210
- paginate
211
- assert_links_match %r{^/foo/bar}
212
- assert_no_links_match /disney/
213
- assert_no_links_match /99/
214
- assert_no_links_match /ftp/
215
- end
216
-
217
- it "doesn't allow tampering with script_name" do
218
- request.params :script_name => 'p0wned', :original_script_name => 'p0wned'
219
- paginate
220
- assert_links_match %r{^/foo/bar}
221
- assert_no_links_match /p0wned/
222
- end
223
-
224
- it "should not preserve parameters on POST" do
225
- request.post
226
- request.params :foo => 'bar'
227
- paginate
228
- assert_no_links_match /foo=bar/
229
- end
230
-
231
- it "should add additional parameters to links" do
232
- paginate({}, :params => { :foo => 'bar' })
233
- assert_links_match /foo=bar/
234
- end
235
-
236
- it "should add anchor parameter" do
237
- paginate({}, :params => { :anchor => 'anchor' })
238
- assert_links_match /#anchor$/
239
- end
240
-
241
- it "should remove arbitrary parameters" do
242
- request.params :foo => 'bar'
243
- paginate({}, :params => { :foo => nil })
244
- assert_no_links_match /foo=bar/
245
- end
246
-
247
- it "should override default route parameters" do
248
- paginate({}, :params => { :controller => 'baz', :action => 'list' })
249
- assert_links_match %r{\Wbaz/list\W}
250
- end
251
-
252
- it "should paginate with custom page parameter" do
253
- paginate({ :page => 2 }, :param_name => :developers_page) do
254
- assert_select 'a[href]', 4 do |elements|
255
- validate_page_numbers [1,1,3,3], elements, :developers_page
256
- end
257
- end
258
- end
259
-
260
- it "should paginate with complex custom page parameter" do
261
- request.params :developers => { :page => 2 }
262
-
263
- paginate({ :page => 2 }, :param_name => 'developers[page]') do
264
- assert_select 'a[href]', 4 do |links|
265
- assert_links_match /\?developers\[page\]=\d+$/, links
266
- validate_page_numbers [1,1,3,3], links, 'developers[page]'
267
- end
268
- end
269
- end
270
-
271
- it "should paginate with custom route page parameter" do
272
- request.symbolized_path_parameters.update :controller => 'dummy', :action => 'index'
273
- paginate :per_page => 2 do
274
- assert_select 'a[href]', 6 do |links|
275
- assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
276
- end
277
- end
278
- end
279
-
280
- it "should paginate with custom route with dot separator page parameter" do
281
- request.symbolized_path_parameters.update :controller => 'dummy', :action => 'dots'
282
- paginate :per_page => 2 do
283
- assert_select 'a[href]', 6 do |links|
284
- assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2]
285
- end
286
- end
287
- end
288
-
289
- it "should paginate with custom route and first page number implicit" do
290
- request.symbolized_path_parameters.update :controller => 'ibocorp', :action => 'index'
291
- paginate :page => 2, :per_page => 2 do
292
- assert_select 'a[href]', 7 do |links|
293
- assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5, 6, 3]
294
- end
295
- end
296
- # Routes.recognize_path('/ibocorp/2').should == {:page=>'2', :action=>'index', :controller=>'ibocorp'}
297
- # Routes.recognize_path('/ibocorp/foo').should == {:action=>'foo', :controller=>'ibocorp'}
298
- end
299
-
300
- ## internal hardcore stuff ##
301
-
302
- it "should be able to guess the collection name" do
303
- collection = mock
304
- collection.expects(:total_pages).returns(1)
305
-
306
- @template = '<%= will_paginate options %>'
307
- controller.controller_name = 'developers'
308
- assigns['developers'] = collection
309
-
310
- paginate(nil)
311
- end
312
-
313
- it "should fail if the inferred collection is nil" do
314
- @template = '<%= will_paginate options %>'
315
- controller.controller_name = 'developers'
316
-
317
- lambda {
318
- paginate(nil)
319
- }.should raise_error(ActionView::TemplateError, /@developers/)
320
- end
321
-
322
- ## i18n
323
-
324
- it "is able to translate previous/next labels" do
325
- translation :will_paginate => {
326
- :previous_label => 'Go back',
327
- :next_label => 'Load more'
328
- }
329
-
330
- paginate do |pagination|
331
- assert_select 'span.disabled:first-child', 'Go back'
332
- assert_select 'a[rel=next]', 'Load more'
333
- end
334
- end
335
-
336
- it "renders using ActionView helpers on a custom object" do
337
- helper = Class.new {
338
- attr_reader :controller
339
- include ActionView::Helpers::UrlHelper
340
- include Routes.url_helpers
341
- include WillPaginate::ActionView
342
- }.new
343
- helper.default_url_options[:controller] = 'dummy'
344
-
345
- collection = WillPaginate::Collection.new(2, 1, 3)
346
- @render_output = helper.will_paginate(collection)
347
-
348
- assert_select 'a[href]', 4 do |links|
349
- urls = links.map {|l| l['href'] }.uniq
350
- urls.should == ['/dummy/page/1', '/dummy/page/3']
351
- end
352
- end
353
-
354
- it "renders using ActionDispatch helper on a custom object" do
355
- helper = Class.new {
356
- include ActionDispatch::Routing::UrlFor
357
- include Routes.url_helpers
358
- include WillPaginate::ActionView
359
- }.new
360
- helper.default_url_options.update \
361
- :only_path => true,
362
- :controller => 'dummy'
363
-
364
- collection = WillPaginate::Collection.new(2, 1, 3)
365
- @render_output = helper.will_paginate(collection)
366
-
367
- assert_select 'a[href]', 4 do |links|
368
- urls = links.map {|l| l['href'] }.uniq
369
- urls.should == ['/dummy/page/1', '/dummy/page/3']
370
- end
371
- end
372
-
373
- private
374
-
375
- def translation(data)
376
- I18n.available_locales # triggers loading existing translations
377
- I18n.backend.store_translations(:en, data)
378
- end
379
-
380
- # Normalizes differences between HTML::Document and Nokogiri::HTML
381
- def text(node)
382
- node.inner_text.gsub('&#8594;', '→').gsub('&#8592;', '←')
383
- end
384
- end
385
-
386
- class AdditionalLinkAttributesRenderer < WillPaginate::ActionView::LinkRenderer
387
- def initialize(link_attributes = nil)
388
- super()
389
- @additional_link_attributes = link_attributes || { :default => 'true' }
390
- end
391
-
392
- def link(text, target, attributes = {})
393
- super(text, target, attributes.merge(@additional_link_attributes))
394
- end
395
- end
396
-
397
- class DummyController
398
- attr_reader :request
399
- attr_accessor :controller_name
400
-
401
- include ActionController::UrlFor
402
- include Routes.url_helpers
403
-
404
- def initialize
405
- @request = DummyRequest.new(self)
406
- end
407
-
408
- def params
409
- @request.params
410
- end
411
-
412
- def env
413
- {}
414
- end
415
-
416
- def _prefixes
417
- []
418
- end
419
- end
420
-
421
- class IbocorpController < DummyController
422
- end
423
-
424
- class DummyRequest
425
- attr_accessor :symbolized_path_parameters
426
- alias :path_parameters :symbolized_path_parameters
427
-
428
- def initialize(controller)
429
- @controller = controller
430
- @get = true
431
- @params = {}.with_indifferent_access
432
- @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
433
- end
434
-
435
- def routes
436
- @controller._routes
437
- end
438
-
439
- def get?
440
- @get
441
- end
442
-
443
- def post
444
- @get = false
445
- end
446
-
447
- def relative_url_root
448
- ''
449
- end
450
-
451
- def script_name
452
- ''
453
- end
454
-
455
- def params(more = nil)
456
- @params.update(more) if more
457
- if defined?(ActionController::Parameters)
458
- ActionController::Parameters.new(@params)
459
- else
460
- @params
461
- end
462
- end
463
-
464
- def host_with_port
465
- 'example.com'
466
- end
467
- alias host host_with_port
468
-
469
- def optional_port
470
- ''
471
- end
472
-
473
- def protocol
474
- 'http:'
475
- end
476
- end
477
-
478
- if defined?(ActionController::Parameters)
479
- ActionController::Parameters.permit_all_parameters = false
480
- end
@@ -1,143 +0,0 @@
1
- require 'spec_helper'
2
- require 'will_paginate/view_helpers'
3
- require 'will_paginate/array'
4
- require 'active_support'
5
- require 'active_support/core_ext/string/inflections'
6
- require 'active_support/inflections'
7
-
8
- describe WillPaginate::ViewHelpers do
9
-
10
- before(:all) do
11
- # make sure default translations aren't loaded
12
- I18n.load_path.clear
13
- I18n.enforce_available_locales = false
14
- end
15
-
16
- before(:each) do
17
- I18n.reload!
18
- end
19
-
20
- include WillPaginate::ViewHelpers
21
-
22
- describe "will_paginate" do
23
- it "should render" do
24
- collection = WillPaginate::Collection.new(1, 2, 4)
25
- renderer = mock 'Renderer'
26
- renderer.expects(:prepare).with(collection, instance_of(Hash), self)
27
- renderer.expects(:to_html).returns('<PAGES>')
28
-
29
- will_paginate(collection, :renderer => renderer).should == '<PAGES>'
30
- end
31
-
32
- it "should return nil for single-page collections" do
33
- collection = mock 'Collection', :total_pages => 1
34
- will_paginate(collection).should be_nil
35
- end
36
-
37
- it "should call html_safe on result" do
38
- collection = WillPaginate::Collection.new(1, 2, 4)
39
-
40
- html = mock 'HTML'
41
- html.expects(:html_safe).returns(html)
42
- renderer = mock 'Renderer'
43
- renderer.stubs(:prepare)
44
- renderer.expects(:to_html).returns(html)
45
-
46
- will_paginate(collection, :renderer => renderer).should eql(html)
47
- end
48
- end
49
-
50
- describe "pagination_options" do
51
- let(:pagination_options) { WillPaginate::ViewHelpers.pagination_options }
52
-
53
- it "deprecates setting :renderer" do
54
- begin
55
- lambda {
56
- pagination_options[:renderer] = 'test'
57
- }.should have_deprecation("pagination_options[:renderer] shouldn't be set")
58
- ensure
59
- pagination_options.delete :renderer
60
- end
61
- end
62
- end
63
-
64
- describe "page_entries_info" do
65
- before :all do
66
- @array = ('a'..'z').to_a
67
- end
68
-
69
- def info(params, options = {})
70
- collection = Hash === params ? @array.paginate(params) : params
71
- page_entries_info collection, {:html => false}.merge(options)
72
- end
73
-
74
- it "should display middle results and total count" do
75
- info(:page => 2, :per_page => 5).should == "Displaying strings 6 - 10 of 26 in total"
76
- end
77
-
78
- it "uses translation if available" do
79
- translation :will_paginate => {
80
- :page_entries_info => {:multi_page => 'Showing %{from} - %{to}'}
81
- }
82
- info(:page => 2, :per_page => 5).should == "Showing 6 - 10"
83
- end
84
-
85
- it "uses specific translation if available" do
86
- translation :will_paginate => {
87
- :page_entries_info => {:multi_page => 'Showing %{from} - %{to}'},
88
- :string => { :page_entries_info => {:multi_page => 'Strings %{from} to %{to}'} }
89
- }
90
- info(:page => 2, :per_page => 5).should == "Strings 6 to 10"
91
- end
92
-
93
- it "should output HTML by default" do
94
- info({ :page => 2, :per_page => 5 }, :html => true).should ==
95
- "Displaying strings <b>6&nbsp;-&nbsp;10</b> of <b>26</b> in total"
96
- end
97
-
98
- it "should display shortened end results" do
99
- info(:page => 7, :per_page => 4).should include_phrase('strings 25 - 26')
100
- end
101
-
102
- it "should handle longer class names" do
103
- collection = @array.paginate(:page => 2, :per_page => 5)
104
- model = stub('Class', :name => 'ProjectType', :to_s => 'ProjectType')
105
- collection.first.stubs(:class).returns(model)
106
- info(collection).should include_phrase('project types')
107
- end
108
-
109
- it "should adjust output for single-page collections" do
110
- info(('a'..'d').to_a.paginate(:page => 1, :per_page => 5)).should == "Displaying all 4 strings"
111
- info(['a'].paginate(:page => 1, :per_page => 5)).should == "Displaying 1 string"
112
- end
113
-
114
- it "should display 'no entries found' for empty collections" do
115
- info([].paginate(:page => 1, :per_page => 5)).should == "No entries found"
116
- end
117
-
118
- it "uses model_name.human when available" do
119
- name = stub('model name', :i18n_key => :flower_key)
120
- name.expects(:human).with(:count => 1).returns('flower')
121
- model = stub('Class', :model_name => name)
122
- collection = [1].paginate(:page => 1)
123
-
124
- info(collection, :model => model).should == "Displaying 1 flower"
125
- end
126
-
127
- it "uses custom translation instead of model_name.human" do
128
- name = stub('model name', :i18n_key => :flower_key)
129
- name.expects(:human).never
130
- model = stub('Class', :model_name => name)
131
- translation :will_paginate => {:models => {:flower_key => 'tulip'}}
132
- collection = [1].paginate(:page => 1)
133
-
134
- info(collection, :model => model).should == "Displaying 1 tulip"
135
- end
136
-
137
- private
138
-
139
- def translation(data)
140
- I18n.backend.store_translations(:en, data)
141
- end
142
- end
143
- end