will_paginate 2.3.17 → 3.0.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of will_paginate might be problematic. Click here for more details.

Files changed (83) hide show
  1. data/CHANGELOG.rdoc +24 -80
  2. data/LICENSE +1 -1
  3. data/README.rdoc +125 -0
  4. data/Rakefile +26 -22
  5. data/lib/will_paginate.rb +10 -84
  6. data/lib/will_paginate/array.rb +25 -8
  7. data/lib/will_paginate/collection.rb +15 -28
  8. data/lib/will_paginate/core_ext.rb +26 -0
  9. data/lib/will_paginate/deprecation.rb +50 -0
  10. data/lib/will_paginate/finders.rb +9 -0
  11. data/lib/will_paginate/finders/active_record.rb +158 -0
  12. data/lib/will_paginate/finders/active_resource.rb +51 -0
  13. data/lib/will_paginate/finders/base.rb +112 -0
  14. data/lib/will_paginate/finders/data_mapper.rb +30 -0
  15. data/lib/will_paginate/finders/sequel.rb +23 -0
  16. data/lib/will_paginate/railtie.rb +26 -0
  17. data/lib/will_paginate/version.rb +5 -5
  18. data/lib/will_paginate/view_helpers.rb +25 -436
  19. data/lib/will_paginate/view_helpers/action_view.rb +142 -0
  20. data/lib/will_paginate/view_helpers/base.rb +126 -0
  21. data/lib/will_paginate/view_helpers/link_renderer.rb +130 -0
  22. data/lib/will_paginate/view_helpers/link_renderer_base.rb +83 -0
  23. data/lib/will_paginate/view_helpers/merb.rb +13 -0
  24. data/spec/collection_spec.rb +147 -0
  25. data/spec/console +8 -0
  26. data/spec/console_fixtures.rb +8 -0
  27. data/spec/database.yml +22 -0
  28. data/spec/finders/active_record_spec.rb +377 -0
  29. data/spec/finders/active_resource_spec.rb +52 -0
  30. data/spec/finders/activerecord_test_connector.rb +114 -0
  31. data/spec/finders/data_mapper_spec.rb +62 -0
  32. data/spec/finders/data_mapper_test_connector.rb +20 -0
  33. data/spec/finders/sequel_spec.rb +53 -0
  34. data/spec/finders/sequel_test_connector.rb +9 -0
  35. data/spec/finders_spec.rb +76 -0
  36. data/{test → spec}/fixtures/admin.rb +0 -0
  37. data/{test → spec}/fixtures/developer.rb +2 -3
  38. data/{test → spec}/fixtures/developers_projects.yml +0 -0
  39. data/{test → spec}/fixtures/project.rb +2 -6
  40. data/{test → spec}/fixtures/projects.yml +1 -1
  41. data/{test → spec}/fixtures/replies.yml +0 -0
  42. data/{test → spec}/fixtures/reply.rb +1 -1
  43. data/{test → spec}/fixtures/schema.rb +0 -0
  44. data/spec/fixtures/topic.rb +7 -0
  45. data/{test → spec}/fixtures/topics.yml +0 -0
  46. data/{test → spec}/fixtures/user.rb +0 -0
  47. data/{test → spec}/fixtures/users.yml +0 -0
  48. data/spec/rcov.opts +2 -0
  49. data/spec/spec.opts +2 -0
  50. data/spec/spec_helper.rb +74 -0
  51. data/spec/tasks.rake +60 -0
  52. data/spec/view_helpers/action_view_spec.rb +345 -0
  53. data/spec/view_helpers/base_spec.rb +64 -0
  54. data/spec/view_helpers/link_renderer_base_spec.rb +84 -0
  55. data/spec/view_helpers/view_example_group.rb +103 -0
  56. metadata +60 -65
  57. data/README.md +0 -53
  58. data/lib/will_paginate/finder.rb +0 -269
  59. data/lib/will_paginate/i18n.rb +0 -29
  60. data/lib/will_paginate/locale/en.yml +0 -33
  61. data/lib/will_paginate/named_scope.rb +0 -170
  62. data/lib/will_paginate/named_scope_patch.rb +0 -37
  63. data/lib/will_paginate/per_page.rb +0 -27
  64. data/test/ci.rb +0 -60
  65. data/test/collection_test.rb +0 -160
  66. data/test/console +0 -8
  67. data/test/database.yml +0 -16
  68. data/test/finder_test.rb +0 -527
  69. data/test/fixtures/topic.rb +0 -12
  70. data/test/gemfiles/Gemfile.1.2 +0 -13
  71. data/test/gemfiles/Gemfile.1.2.lock +0 -39
  72. data/test/gemfiles/Gemfile.2.0 +0 -16
  73. data/test/gemfiles/Gemfile.2.0.lock +0 -28
  74. data/test/gemfiles/Gemfile.2.1 +0 -16
  75. data/test/gemfiles/Gemfile.2.1.lock +0 -28
  76. data/test/gemfiles/Gemfile.2.2 +0 -16
  77. data/test/gemfiles/Gemfile.2.2.lock +0 -28
  78. data/test/helper.rb +0 -34
  79. data/test/lib/activerecord_test_case.rb +0 -38
  80. data/test/lib/activerecord_test_connector.rb +0 -86
  81. data/test/lib/load_fixtures.rb +0 -12
  82. data/test/lib/view_test_process.rb +0 -186
  83. data/test/view_test.rb +0 -380
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'will_paginate/view_helpers/base'
3
+ require 'will_paginate/array'
4
+
5
+ describe WillPaginate::ViewHelpers::Base do
6
+
7
+ include WillPaginate::ViewHelpers::Base
8
+
9
+ describe "will_paginate" do
10
+ it "should render" do
11
+ collection = WillPaginate::Collection.new(1, 2, 4)
12
+ renderer = mock 'Renderer'
13
+ renderer.expects(:prepare).with(collection, instance_of(Hash), self)
14
+ renderer.expects(:to_html).returns('<PAGES>')
15
+
16
+ will_paginate(collection, :renderer => renderer).should == '<PAGES>'
17
+ end
18
+
19
+ it "should return nil for single-page collections" do
20
+ collection = mock 'Collection', :total_pages => 1
21
+ will_paginate(collection).should be_nil
22
+ end
23
+ end
24
+
25
+ describe "page_entries_info" do
26
+ before :all do
27
+ @array = ('a'..'z').to_a
28
+ end
29
+
30
+ def info(params, options = {})
31
+ options[:html] ||= false unless options.key?(:html) and options[:html].nil?
32
+ collection = Hash === params ? @array.paginate(params) : params
33
+ page_entries_info collection, options
34
+ end
35
+
36
+ it "should display middle results and total count" do
37
+ info(:page => 2, :per_page => 5).should == "Displaying strings 6 - 10 of 26 in total"
38
+ end
39
+
40
+ it "should output HTML by default" do
41
+ info({ :page => 2, :per_page => 5 }, :html => nil).should ==
42
+ "Displaying strings <b>6&nbsp;-&nbsp;10</b> of <b>26</b> in total"
43
+ end
44
+
45
+ it "should display shortened end results" do
46
+ info(:page => 7, :per_page => 4).should include_phrase('strings 25 - 26')
47
+ end
48
+
49
+ it "should handle longer class names" do
50
+ collection = @array.paginate(:page => 2, :per_page => 5)
51
+ collection.first.stubs(:class).returns(mock('Class', :name => 'ProjectType'))
52
+ info(collection).should include_phrase('project types')
53
+ end
54
+
55
+ it "should adjust output for single-page collections" do
56
+ info(('a'..'d').to_a.paginate(:page => 1, :per_page => 5)).should == "Displaying all 4 strings"
57
+ info(['a'].paginate(:page => 1, :per_page => 5)).should == "Displaying 1 string"
58
+ end
59
+
60
+ it "should display 'no entries found' for empty collections" do
61
+ info([].paginate(:page => 1, :per_page => 5)).should == "No entries found"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require 'will_paginate/view_helpers/link_renderer_base'
3
+ require 'will_paginate/collection'
4
+
5
+ describe WillPaginate::ViewHelpers::LinkRendererBase do
6
+
7
+ before do
8
+ @renderer = WillPaginate::ViewHelpers::LinkRendererBase.new
9
+ end
10
+
11
+ it "should raise error when unprepared" do
12
+ lambda {
13
+ @renderer.send :param_name
14
+ }.should raise_error
15
+ end
16
+
17
+ it "should prepare with collection and options" do
18
+ prepare({}, :param_name => 'mypage')
19
+ @renderer.send(:current_page).should == 1
20
+ @renderer.send(:param_name).should == 'mypage'
21
+ end
22
+
23
+ it "should have total_pages accessor" do
24
+ prepare :total_pages => 42
25
+ lambda {
26
+ @renderer.send(:total_pages).should == 42
27
+ }.should_not have_deprecation
28
+ end
29
+
30
+ it "should clear old cached values when prepared" do
31
+ prepare({ :total_pages => 1 }, :param_name => 'foo')
32
+ @renderer.send(:total_pages).should == 1
33
+ @renderer.send(:param_name).should == 'foo'
34
+ # prepare with different object and options:
35
+ prepare({ :total_pages => 2 }, :param_name => 'bar')
36
+ @renderer.send(:total_pages).should == 2
37
+ @renderer.send(:param_name).should == 'bar'
38
+ end
39
+
40
+ it "should have pagination definition" do
41
+ prepare({ :total_pages => 1 }, :page_links => true)
42
+ @renderer.pagination.should == [:previous_page, 1, :next_page]
43
+ end
44
+
45
+ describe "visible page numbers" do
46
+ it "should calculate windowed visible links" do
47
+ prepare({ :page => 6, :total_pages => 11 }, :inner_window => 1, :outer_window => 1)
48
+ showing_pages 1, 2, :gap, 5, 6, 7, :gap, 10, 11
49
+ end
50
+
51
+ it "should eliminate small gaps" do
52
+ prepare({ :page => 6, :total_pages => 11 }, :inner_window => 2, :outer_window => 1)
53
+ # pages 4 and 8 appear instead of the gap
54
+ showing_pages 1..11
55
+ end
56
+
57
+ it "should support having no windows at all" do
58
+ prepare({ :page => 4, :total_pages => 7 }, :inner_window => 0, :outer_window => 0)
59
+ showing_pages 1, :gap, 4, :gap, 7
60
+ end
61
+
62
+ it "should adjust upper limit if lower is out of bounds" do
63
+ prepare({ :page => 1, :total_pages => 10 }, :inner_window => 2, :outer_window => 1)
64
+ showing_pages 1, 2, 3, 4, 5, :gap, 9, 10
65
+ end
66
+
67
+ it "should adjust lower limit if upper is out of bounds" do
68
+ prepare({ :page => 10, :total_pages => 10 }, :inner_window => 2, :outer_window => 1)
69
+ showing_pages 1, 2, :gap, 6, 7, 8, 9, 10
70
+ end
71
+
72
+ def showing_pages(*pages)
73
+ pages = pages.first.to_a if Array === pages.first or Range === pages.first
74
+ @renderer.send(:windowed_page_numbers).should == pages
75
+ end
76
+ end
77
+
78
+ protected
79
+
80
+ def prepare(collection_options, options = {})
81
+ @renderer.prepare(collection(collection_options), options)
82
+ end
83
+
84
+ end
@@ -0,0 +1,103 @@
1
+ require 'action_dispatch/testing/assertions'
2
+
3
+ class ViewExampleGroup < Spec::Example::ExampleGroup
4
+
5
+ include ActionDispatch::Assertions::SelectorAssertions
6
+
7
+ def assert(value, message)
8
+ raise message unless value
9
+ end
10
+
11
+ def paginate(collection = {}, options = {}, &block)
12
+ if collection.instance_of? Hash
13
+ page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
14
+ collection = [1].paginate(page_options)
15
+ end
16
+
17
+ locals = { :collection => collection, :options => options }
18
+
19
+ @render_output = render(locals)
20
+ @html_document = nil
21
+
22
+ if block_given?
23
+ classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
24
+ assert_select("div.#{classname}", 1, 'no main DIV', &block)
25
+ end
26
+
27
+ @render_output
28
+ end
29
+
30
+ def html_document
31
+ @html_document ||= HTML::Document.new(@render_output, true, false)
32
+ end
33
+
34
+ def response_from_page_or_rjs
35
+ html_document.root
36
+ end
37
+
38
+ def validate_page_numbers(expected, links, param_name = :page)
39
+ param_pattern = /\W#{Regexp.escape(param_name.to_s)}=([^&]*)/
40
+
41
+ links.map { |e|
42
+ e['href'] =~ param_pattern
43
+ $1 ? $1.to_i : $1
44
+ }.should == expected
45
+ end
46
+
47
+ def assert_links_match(pattern, links = nil, numbers = nil)
48
+ links ||= assert_select 'div.pagination a[href]' do |elements|
49
+ elements
50
+ end
51
+
52
+ pages = [] if numbers
53
+
54
+ links.each do |el|
55
+ el['href'].should =~ pattern
56
+ if numbers
57
+ el['href'] =~ pattern
58
+ pages << ($1.nil?? nil : $1.to_i)
59
+ end
60
+ end
61
+
62
+ pages.should == numbers if numbers
63
+ end
64
+
65
+ def assert_no_links_match(pattern)
66
+ assert_select 'div.pagination a[href]' do |elements|
67
+ elements.each do |el|
68
+ el['href'] !~ pattern
69
+ end
70
+ end
71
+ end
72
+
73
+ def build_message(message, pattern, *args)
74
+ built_message = pattern.dup
75
+ for value in args
76
+ built_message.sub! '?', value.inspect
77
+ end
78
+ built_message
79
+ end
80
+
81
+ end
82
+
83
+ Spec::Example::ExampleGroupFactory.register(:view_helpers, ViewExampleGroup)
84
+
85
+ module HTML
86
+ Node.class_eval do
87
+ def inner_text
88
+ children.map(&:inner_text).join('')
89
+ end
90
+ end
91
+
92
+ Text.class_eval do
93
+ def inner_text
94
+ self.to_s
95
+ end
96
+ end
97
+
98
+ Tag.class_eval do
99
+ def inner_text
100
+ childless?? '' : super
101
+ end
102
+ end
103
+ end
metadata CHANGED
@@ -1,33 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
5
- prerelease:
6
- segments:
7
- - 2
8
- - 3
9
- - 17
10
- version: 2.3.17
4
+ version: 3.0.pre
11
5
  platform: ruby
12
6
  authors:
13
7
  - "Mislav Marohni\xC4\x87"
14
- - PJ Hyett
15
8
  autorequire:
16
9
  bindir: bin
17
10
  cert_chain: []
18
11
 
19
- date: 2016-10-15 00:00:00 +02:00
12
+ date: 2010-02-05 00:00:00 +01:00
20
13
  default_executable:
21
14
  dependencies: []
22
15
 
23
- description: will_paginate provides a simple API for Active Record pagination and rendering of pagination links in Rails templates.
16
+ description: The will_paginate library provides a simple, yet powerful and extensible API for pagination and rendering of page links in web application templates.
24
17
  email: mislav.marohnic@gmail.com
25
18
  executables: []
26
19
 
27
20
  extensions: []
28
21
 
29
22
  extra_rdoc_files:
30
- - README.md
23
+ - README.rdoc
31
24
  - LICENSE
32
25
  - CHANGELOG.rdoc
33
26
  files:
@@ -35,84 +28,86 @@ files:
35
28
  - lib/will_paginate/array.rb
36
29
  - lib/will_paginate/collection.rb
37
30
  - lib/will_paginate/core_ext.rb
38
- - lib/will_paginate/finder.rb
39
- - lib/will_paginate/i18n.rb
40
- - lib/will_paginate/locale/en.yml
41
- - lib/will_paginate/named_scope.rb
42
- - lib/will_paginate/named_scope_patch.rb
43
- - lib/will_paginate/per_page.rb
31
+ - lib/will_paginate/deprecation.rb
32
+ - lib/will_paginate/finders/active_record.rb
33
+ - lib/will_paginate/finders/active_resource.rb
34
+ - lib/will_paginate/finders/base.rb
35
+ - lib/will_paginate/finders/data_mapper.rb
36
+ - lib/will_paginate/finders/sequel.rb
37
+ - lib/will_paginate/finders.rb
38
+ - lib/will_paginate/railtie.rb
44
39
  - lib/will_paginate/version.rb
40
+ - lib/will_paginate/view_helpers/action_view.rb
41
+ - lib/will_paginate/view_helpers/base.rb
42
+ - lib/will_paginate/view_helpers/link_renderer.rb
43
+ - lib/will_paginate/view_helpers/link_renderer_base.rb
44
+ - lib/will_paginate/view_helpers/merb.rb
45
45
  - lib/will_paginate/view_helpers.rb
46
46
  - lib/will_paginate.rb
47
- - test/ci.rb
48
- - test/collection_test.rb
49
- - test/console
50
- - test/database.yml
51
- - test/finder_test.rb
52
- - test/fixtures/admin.rb
53
- - test/fixtures/developer.rb
54
- - test/fixtures/developers_projects.yml
55
- - test/fixtures/project.rb
56
- - test/fixtures/projects.yml
57
- - test/fixtures/replies.yml
58
- - test/fixtures/reply.rb
59
- - test/fixtures/schema.rb
60
- - test/fixtures/topic.rb
61
- - test/fixtures/topics.yml
62
- - test/fixtures/user.rb
63
- - test/fixtures/users.yml
64
- - test/gemfiles/Gemfile.1.2
65
- - test/gemfiles/Gemfile.1.2.lock
66
- - test/gemfiles/Gemfile.2.0
67
- - test/gemfiles/Gemfile.2.0.lock
68
- - test/gemfiles/Gemfile.2.1
69
- - test/gemfiles/Gemfile.2.1.lock
70
- - test/gemfiles/Gemfile.2.2
71
- - test/gemfiles/Gemfile.2.2.lock
72
- - test/helper.rb
73
- - test/lib/activerecord_test_case.rb
74
- - test/lib/activerecord_test_connector.rb
75
- - test/lib/load_fixtures.rb
76
- - test/lib/view_test_process.rb
77
- - test/view_test.rb
78
- - README.md
47
+ - spec/collection_spec.rb
48
+ - spec/console
49
+ - spec/console_fixtures.rb
50
+ - spec/database.yml
51
+ - spec/finders/active_record_spec.rb
52
+ - spec/finders/active_resource_spec.rb
53
+ - spec/finders/activerecord_test_connector.rb
54
+ - spec/finders/data_mapper_spec.rb
55
+ - spec/finders/data_mapper_test_connector.rb
56
+ - spec/finders/sequel_spec.rb
57
+ - spec/finders/sequel_test_connector.rb
58
+ - spec/finders_spec.rb
59
+ - spec/fixtures/admin.rb
60
+ - spec/fixtures/developer.rb
61
+ - spec/fixtures/developers_projects.yml
62
+ - spec/fixtures/project.rb
63
+ - spec/fixtures/projects.yml
64
+ - spec/fixtures/replies.yml
65
+ - spec/fixtures/reply.rb
66
+ - spec/fixtures/schema.rb
67
+ - spec/fixtures/topic.rb
68
+ - spec/fixtures/topics.yml
69
+ - spec/fixtures/user.rb
70
+ - spec/fixtures/users.yml
71
+ - spec/rcov.opts
72
+ - spec/spec.opts
73
+ - spec/spec_helper.rb
74
+ - spec/tasks.rake
75
+ - spec/view_helpers/action_view_spec.rb
76
+ - spec/view_helpers/base_spec.rb
77
+ - spec/view_helpers/link_renderer_base_spec.rb
78
+ - spec/view_helpers/view_example_group.rb
79
+ - README.rdoc
79
80
  - LICENSE
80
81
  - CHANGELOG.rdoc
81
82
  has_rdoc: true
82
- homepage: https://github.com/mislav/will_paginate/wiki
83
- licenses:
84
- - MIT
83
+ homepage: http://github.com/mislav/will_paginate/wikis
84
+ licenses: []
85
+
85
86
  post_install_message:
86
87
  rdoc_options:
87
88
  - --main
88
- - README.md
89
+ - README.rdoc
89
90
  - --charset=UTF-8
90
91
  require_paths:
91
92
  - lib
92
93
  required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- hash: 3
98
- segments:
99
- - 0
100
97
  version: "0"
98
+ version:
101
99
  required_rubygems_version: !ruby/object:Gem::Requirement
102
- none: false
103
100
  requirements:
104
- - - ">="
101
+ - - ">"
105
102
  - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
108
- - 0
109
- version: "0"
103
+ version: 1.3.1
104
+ version:
110
105
  requirements: []
111
106
 
112
107
  rubyforge_project:
113
- rubygems_version: 1.6.2
108
+ rubygems_version: 1.3.5
114
109
  signing_key:
115
110
  specification_version: 3
116
- summary: Easy pagination for Rails
111
+ summary: Adaptive pagination plugin for web frameworks and other applications
117
112
  test_files: []
118
113
 
data/README.md DELETED
@@ -1,53 +0,0 @@
1
- # will_paginate
2
-
3
- will_paginate v2.3 is a pagination plugin for Rails and Active Record.
4
-
5
- Installation:
6
-
7
- ~~~ ruby
8
- ## environment.rb
9
- Rails::Initializer.run do |config|
10
- config.gem 'will_paginate', :version => '~> 2.3.16'
11
- end
12
- ~~~
13
-
14
- See [installation instructions][install] on the wiki for more info.
15
-
16
-
17
- ## Basic will_paginate use
18
-
19
- ~~~ ruby
20
- ## perform a paginated query:
21
- @posts = Post.paginate(:page => params[:page])
22
-
23
- # or, use an explicit "per page" limit:
24
- Post.paginate(:page => params[:page], :per_page => 30)
25
-
26
- ## render page links in the view:
27
- <%= will_paginate @posts %>
28
- ~~~
29
-
30
- And that's it! You're done. You just need to add some CSS styles to [make those pagination links prettier][css].
31
-
32
- You can customize the default "per_page" value:
33
-
34
- ~~~ ruby
35
- # for the Post model
36
- class Post
37
- self.per_page = 10
38
- end
39
-
40
- # set per_page globally
41
- WillPaginate.per_page = 10
42
- ~~~
43
-
44
- See [the wiki][wiki] for more documentation. [Ask on the group][group] if you have usage questions. [Report bugs][issues] on GitHub.
45
-
46
- Happy paginating.
47
-
48
-
49
- [wiki]: https://github.com/mislav/will_paginate/wiki
50
- [install]: https://github.com/mislav/will_paginate/wiki/Installation "will_paginate installation"
51
- [group]: http://groups.google.com/group/will_paginate "will_paginate discussion and support group"
52
- [issues]: https://github.com/mislav/will_paginate/issues
53
- [css]: http://mislav.uniqpath.com/will_paginate/