pb-will_paginate 2.3.12

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 (51) hide show
  1. data/.gitignore +4 -0
  2. data/.manifest +43 -0
  3. data/CHANGELOG.rdoc +139 -0
  4. data/LICENSE +18 -0
  5. data/README.rdoc +107 -0
  6. data/Rakefile +71 -0
  7. data/VERSION +1 -0
  8. data/examples/apple-circle.gif +0 -0
  9. data/examples/index.haml +69 -0
  10. data/examples/index.html +92 -0
  11. data/examples/pagination.css +90 -0
  12. data/examples/pagination.sass +91 -0
  13. data/init.rb +2 -0
  14. data/lib/will_paginate.rb +90 -0
  15. data/lib/will_paginate/array.rb +16 -0
  16. data/lib/will_paginate/collection.rb +144 -0
  17. data/lib/will_paginate/core_ext.rb +43 -0
  18. data/lib/will_paginate/finder.rb +264 -0
  19. data/lib/will_paginate/i18n.rb +178 -0
  20. data/lib/will_paginate/named_scope.rb +170 -0
  21. data/lib/will_paginate/named_scope_patch.rb +37 -0
  22. data/lib/will_paginate/version.rb +9 -0
  23. data/lib/will_paginate/view_helpers.rb +397 -0
  24. data/locales/en.yml +11 -0
  25. data/pb-will_paginate.gemspec +106 -0
  26. data/test/boot.rb +21 -0
  27. data/test/collection_test.rb +143 -0
  28. data/test/console +8 -0
  29. data/test/database.yml +22 -0
  30. data/test/finder_test.rb +473 -0
  31. data/test/fixtures/admin.rb +3 -0
  32. data/test/fixtures/developer.rb +14 -0
  33. data/test/fixtures/developers_projects.yml +13 -0
  34. data/test/fixtures/project.rb +15 -0
  35. data/test/fixtures/projects.yml +6 -0
  36. data/test/fixtures/replies.yml +29 -0
  37. data/test/fixtures/reply.rb +7 -0
  38. data/test/fixtures/schema.rb +38 -0
  39. data/test/fixtures/topic.rb +10 -0
  40. data/test/fixtures/topics.yml +30 -0
  41. data/test/fixtures/user.rb +2 -0
  42. data/test/fixtures/users.yml +35 -0
  43. data/test/helper.rb +37 -0
  44. data/test/i18n_test.rb +194 -0
  45. data/test/lib/activerecord_test_case.rb +43 -0
  46. data/test/lib/activerecord_test_connector.rb +75 -0
  47. data/test/lib/load_fixtures.rb +11 -0
  48. data/test/lib/view_test_process.rb +179 -0
  49. data/test/tasks.rake +59 -0
  50. data/test/view_test.rb +289 -0
  51. metadata +122 -0
@@ -0,0 +1,43 @@
1
+ require 'lib/activerecord_test_connector'
2
+
3
+ class ActiveRecordTestCase < Test::Unit::TestCase
4
+ if defined?(ActiveSupport::Testing::SetupAndTeardown)
5
+ include ActiveSupport::Testing::SetupAndTeardown
6
+ end
7
+
8
+ if defined?(ActiveRecord::TestFixtures)
9
+ include ActiveRecord::TestFixtures
10
+ end
11
+ # Set our fixture path
12
+ if ActiveRecordTestConnector.able_to_connect
13
+ self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
14
+ self.use_transactional_fixtures = true
15
+ end
16
+
17
+ def self.fixtures(*args)
18
+ super if ActiveRecordTestConnector.connected
19
+ end
20
+
21
+ def run(*args)
22
+ super if ActiveRecordTestConnector.connected
23
+ end
24
+
25
+ # Default so Test::Unit::TestCase doesn't complain
26
+ def test_truth
27
+ end
28
+
29
+ protected
30
+
31
+ def assert_queries(num = 1)
32
+ $query_count = 0
33
+ yield
34
+ ensure
35
+ assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed."
36
+ end
37
+
38
+ def assert_no_queries(&block)
39
+ assert_queries(0, &block)
40
+ end
41
+ end
42
+
43
+ ActiveRecordTestConnector.setup
@@ -0,0 +1,75 @@
1
+ require 'active_record'
2
+ require 'active_record/version'
3
+ require 'active_record/fixtures'
4
+
5
+ class ActiveRecordTestConnector
6
+ cattr_accessor :able_to_connect
7
+ cattr_accessor :connected
8
+
9
+ FIXTURES_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures')
10
+
11
+ # Set our defaults
12
+ self.connected = false
13
+ self.able_to_connect = true
14
+
15
+ def self.setup
16
+ unless self.connected || !self.able_to_connect
17
+ setup_connection
18
+ load_schema
19
+ add_load_path FIXTURES_PATH
20
+ self.connected = true
21
+ end
22
+ rescue Exception => e # errors from ActiveRecord setup
23
+ $stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
24
+ self.able_to_connect = false
25
+ end
26
+
27
+ private
28
+
29
+ def self.add_load_path(path)
30
+ dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
31
+ dep.load_paths.unshift path
32
+ end
33
+
34
+ def self.setup_connection
35
+ db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
36
+
37
+ configurations = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'database.yml'))
38
+ raise "no configuration for '#{db}'" unless configurations.key? db
39
+ configuration = configurations[db]
40
+
41
+ ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
42
+ puts "using #{configuration['adapter']} adapter" unless ENV['DB'].blank?
43
+
44
+ gem 'sqlite3-ruby' if 'sqlite3' == db
45
+
46
+ ActiveRecord::Base.establish_connection(configuration)
47
+ ActiveRecord::Base.configurations = { db => configuration }
48
+ prepare ActiveRecord::Base.connection
49
+
50
+ unless Object.const_defined?(:QUOTED_TYPE)
51
+ Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')
52
+ end
53
+ end
54
+
55
+ def self.load_schema
56
+ ActiveRecord::Base.silence do
57
+ ActiveRecord::Migration.verbose = false
58
+ load File.join(FIXTURES_PATH, 'schema.rb')
59
+ end
60
+ end
61
+
62
+ def self.prepare(conn)
63
+ class << conn
64
+ IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SHOW FIELDS /]
65
+
66
+ def execute_with_counting(sql, name = nil, &block)
67
+ $query_count ||= 0
68
+ $query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
69
+ execute_without_counting(sql, name, &block)
70
+ end
71
+
72
+ alias_method_chain :execute, :counting
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,11 @@
1
+ require 'boot'
2
+ require 'lib/activerecord_test_connector'
3
+
4
+ # setup the connection
5
+ ActiveRecordTestConnector.setup
6
+
7
+ # load all fixtures
8
+ Fixtures.create_fixtures(ActiveRecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables)
9
+
10
+ require 'will_paginate'
11
+ WillPaginate.enable_activerecord
@@ -0,0 +1,179 @@
1
+ require 'will_paginate/core_ext'
2
+ require 'action_controller'
3
+ require 'action_controller/test_process'
4
+
5
+ require 'will_paginate'
6
+ WillPaginate.enable_actionpack
7
+
8
+ ActionController::Routing::Routes.draw do |map|
9
+ map.connect 'dummy/page/:page', :controller => 'dummy'
10
+ map.connect 'dummy/dots/page.:page', :controller => 'dummy', :action => 'dots'
11
+ map.connect 'ibocorp/:page', :controller => 'ibocorp',
12
+ :requirements => { :page => /\d+/ },
13
+ :defaults => { :page => 1 }
14
+
15
+ map.connect ':controller/:action/:id'
16
+ end
17
+
18
+ ActionController::Base.perform_caching = false
19
+
20
+ class WillPaginate::ViewTestCase < Test::Unit::TestCase
21
+ if defined?(ActionController::TestCase::Assertions)
22
+ include ActionController::TestCase::Assertions
23
+ end
24
+ if defined?(ActiveSupport::Testing::Deprecation)
25
+ include ActiveSupport::Testing::Deprecation
26
+ end
27
+
28
+ def setup
29
+ super
30
+ @controller = DummyController.new
31
+ @request = @controller.request
32
+ @html_result = nil
33
+ @template = '<%= will_paginate collection, options %>'
34
+
35
+ @view = ActionView::Base.new
36
+ @view.assigns['controller'] = @controller
37
+ @view.assigns['_request'] = @request
38
+ @view.assigns['_params'] = @request.params
39
+ end
40
+
41
+ def test_no_complain; end
42
+
43
+ protected
44
+
45
+ def paginate(collection = {}, options = {}, &block)
46
+ if collection.instance_of? Hash
47
+ page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
48
+ collection = [1].paginate(page_options)
49
+ end
50
+
51
+ locals = { :collection => collection, :options => options }
52
+
53
+ unless @view.respond_to? :render_template
54
+ # Rails 2.2
55
+ @html_result = ActionView::InlineTemplate.new(@template).render(@view, locals)
56
+ else
57
+ if defined? ActionView::InlineTemplate
58
+ # Rails 2.1
59
+ args = [ ActionView::InlineTemplate.new(@view, @template, locals) ]
60
+ else
61
+ # older Rails versions
62
+ args = [nil, @template, nil, locals]
63
+ end
64
+
65
+ @html_result = @view.render_template(*args)
66
+ end
67
+
68
+ @html_document = HTML::Document.new(@html_result, true, false)
69
+
70
+ if block_given?
71
+ classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
72
+ assert_select("div.#{classname}", 1, 'no main DIV', &block)
73
+ end
74
+ end
75
+
76
+ def response_from_page_or_rjs
77
+ @html_document.root
78
+ end
79
+
80
+ def validate_page_numbers expected, links, param_name = :page
81
+ param_pattern = /\W#{CGI.escape(param_name.to_s)}=([^&]*)/
82
+
83
+ assert_equal(expected, links.map { |e|
84
+ e['href'] =~ param_pattern
85
+ $1 ? $1.to_i : $1
86
+ })
87
+ end
88
+
89
+ def assert_links_match pattern, links = nil, numbers = nil
90
+ links ||= assert_select 'div.pagination a[href]' do |elements|
91
+ elements
92
+ end
93
+
94
+ pages = [] if numbers
95
+
96
+ links.each do |el|
97
+ assert_match pattern, el['href']
98
+ if numbers
99
+ el['href'] =~ pattern
100
+ pages << ($1.nil?? nil : $1.to_i)
101
+ end
102
+ end
103
+
104
+ assert_equal numbers, pages, "page numbers don't match" if numbers
105
+ end
106
+
107
+ def assert_no_links_match pattern
108
+ assert_select 'div.pagination a[href]' do |elements|
109
+ elements.each do |el|
110
+ assert_no_match pattern, el['href']
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ class DummyRequest
117
+ attr_accessor :symbolized_path_parameters
118
+
119
+ def initialize
120
+ @get = true
121
+ @params = {}
122
+ @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
123
+ end
124
+
125
+ def get?
126
+ @get
127
+ end
128
+
129
+ def post
130
+ @get = false
131
+ end
132
+
133
+ def relative_url_root
134
+ ''
135
+ end
136
+
137
+ def params(more = nil)
138
+ @params.update(more) if more
139
+ @params
140
+ end
141
+ end
142
+
143
+ class DummyController
144
+ attr_reader :request
145
+ attr_accessor :controller_name
146
+
147
+ def initialize
148
+ @request = DummyRequest.new
149
+ @url = ActionController::UrlRewriter.new(@request, @request.params)
150
+ end
151
+
152
+ def params
153
+ @request.params
154
+ end
155
+
156
+ def url_for(params)
157
+ @url.rewrite(params)
158
+ end
159
+ end
160
+
161
+ module HTML
162
+ Node.class_eval do
163
+ def inner_text
164
+ children.map(&:inner_text).join('')
165
+ end
166
+ end
167
+
168
+ Text.class_eval do
169
+ def inner_text
170
+ self.to_s
171
+ end
172
+ end
173
+
174
+ Tag.class_eval do
175
+ def inner_text
176
+ childless?? '' : super
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,59 @@
1
+ require 'rake/testtask'
2
+
3
+ desc 'Test the will_paginate plugin.'
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.pattern = 'test/**/*_test.rb'
6
+ t.verbose = true
7
+ t.libs << 'test'
8
+ end
9
+
10
+ # I want to specify environment variables at call time
11
+ class EnvTestTask < Rake::TestTask
12
+ attr_accessor :env
13
+
14
+ def ruby(*args)
15
+ env.each { |key, value| ENV[key] = value } if env
16
+ super
17
+ env.keys.each { |key| ENV.delete key } if env
18
+ end
19
+ end
20
+
21
+ for configuration in %w( sqlite3 mysql postgres )
22
+ EnvTestTask.new("test_#{configuration}") do |t|
23
+ t.pattern = 'test/finder_test.rb'
24
+ t.verbose = true
25
+ t.env = { 'DB' => configuration }
26
+ t.libs << 'test'
27
+ end
28
+ end
29
+
30
+ task :test_databases => %w(test_mysql test_sqlite3 test_postgres)
31
+
32
+ desc %{Test everything on SQLite3, MySQL and PostgreSQL}
33
+ task :test_full => %w(test test_mysql test_postgres)
34
+
35
+ desc %{Test everything with Rails 2.1.x, 2.0.x & 1.2.x gems}
36
+ task :test_all do
37
+ all = Rake::Task['test_full']
38
+ versions = %w(2.3.2 2.2.2 2.1.0 2.0.4 1.2.6)
39
+ versions.each do |version|
40
+ ENV['RAILS_VERSION'] = "~> #{version}"
41
+ all.invoke
42
+ reset_invoked unless version == versions.last
43
+ end
44
+ end
45
+
46
+ def reset_invoked
47
+ %w( test_full test test_mysql test_postgres ).each do |name|
48
+ Rake::Task[name].instance_variable_set '@already_invoked', false
49
+ end
50
+ end
51
+
52
+ task :rcov do
53
+ excludes = %w( lib/will_paginate/named_scope*
54
+ lib/will_paginate/core_ext.rb
55
+ lib/will_paginate.rb
56
+ rails* )
57
+
58
+ system %[rcov -Itest:lib test/*.rb -x #{excludes.join(',')}]
59
+ end
@@ -0,0 +1,289 @@
1
+ require 'helper'
2
+ require 'lib/view_test_process'
3
+
4
+ class AdditionalLinkAttributesRenderer < WillPaginate::LinkRenderer
5
+ def initialize(link_attributes = nil)
6
+ super()
7
+ @additional_link_attributes = link_attributes || { :default => 'true' }
8
+ end
9
+
10
+ def page_link(page, text, attributes = {})
11
+ @template.link_to text, url_for(page), attributes.merge(@additional_link_attributes)
12
+ end
13
+ end
14
+
15
+ class ViewTest < WillPaginate::ViewTestCase
16
+
17
+ ## basic pagination ##
18
+
19
+ def test_will_paginate
20
+ paginate do |pagination|
21
+ assert_select 'a[href]', 3 do |elements|
22
+ validate_page_numbers [2,3,2], elements
23
+ assert_select elements.last, ':last-child', "Next &raquo;"
24
+ end
25
+ assert_select 'span', 2
26
+ assert_select 'span.disabled:first-child', '&laquo; Previous'
27
+ assert_select 'span.current', '1'
28
+ assert_equal '&laquo; Previous 1 2 3 Next &raquo;', pagination.first.inner_text
29
+ end
30
+ end
31
+
32
+ def test_no_pagination_when_page_count_is_one
33
+ paginate :per_page => 30
34
+ assert_equal '', @html_result
35
+ end
36
+
37
+ def test_will_paginate_with_options
38
+ paginate({ :page => 2 }, :class => 'will_paginate') do
39
+ assert_select 'a[href]', 4 do |elements|
40
+ validate_page_numbers [1,1,3,3], elements
41
+ # test rel attribute values:
42
+ assert_select elements[1], 'a', '1' do |link|
43
+ assert_equal 'prev start', link.first['rel']
44
+ end
45
+ end
46
+ assert_select 'span.current', '2'
47
+ end
48
+ end
49
+
50
+ def test_will_paginate_using_renderer_class
51
+ paginate({}, :renderer => AdditionalLinkAttributesRenderer) do
52
+ assert_select 'a[default=true]', 3
53
+ end
54
+ end
55
+
56
+ def test_prev_next_links_have_classnames
57
+ paginate do |pagination|
58
+ assert_select 'span.disabled.prev_page:first-child'
59
+ assert_select 'a.next_page[href]:last-child'
60
+ end
61
+ end
62
+
63
+ def test_full_output
64
+ paginate
65
+ expected = <<-HTML
66
+ <div class="pagination"><span class="disabled prev_page">&laquo; Previous</span>
67
+ <span class="current">1</span>
68
+ <a href="/foo/bar?page=2" rel="next">2</a>
69
+ <a href="/foo/bar?page=3">3</a>
70
+ <a href="/foo/bar?page=2" class="next_page" rel="next">Next &raquo;</a></div>
71
+ HTML
72
+ expected.strip!.gsub!(/\s{2,}/, ' ')
73
+
74
+ assert_dom_equal expected, @html_result
75
+ end
76
+
77
+ def test_escaping_of_urls
78
+ paginate({:page => 1, :per_page => 1, :total_entries => 2},
79
+ :page_links => false, :params => { :tag => '<br>' })
80
+
81
+ assert_select 'a[href]', 1 do |links|
82
+ query = links.first['href'].split('?', 2)[1]
83
+ assert_equal %w(page=2 tag=%3Cbr%3E), query.split('&amp;').sort
84
+ end
85
+ end
86
+
87
+ ## advanced options for pagination ##
88
+
89
+ def test_will_paginate_without_container
90
+ paginate({}, :container => false)
91
+ assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t'
92
+ assert_select 'a[href]', 3
93
+ end
94
+
95
+ def test_will_paginate_without_page_links
96
+ paginate({ :page => 2 }, :page_links => false) do
97
+ assert_select 'a[href]', 2 do |elements|
98
+ validate_page_numbers [1,3], elements
99
+ end
100
+ end
101
+ end
102
+
103
+ def test_will_paginate_windows
104
+ paginate({ :page => 6, :per_page => 1 }, :inner_window => 1) do |pagination|
105
+ assert_select 'a[href]', 8 do |elements|
106
+ validate_page_numbers [5,1,2,5,7,10,11,7], elements
107
+ assert_select elements.first, 'a', '&laquo; Previous'
108
+ assert_select elements.last, 'a', 'Next &raquo;'
109
+ end
110
+ assert_select 'span.current', '6'
111
+ assert_equal '&laquo; Previous 1 2 &hellip; 5 6 7 &hellip; 10 11 Next &raquo;', pagination.first.inner_text
112
+ end
113
+ end
114
+
115
+ def test_will_paginate_eliminates_small_gaps
116
+ paginate({ :page => 6, :per_page => 1 }, :inner_window => 2) do
117
+ assert_select 'a[href]', 12 do |elements|
118
+ validate_page_numbers [5,1,2,3,4,5,7,8,9,10,11,7], elements
119
+ end
120
+ end
121
+ end
122
+
123
+ def test_container_id
124
+ paginate do |div|
125
+ assert_nil div.first['id']
126
+ end
127
+
128
+ # magic ID
129
+ paginate({}, :id => true) do |div|
130
+ assert_equal 'fixnums_pagination', div.first['id']
131
+ end
132
+
133
+ # explicit ID
134
+ paginate({}, :id => 'custom_id') do |div|
135
+ assert_equal 'custom_id', div.first['id']
136
+ end
137
+ end
138
+
139
+ ## other helpers ##
140
+
141
+ def test_paginated_section
142
+ @template = <<-ERB
143
+ <% paginated_section collection, options do %>
144
+ <%= content_tag :div, '', :id => "developers" %>
145
+ <% end %>
146
+ ERB
147
+
148
+ paginate
149
+ assert_select 'div.pagination', 2
150
+ assert_select 'div.pagination + div#developers', 1
151
+ end
152
+
153
+ ## parameter handling in page links ##
154
+
155
+ def test_will_paginate_preserves_parameters_on_get
156
+ @request.params :foo => { :bar => 'baz' }
157
+ paginate
158
+ assert_links_match /foo%5Bbar%5D=baz/
159
+ end
160
+
161
+ def test_will_paginate_doesnt_preserve_parameters_on_post
162
+ @request.post
163
+ @request.params :foo => 'bar'
164
+ paginate
165
+ assert_no_links_match /foo=bar/
166
+ end
167
+
168
+ def test_adding_additional_parameters
169
+ paginate({}, :params => { :foo => 'bar' })
170
+ assert_links_match /foo=bar/
171
+ end
172
+
173
+ def test_adding_anchor_parameter
174
+ paginate({}, :params => { :anchor => 'anchor' })
175
+ assert_links_match /#anchor$/
176
+ end
177
+
178
+ def test_removing_arbitrary_parameters
179
+ @request.params :foo => 'bar'
180
+ paginate({}, :params => { :foo => nil })
181
+ assert_no_links_match /foo=bar/
182
+ end
183
+
184
+ def test_adding_additional_route_parameters
185
+ paginate({}, :params => { :controller => 'baz', :action => 'list' })
186
+ assert_links_match %r{\Wbaz/list\W}
187
+ end
188
+
189
+ def test_will_paginate_with_custom_page_param
190
+ paginate({ :page => 2 }, :param_name => :developers_page) do
191
+ assert_select 'a[href]', 4 do |elements|
192
+ validate_page_numbers [1,1,3,3], elements, :developers_page
193
+ end
194
+ end
195
+ end
196
+
197
+ def test_will_paginate_with_atmark_url
198
+ @request.symbolized_path_parameters[:action] = "@tag"
199
+ renderer = WillPaginate::LinkRenderer.new
200
+
201
+ paginate({ :page => 1 }, :renderer=>renderer)
202
+ assert_links_match %r[/foo/@tag\?page=\d]
203
+ end
204
+
205
+ def test_complex_custom_page_param
206
+ @request.params :developers => { :page => 2 }
207
+
208
+ paginate({ :page => 2 }, :param_name => 'developers[page]') do
209
+ assert_select 'a[href]', 4 do |links|
210
+ assert_links_match /\?developers%5Bpage%5D=\d+$/, links
211
+ validate_page_numbers [1,1,3,3], links, 'developers[page]'
212
+ end
213
+ end
214
+ end
215
+
216
+ def test_custom_routing_page_param
217
+ @request.symbolized_path_parameters.update :controller => 'dummy', :action => nil
218
+ paginate :per_page => 2 do
219
+ assert_select 'a[href]', 6 do |links|
220
+ assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
221
+ end
222
+ end
223
+ end
224
+
225
+ def test_custom_routing_page_param_with_dot_separator
226
+ @request.symbolized_path_parameters.update :controller => 'dummy', :action => 'dots'
227
+ paginate :per_page => 2 do
228
+ assert_select 'a[href]', 6 do |links|
229
+ assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2]
230
+ end
231
+ end
232
+ end
233
+
234
+ def test_custom_routing_with_first_page_hidden
235
+ @request.symbolized_path_parameters.update :controller => 'ibocorp', :action => nil
236
+ paginate :page => 2, :per_page => 2 do
237
+ assert_select 'a[href]', 7 do |links|
238
+ assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5, 6, 3]
239
+ end
240
+ end
241
+ end
242
+
243
+ ## internal hardcore stuff ##
244
+
245
+ class LegacyCollection < WillPaginate::Collection
246
+ alias :page_count :total_pages
247
+ undef :total_pages
248
+ end
249
+
250
+ def test_deprecation_notices_with_page_count
251
+ collection = LegacyCollection.new(1, 1, 2)
252
+
253
+ assert_deprecated collection.class.name do
254
+ paginate collection
255
+ end
256
+ end
257
+
258
+ uses_mocha 'view internals' do
259
+ def test_collection_name_can_be_guessed
260
+ collection = mock
261
+ collection.expects(:total_pages).returns(1)
262
+
263
+ @template = '<%= will_paginate options %>'
264
+ @controller.controller_name = 'developers'
265
+ @view.assigns['developers'] = collection
266
+
267
+ paginate(nil)
268
+ end
269
+ end
270
+
271
+ def test_inferred_collection_name_raises_error_when_nil
272
+ @template = '<%= will_paginate options %>'
273
+ @controller.controller_name = 'developers'
274
+
275
+ e = assert_raise ArgumentError do
276
+ paginate(nil)
277
+ end
278
+ assert e.message.include?('@developers')
279
+ end
280
+
281
+ if ActionController::Base.respond_to? :rescue_responses
282
+ # only on Rails 2
283
+ def test_rescue_response_hook_presence
284
+ assert_equal :not_found,
285
+ ActionController::Base.rescue_responses['WillPaginate::InvalidPage']
286
+ end
287
+ end
288
+
289
+ end