svenaas-will_paginate 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/.autotest +54 -0
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/.manifest +61 -0
  5. data/CHANGELOG.rdoc +105 -0
  6. data/LICENSE +18 -0
  7. data/README.rdoc +125 -0
  8. data/Rakefile +58 -0
  9. data/init.rb +1 -0
  10. data/lib/will_paginate.rb +45 -0
  11. data/lib/will_paginate/array.rb +33 -0
  12. data/lib/will_paginate/collection.rb +145 -0
  13. data/lib/will_paginate/core_ext.rb +69 -0
  14. data/lib/will_paginate/deprecation.rb +50 -0
  15. data/lib/will_paginate/finders.rb +9 -0
  16. data/lib/will_paginate/finders/active_record.rb +192 -0
  17. data/lib/will_paginate/finders/active_record/named_scope.rb +170 -0
  18. data/lib/will_paginate/finders/active_record/named_scope_patch.rb +39 -0
  19. data/lib/will_paginate/finders/active_resource.rb +51 -0
  20. data/lib/will_paginate/finders/base.rb +112 -0
  21. data/lib/will_paginate/finders/data_mapper.rb +30 -0
  22. data/lib/will_paginate/finders/sequel.rb +22 -0
  23. data/lib/will_paginate/version.rb +9 -0
  24. data/lib/will_paginate/view_helpers.rb +42 -0
  25. data/lib/will_paginate/view_helpers/action_view.rb +158 -0
  26. data/lib/will_paginate/view_helpers/base.rb +126 -0
  27. data/lib/will_paginate/view_helpers/link_renderer.rb +130 -0
  28. data/lib/will_paginate/view_helpers/link_renderer_base.rb +83 -0
  29. data/lib/will_paginate/view_helpers/merb.rb +13 -0
  30. data/spec/collection_spec.rb +147 -0
  31. data/spec/console +8 -0
  32. data/spec/console_fixtures.rb +8 -0
  33. data/spec/database.yml +22 -0
  34. data/spec/finders/active_record_spec.rb +461 -0
  35. data/spec/finders/active_resource_spec.rb +52 -0
  36. data/spec/finders/activerecord_test_connector.rb +108 -0
  37. data/spec/finders/data_mapper_spec.rb +62 -0
  38. data/spec/finders/data_mapper_test_connector.rb +20 -0
  39. data/spec/finders/sequel_spec.rb +53 -0
  40. data/spec/finders/sequel_test_connector.rb +9 -0
  41. data/spec/finders_spec.rb +76 -0
  42. data/spec/fixtures/admin.rb +3 -0
  43. data/spec/fixtures/developer.rb +13 -0
  44. data/spec/fixtures/developers_projects.yml +13 -0
  45. data/spec/fixtures/project.rb +15 -0
  46. data/spec/fixtures/projects.yml +6 -0
  47. data/spec/fixtures/replies.yml +29 -0
  48. data/spec/fixtures/reply.rb +7 -0
  49. data/spec/fixtures/schema.rb +38 -0
  50. data/spec/fixtures/topic.rb +6 -0
  51. data/spec/fixtures/topics.yml +30 -0
  52. data/spec/fixtures/user.rb +2 -0
  53. data/spec/fixtures/users.yml +35 -0
  54. data/spec/rcov.opts +2 -0
  55. data/spec/spec.opts +2 -0
  56. data/spec/spec_helper.rb +75 -0
  57. data/spec/tasks.rake +60 -0
  58. data/spec/view_helpers/action_view_spec.rb +344 -0
  59. data/spec/view_helpers/base_spec.rb +64 -0
  60. data/spec/view_helpers/link_renderer_base_spec.rb +84 -0
  61. data/spec/view_helpers/view_example_group.rb +111 -0
  62. metadata +164 -0
@@ -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,111 @@
1
+ unless $:.find { |p| p =~ %r{/html-scanner$} }
2
+ unless actionpack_path = $:.find { |p| p =~ %r{/actionpack(-[\d.]+)?/lib$} }
3
+ raise "cannot find ActionPack in load paths"
4
+ end
5
+ html_scanner_path = "#{actionpack_path}/action_controller/vendor/html-scanner"
6
+ $:.unshift(html_scanner_path)
7
+ end
8
+
9
+ require 'action_controller/assertions/selector_assertions'
10
+
11
+ class ViewExampleGroup < Spec::Example::ExampleGroup
12
+
13
+ include ActionController::Assertions::SelectorAssertions
14
+
15
+ def assert(value, message)
16
+ raise message unless value
17
+ end
18
+
19
+ def paginate(collection = {}, options = {}, &block)
20
+ if collection.instance_of? Hash
21
+ page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
22
+ collection = [1].paginate(page_options)
23
+ end
24
+
25
+ locals = { :collection => collection, :options => options }
26
+
27
+ @render_output = render(locals)
28
+ @html_document = nil
29
+
30
+ if block_given?
31
+ classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
32
+ assert_select("div.#{classname}", 1, 'no main DIV', &block)
33
+ end
34
+
35
+ @render_output
36
+ end
37
+
38
+ def html_document
39
+ @html_document ||= HTML::Document.new(@render_output, true, false)
40
+ end
41
+
42
+ def response_from_page_or_rjs
43
+ html_document.root
44
+ end
45
+
46
+ def validate_page_numbers(expected, links, param_name = :page)
47
+ param_pattern = /\W#{CGI.escape(param_name.to_s)}=([^&]*)/
48
+
49
+ links.map { |e|
50
+ e['href'] =~ param_pattern
51
+ $1 ? $1.to_i : $1
52
+ }.should == expected
53
+ end
54
+
55
+ def assert_links_match(pattern, links = nil, numbers = nil)
56
+ links ||= assert_select 'div.pagination a[href]' do |elements|
57
+ elements
58
+ end
59
+
60
+ pages = [] if numbers
61
+
62
+ links.each do |el|
63
+ el['href'].should =~ pattern
64
+ if numbers
65
+ el['href'] =~ pattern
66
+ pages << ($1.nil?? nil : $1.to_i)
67
+ end
68
+ end
69
+
70
+ pages.should == numbers if numbers
71
+ end
72
+
73
+ def assert_no_links_match(pattern)
74
+ assert_select 'div.pagination a[href]' do |elements|
75
+ elements.each do |el|
76
+ el['href'] !~ pattern
77
+ end
78
+ end
79
+ end
80
+
81
+ def build_message(message, pattern, *args)
82
+ built_message = pattern.dup
83
+ for value in args
84
+ built_message.sub! '?', value.inspect
85
+ end
86
+ built_message
87
+ end
88
+
89
+ end
90
+
91
+ Spec::Example::ExampleGroupFactory.register(:view_helpers, ViewExampleGroup)
92
+
93
+ module HTML
94
+ Node.class_eval do
95
+ def inner_text
96
+ children.map(&:inner_text).join('')
97
+ end
98
+ end
99
+
100
+ Text.class_eval do
101
+ def inner_text
102
+ self.to_s
103
+ end
104
+ end
105
+
106
+ Tag.class_eval do
107
+ def inner_text
108
+ childless?? '' : super
109
+ end
110
+ end
111
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svenaas-will_paginate
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
+ prerelease: false
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 2
10
+ version: 3.0.2
11
+ platform: ruby
12
+ authors:
13
+ - "Mislav Marohni\xC4\x87"
14
+ - PJ Hyett
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-07-08 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: The will_paginate library provides a simple, yet powerful and extensible API for pagination and rendering of page links in templates.
24
+ email: mislav.marohnic@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ - LICENSE
32
+ - CHANGELOG.rdoc
33
+ files:
34
+ - .autotest
35
+ - .gitignore
36
+ - .gitmodules
37
+ - .manifest
38
+ - CHANGELOG.rdoc
39
+ - LICENSE
40
+ - README.rdoc
41
+ - Rakefile
42
+ - init.rb
43
+ - lib/will_paginate.rb
44
+ - lib/will_paginate/array.rb
45
+ - lib/will_paginate/collection.rb
46
+ - lib/will_paginate/core_ext.rb
47
+ - lib/will_paginate/deprecation.rb
48
+ - lib/will_paginate/finders.rb
49
+ - lib/will_paginate/finders/active_record.rb
50
+ - lib/will_paginate/finders/active_record/named_scope.rb
51
+ - lib/will_paginate/finders/active_record/named_scope_patch.rb
52
+ - lib/will_paginate/finders/active_resource.rb
53
+ - lib/will_paginate/finders/base.rb
54
+ - lib/will_paginate/finders/data_mapper.rb
55
+ - lib/will_paginate/finders/sequel.rb
56
+ - lib/will_paginate/version.rb
57
+ - lib/will_paginate/view_helpers.rb
58
+ - lib/will_paginate/view_helpers/action_view.rb
59
+ - lib/will_paginate/view_helpers/base.rb
60
+ - lib/will_paginate/view_helpers/link_renderer.rb
61
+ - lib/will_paginate/view_helpers/link_renderer_base.rb
62
+ - lib/will_paginate/view_helpers/merb.rb
63
+ - spec/collection_spec.rb
64
+ - spec/console
65
+ - spec/console_fixtures.rb
66
+ - spec/database.yml
67
+ - spec/finders/active_record_spec.rb
68
+ - spec/finders/active_resource_spec.rb
69
+ - spec/finders/activerecord_test_connector.rb
70
+ - spec/finders/data_mapper_spec.rb
71
+ - spec/finders/data_mapper_test_connector.rb
72
+ - spec/finders/sequel_spec.rb
73
+ - spec/finders/sequel_test_connector.rb
74
+ - spec/finders_spec.rb
75
+ - spec/fixtures/admin.rb
76
+ - spec/fixtures/developer.rb
77
+ - spec/fixtures/developers_projects.yml
78
+ - spec/fixtures/project.rb
79
+ - spec/fixtures/projects.yml
80
+ - spec/fixtures/replies.yml
81
+ - spec/fixtures/reply.rb
82
+ - spec/fixtures/schema.rb
83
+ - spec/fixtures/topic.rb
84
+ - spec/fixtures/topics.yml
85
+ - spec/fixtures/user.rb
86
+ - spec/fixtures/users.yml
87
+ - spec/rcov.opts
88
+ - spec/spec.opts
89
+ - spec/spec_helper.rb
90
+ - spec/tasks.rake
91
+ - spec/view_helpers/action_view_spec.rb
92
+ - spec/view_helpers/base_spec.rb
93
+ - spec/view_helpers/link_renderer_base_spec.rb
94
+ - spec/view_helpers/view_example_group.rb
95
+ has_rdoc: true
96
+ homepage: http://github.com/mislav/will_paginate/wikis
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options:
101
+ - --main
102
+ - README.rdoc
103
+ - --inline-source
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirements: []
126
+
127
+ rubyforge_project:
128
+ rubygems_version: 1.3.7
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Most awesome pagination solution for every web app
132
+ test_files:
133
+ - spec/collection_spec.rb
134
+ - spec/console
135
+ - spec/console_fixtures.rb
136
+ - spec/database.yml
137
+ - spec/finders/active_record_spec.rb
138
+ - spec/finders/active_resource_spec.rb
139
+ - spec/finders/activerecord_test_connector.rb
140
+ - spec/finders/data_mapper_spec.rb
141
+ - spec/finders/data_mapper_test_connector.rb
142
+ - spec/finders/sequel_spec.rb
143
+ - spec/finders/sequel_test_connector.rb
144
+ - spec/finders_spec.rb
145
+ - spec/fixtures/admin.rb
146
+ - spec/fixtures/developer.rb
147
+ - spec/fixtures/developers_projects.yml
148
+ - spec/fixtures/project.rb
149
+ - spec/fixtures/projects.yml
150
+ - spec/fixtures/replies.yml
151
+ - spec/fixtures/reply.rb
152
+ - spec/fixtures/schema.rb
153
+ - spec/fixtures/topic.rb
154
+ - spec/fixtures/topics.yml
155
+ - spec/fixtures/user.rb
156
+ - spec/fixtures/users.yml
157
+ - spec/rcov.opts
158
+ - spec/spec.opts
159
+ - spec/spec_helper.rb
160
+ - spec/tasks.rake
161
+ - spec/view_helpers/action_view_spec.rb
162
+ - spec/view_helpers/base_spec.rb
163
+ - spec/view_helpers/link_renderer_base_spec.rb
164
+ - spec/view_helpers/view_example_group.rb