f1sherman-will_paginate 3.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGELOG.rdoc +105 -0
  2. data/LICENSE +18 -0
  3. data/README.rdoc +111 -0
  4. data/Rakefile +32 -0
  5. data/lib/will_paginate.rb +23 -0
  6. data/lib/will_paginate/array.rb +33 -0
  7. data/lib/will_paginate/collection.rb +145 -0
  8. data/lib/will_paginate/core_ext.rb +69 -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 +9 -0
  18. data/lib/will_paginate/view_helpers.rb +42 -0
  19. data/lib/will_paginate/view_helpers/action_view.rb +134 -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 +4 -0
  26. data/spec/console_fixtures.rb +29 -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 +110 -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/spec/fixtures/admin.rb +3 -0
  37. data/spec/fixtures/developer.rb +13 -0
  38. data/spec/fixtures/developers_projects.yml +13 -0
  39. data/spec/fixtures/project.rb +13 -0
  40. data/spec/fixtures/projects.yml +6 -0
  41. data/spec/fixtures/replies.yml +29 -0
  42. data/spec/fixtures/reply.rb +7 -0
  43. data/spec/fixtures/schema.rb +38 -0
  44. data/spec/fixtures/topic.rb +7 -0
  45. data/spec/fixtures/topics.yml +30 -0
  46. data/spec/fixtures/user.rb +2 -0
  47. data/spec/fixtures/users.yml +35 -0
  48. data/spec/rcov.opts +2 -0
  49. data/spec/spec.opts +2 -0
  50. data/spec/spec_helper.rb +76 -0
  51. data/spec/tasks.rake +60 -0
  52. data/spec/view_helpers/action_view_spec.rb +356 -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 +126 -0
@@ -0,0 +1,29 @@
1
+ witty_retort:
2
+ id: 1
3
+ topic_id: 1
4
+ content: Birdman is better!
5
+ created_at: <%= 6.hours.ago.to_s(:db) %>
6
+
7
+ another:
8
+ id: 2
9
+ topic_id: 2
10
+ content: Nuh uh!
11
+ created_at: <%= 1.hour.ago.to_s(:db) %>
12
+
13
+ spam:
14
+ id: 3
15
+ topic_id: 1
16
+ content: Nice site!
17
+ created_at: <%= 1.hour.ago.to_s(:db) %>
18
+
19
+ decisive:
20
+ id: 4
21
+ topic_id: 4
22
+ content: "I'm getting to the bottom of this"
23
+ created_at: <%= 30.minutes.ago.to_s(:db) %>
24
+
25
+ brave:
26
+ id: 5
27
+ topic_id: 4
28
+ content: "AR doesn't scare me a bit"
29
+ created_at: <%= 10.minutes.ago.to_s(:db) %>
@@ -0,0 +1,7 @@
1
+ class Reply < ActiveRecord::Base
2
+ belongs_to :topic, :include => [:replies]
3
+
4
+ scope :recent, :conditions => ['replies.created_at > ?', 15.minutes.ago]
5
+
6
+ validates_presence_of :content
7
+ end
@@ -0,0 +1,38 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table "users", :force => true do |t|
4
+ t.column "name", :text
5
+ t.column "salary", :integer, :default => 70000
6
+ t.column "created_at", :datetime
7
+ t.column "updated_at", :datetime
8
+ t.column "type", :text
9
+ end
10
+
11
+ create_table "projects", :force => true do |t|
12
+ t.column "name", :text
13
+ end
14
+
15
+ create_table "developers_projects", :id => false, :force => true do |t|
16
+ t.column "developer_id", :integer, :null => false
17
+ t.column "project_id", :integer, :null => false
18
+ t.column "joined_on", :date
19
+ t.column "access_level", :integer, :default => 1
20
+ end
21
+
22
+ create_table "topics", :force => true do |t|
23
+ t.column "project_id", :integer
24
+ t.column "title", :string
25
+ t.column "subtitle", :string
26
+ t.column "content", :text
27
+ t.column "created_at", :datetime
28
+ t.column "updated_at", :datetime
29
+ end
30
+
31
+ create_table "replies", :force => true do |t|
32
+ t.column "content", :text
33
+ t.column "created_at", :datetime
34
+ t.column "updated_at", :datetime
35
+ t.column "topic_id", :integer
36
+ end
37
+
38
+ end
@@ -0,0 +1,7 @@
1
+ class Topic < ActiveRecord::Base
2
+ has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC'
3
+ belongs_to :project
4
+
5
+ scope :mentions_activerecord, :conditions => ['topics.title LIKE ?', '%ActiveRecord%']
6
+ scope :distinct, :select => "DISTINCT #{table_name}.*"
7
+ end
@@ -0,0 +1,30 @@
1
+ futurama:
2
+ id: 1
3
+ title: Isnt futurama awesome?
4
+ subtitle: It really is, isnt it.
5
+ content: I like futurama
6
+ created_at: <%= 1.day.ago.to_s(:db) %>
7
+ updated_at:
8
+
9
+ harvey_birdman:
10
+ id: 2
11
+ title: Harvey Birdman is the king of all men
12
+ subtitle: yup
13
+ content: He really is
14
+ created_at: <%= 2.hours.ago.to_s(:db) %>
15
+ updated_at:
16
+
17
+ rails:
18
+ id: 3
19
+ project_id: 1
20
+ title: Rails is nice
21
+ subtitle: It makes me happy
22
+ content: except when I have to hack internals to fix pagination. even then really.
23
+ created_at: <%= 20.minutes.ago.to_s(:db) %>
24
+
25
+ ar:
26
+ id: 4
27
+ project_id: 1
28
+ title: ActiveRecord sometimes freaks me out
29
+ content: "I mean, what's the deal with eager loading?"
30
+ created_at: <%= 15.minutes.ago.to_s(:db) %>
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,35 @@
1
+ david:
2
+ id: 1
3
+ name: David
4
+ salary: 80000
5
+ type: Developer
6
+
7
+ jamis:
8
+ id: 2
9
+ name: Jamis
10
+ salary: 150000
11
+ type: Developer
12
+
13
+ <% for digit in 3..10 %>
14
+ dev_<%= digit %>:
15
+ id: <%= digit %>
16
+ name: fixture_<%= digit %>
17
+ salary: 100000
18
+ type: Developer
19
+ <% end %>
20
+
21
+ poor_jamis:
22
+ id: 11
23
+ name: Jamis
24
+ salary: 9000
25
+ type: Developer
26
+
27
+ admin:
28
+ id: 12
29
+ name: admin
30
+ type: Admin
31
+
32
+ goofy:
33
+ id: 13
34
+ name: Goofy
35
+ type: Admin
data/spec/rcov.opts ADDED
@@ -0,0 +1,2 @@
1
+ --exclude ^\/,^spec\/,core_ext.rb,deprecation.rb
2
+ --no-validator-links
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --reverse
@@ -0,0 +1,76 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'spec/autorun'
4
+
5
+ module MyExtras
6
+ protected
7
+
8
+ def include_phrase(string)
9
+ PhraseMatcher.new(string)
10
+ end
11
+
12
+ def collection(params = {})
13
+ if params[:total_pages]
14
+ params[:per_page] = 1
15
+ params[:total_entries] = params[:total_pages]
16
+ end
17
+ WillPaginate::Collection.new(params[:page] || 1, params[:per_page] || 30, params[:total_entries])
18
+ end
19
+
20
+ def have_deprecation
21
+ DeprecationMatcher.new
22
+ end
23
+ end
24
+
25
+ Spec::Runner.configure do |config|
26
+ # config.include My::Pony, My::Horse, :type => :farm
27
+ config.include MyExtras
28
+ # config.predicate_matchers[:swim] = :can_swim?
29
+
30
+ config.mock_with :mocha
31
+ end
32
+
33
+ class PhraseMatcher
34
+ def initialize(string)
35
+ @string = string
36
+ @pattern = /\b#{string}\b/
37
+ end
38
+
39
+ def matches?(actual)
40
+ @actual = actual.to_s
41
+ @actual =~ @pattern
42
+ end
43
+
44
+ def failure_message
45
+ "expected #{@actual.inspect} to contain phrase #{@string.inspect}"
46
+ end
47
+
48
+ def negative_failure_message
49
+ "expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
50
+ end
51
+ end
52
+
53
+ class DeprecationMatcher
54
+ def initialize
55
+ @old_behavior = WillPaginate::Deprecation.behavior
56
+ @messages = []
57
+ WillPaginate::Deprecation.behavior = lambda { |message, callstack|
58
+ @messages << message
59
+ }
60
+ end
61
+
62
+ def matches?(block)
63
+ block.call
64
+ !@messages.empty?
65
+ ensure
66
+ WillPaginate::Deprecation.behavior = @old_behavior
67
+ end
68
+
69
+ def failure_message
70
+ "expected block to raise a deprecation warning"
71
+ end
72
+
73
+ def negative_failure_message
74
+ "expected block not to raise deprecation warnings, #{@messages.size} raised"
75
+ end
76
+ end
data/spec/tasks.rake ADDED
@@ -0,0 +1,60 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ spec_opts = 'spec/spec.opts'
4
+
5
+ desc 'Run framework-agnostic specs'
6
+ Spec::Rake::SpecTask.new(:spec) do |t|
7
+ t.libs << 'spec'
8
+ t.spec_opts = ['--options', spec_opts]
9
+ t.spec_files = FileList.new('spec/**/*_spec.rb') do |files|
10
+ files.exclude(/\b(active_record|active_resource|action_view|data_mapper|sequel)_/)
11
+ end
12
+ end
13
+
14
+ namespace :spec do
15
+ desc 'Run specs for core, ActiveRecord and ActionView'
16
+ Spec::Rake::SpecTask.new(:rails) do |t|
17
+ t.libs << 'spec'
18
+ t.spec_opts = ['--options', spec_opts]
19
+ t.spec_files = FileList.new('spec/**/*_spec.rb') do |files|
20
+ files.exclude(/\b(data_mapper|sequel)_/)
21
+ end
22
+ end
23
+
24
+ desc 'Run specs for DataMapper'
25
+ Spec::Rake::SpecTask.new(:datamapper) do |t|
26
+ t.libs << 'spec'
27
+ t.spec_opts = ['--options', spec_opts]
28
+ t.spec_files = FileList.new('spec/finders_spec.rb', 'spec/finders/data_mapper_spec.rb')
29
+ end
30
+
31
+ desc 'Run specs for Sequel'
32
+ Spec::Rake::SpecTask.new(:sequel) do |t|
33
+ t.libs << 'spec'
34
+ t.spec_opts = ['--options', spec_opts]
35
+ t.spec_files = FileList.new('spec/finders_spec.rb', 'spec/finders/sequel_spec.rb')
36
+ end
37
+
38
+ desc 'Analyze spec coverage with RCov'
39
+ Spec::Rake::SpecTask.new(:rcov) do |t|
40
+ t.libs << 'spec'
41
+ t.spec_opts = ['--options', spec_opts]
42
+ t.rcov = true
43
+ t.rcov_opts = lambda do
44
+ IO.readlines('spec/rcov.opts').map { |l| l.chomp.split(" ") }.flatten
45
+ end
46
+ end
47
+
48
+ desc 'Print Specdoc for all specs'
49
+ Spec::Rake::SpecTask.new(:doc) do |t|
50
+ t.libs << 'spec'
51
+ t.spec_opts = ['--format', 'specdoc', '--dry-run']
52
+ end
53
+
54
+ desc 'Generate HTML report'
55
+ Spec::Rake::SpecTask.new(:html) do |t|
56
+ t.libs << 'spec'
57
+ t.spec_opts = ['--format', 'html:doc/spec_results.html', '--diff']
58
+ t.fail_on_error = false
59
+ end
60
+ end
@@ -0,0 +1,356 @@
1
+ require 'spec_helper'
2
+ require 'active_support/rescuable' # needed for Ruby 1.9.1
3
+ require 'action_controller'
4
+ require 'view_helpers/view_example_group'
5
+ require 'will_paginate/view_helpers/action_view'
6
+ require 'will_paginate/collection'
7
+
8
+ ActionView::Base.send(:include, WillPaginate::ViewHelpers::ActionView)
9
+
10
+ Routes = ActionDispatch::Routing::RouteSet.new
11
+
12
+ Routes.draw do
13
+ match 'dummy/page/:page' => 'dummy#index'
14
+ match 'dummy/dots/page.:page' => 'dummy#dots'
15
+ match 'ibocorp(/:page)' => 'ibocorp#index',
16
+ :constraints => { :page => /\d+/ }, :defaults => { :page => 1 }
17
+
18
+ match ':controller(/:action(/:id(.:format)))'
19
+ end
20
+
21
+ describe WillPaginate::ViewHelpers::ActionView do
22
+ before(:each) do
23
+ @assigns = {}
24
+ @controller = DummyController.new
25
+ @request = @controller.request
26
+ @template = '<%= will_paginate collection, options %>'
27
+ end
28
+
29
+ attr_reader :assigns, :controller, :request
30
+
31
+ def render(locals)
32
+ @view = ActionView::Base.new([], @assigns, @controller)
33
+ @view.request = @request
34
+ @view.singleton_class.send(:include, @controller._routes.url_helpers)
35
+ @view.render(:inline => @template, :locals => locals)
36
+ end
37
+
38
+ ## basic pagination ##
39
+
40
+ it "should render" do
41
+ paginate do |pagination|
42
+ assert_select 'a[href]', 3 do |elements|
43
+ validate_page_numbers [2,3,2], elements
44
+ assert_select elements.last, ':last-child', "Next &#8594;"
45
+ end
46
+ assert_select 'span', 1
47
+ assert_select 'span.disabled:first-child', '&#8592; Previous'
48
+ assert_select 'em', '1'
49
+ pagination.first.inner_text.should == '&#8592; Previous 1 2 3 Next &#8594;'
50
+ end
51
+ end
52
+
53
+ it "should render nothing when there is only 1 page" do
54
+ paginate(:per_page => 30).should be_empty
55
+ end
56
+
57
+ it "should paginate with options" do
58
+ paginate({ :page => 2 }, :class => 'will_paginate', :previous_label => 'Prev', :next_label => 'Next') do
59
+ assert_select 'a[href]', 4 do |elements|
60
+ validate_page_numbers [1,1,3,3], elements
61
+ # test rel attribute values:
62
+ assert_select elements[1], 'a', '1' do |link|
63
+ link.first['rel'].should == 'prev start'
64
+ end
65
+ assert_select elements.first, 'a', "Prev" do |link|
66
+ link.first['rel'].should == 'prev start'
67
+ end
68
+ assert_select elements.last, 'a', "Next" do |link|
69
+ link.first['rel'].should == 'next'
70
+ end
71
+ end
72
+ assert_select 'em', '2'
73
+ end
74
+ end
75
+
76
+ it "should paginate using a custom renderer class" do
77
+ paginate({}, :renderer => AdditionalLinkAttributesRenderer) do
78
+ assert_select 'a[default=true]', 3
79
+ end
80
+ end
81
+
82
+ it "should paginate using a custom renderer instance" do
83
+ renderer = WillPaginate::ViewHelpers::LinkRenderer.new
84
+ def renderer.gap() '<span class="my-gap">~~</span>' end
85
+
86
+ paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0, :renderer => renderer) do
87
+ assert_select 'span.my-gap', '~~'
88
+ end
89
+
90
+ renderer = AdditionalLinkAttributesRenderer.new(:title => 'rendered')
91
+ paginate({}, :renderer => renderer) do
92
+ assert_select 'a[title=rendered]', 3
93
+ end
94
+ end
95
+
96
+ it "should have classnames on previous/next links" do
97
+ paginate do |pagination|
98
+ assert_select 'span.disabled.previous_page:first-child'
99
+ assert_select 'a.next_page[href]:last-child'
100
+ end
101
+ end
102
+
103
+ it "should warn about :prev_label being deprecated" do
104
+ lambda {
105
+ paginate({ :page => 2 }, :prev_label => 'Deprecated') do
106
+ assert_select 'a[href]:first-child', 'Deprecated'
107
+ end
108
+ }.should have_deprecation
109
+ end
110
+
111
+ it "should match expected markup" do
112
+ paginate
113
+ expected = <<-HTML
114
+ <div class="pagination"><span class="previous_page disabled">&#8592; Previous</span>
115
+ <em>1</em>
116
+ <a href="/foo/bar?page=2" rel="next">2</a>
117
+ <a href="/foo/bar?page=3">3</a>
118
+ <a href="/foo/bar?page=2" class="next_page" rel="next">Next &#8594;</a></div>
119
+ HTML
120
+ expected.strip!.gsub!(/\s{2,}/, ' ')
121
+ expected_dom = HTML::Document.new(expected).root
122
+
123
+ html_document.root.should == expected_dom
124
+ end
125
+
126
+ it "should output escaped URLs" do
127
+ paginate({:page => 1, :per_page => 1, :total_entries => 2},
128
+ :page_links => false, :params => { :tag => '<br>' })
129
+
130
+ assert_select 'a[href]', 1 do |links|
131
+ query = links.first['href'].split('?', 2)[1]
132
+ query.split('&amp;').sort.should == %w(page=2 tag=%3Cbr%3E)
133
+ end
134
+ end
135
+
136
+ ## advanced options for pagination ##
137
+
138
+ it "should be able to render without container" do
139
+ paginate({}, :container => false)
140
+ assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t'
141
+ assert_select 'a[href]', 3
142
+ end
143
+
144
+ it "should be able to render without page links" do
145
+ paginate({ :page => 2 }, :page_links => false) do
146
+ assert_select 'a[href]', 2 do |elements|
147
+ validate_page_numbers [1,3], elements
148
+ end
149
+ end
150
+ end
151
+
152
+ it "should have magic HTML ID for the container" do
153
+ paginate do |div|
154
+ div.first['id'].should be_nil
155
+ end
156
+
157
+ # magic ID
158
+ paginate({}, :id => true) do |div|
159
+ div.first['id'].should == 'fixnums_pagination'
160
+ end
161
+
162
+ # explicit ID
163
+ paginate({}, :id => 'custom_id') do |div|
164
+ div.first['id'].should == 'custom_id'
165
+ end
166
+ end
167
+
168
+ ## other helpers ##
169
+
170
+ it "should render a paginated section" do
171
+ @template = <<-ERB
172
+ <%= paginated_section collection, options do %>
173
+ <%= content_tag :div, '', :id => "developers" %>
174
+ <% end %>
175
+ ERB
176
+
177
+ paginate
178
+ assert_select 'div.pagination', 2
179
+ assert_select 'div.pagination + div#developers', 1
180
+ end
181
+
182
+ ## parameter handling in page links ##
183
+
184
+ it "should preserve parameters on GET" do
185
+ request.params :foo => { :bar => 'baz' }
186
+ paginate
187
+ assert_links_match /foo\[bar\]=baz/
188
+ end
189
+
190
+ it "should not preserve parameters on POST" do
191
+ request.post
192
+ request.params :foo => 'bar'
193
+ paginate
194
+ assert_no_links_match /foo=bar/
195
+ end
196
+
197
+ it "should add additional parameters to links" do
198
+ paginate({}, :params => { :foo => 'bar' })
199
+ assert_links_match /foo=bar/
200
+ end
201
+
202
+ it "should add anchor parameter" do
203
+ paginate({}, :params => { :anchor => 'anchor' })
204
+ assert_links_match /#anchor$/
205
+ end
206
+
207
+ it "should remove arbitrary parameters" do
208
+ request.params :foo => 'bar'
209
+ paginate({}, :params => { :foo => nil })
210
+ assert_no_links_match /foo=bar/
211
+ end
212
+
213
+ it "should override default route parameters" do
214
+ paginate({}, :params => { :controller => 'baz', :action => 'list' })
215
+ assert_links_match %r{\Wbaz/list\W}
216
+ end
217
+
218
+ it "should paginate with custom page parameter" do
219
+ paginate({ :page => 2 }, :param_name => :developers_page) do
220
+ assert_select 'a[href]', 4 do |elements|
221
+ validate_page_numbers [1,1,3,3], elements, :developers_page
222
+ end
223
+ end
224
+ end
225
+
226
+ it "should paginate with complex custom page parameter" do
227
+ request.params :developers => { :page => 2 }
228
+
229
+ paginate({ :page => 2 }, :param_name => 'developers[page]') do
230
+ assert_select 'a[href]', 4 do |links|
231
+ assert_links_match /\?developers\[page\]=\d+$/, links
232
+ validate_page_numbers [1,1,3,3], links, 'developers[page]'
233
+ end
234
+ end
235
+ end
236
+
237
+ it "should paginate with custom route page parameter" do
238
+ request.symbolized_path_parameters.update :controller => 'dummy', :action => nil
239
+ paginate :per_page => 2 do
240
+ assert_select 'a[href]', 6 do |links|
241
+ assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
242
+ end
243
+ end
244
+ end
245
+
246
+ it "should paginate with custom route with dot separator page parameter" do
247
+ request.symbolized_path_parameters.update :controller => 'dummy', :action => 'dots'
248
+ paginate :per_page => 2 do
249
+ assert_select 'a[href]', 6 do |links|
250
+ assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2]
251
+ end
252
+ end
253
+ end
254
+
255
+ it "should paginate with custom route and first page number implicit" do
256
+ request.symbolized_path_parameters.update :controller => 'ibocorp', :action => nil
257
+ paginate :page => 2, :per_page => 2 do
258
+ assert_select 'a[href]', 7 do |links|
259
+ assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5, 6, 3]
260
+ end
261
+ end
262
+ # Routes.recognize_path('/ibocorp/2').should == {:page=>'2', :action=>'index', :controller=>'ibocorp'}
263
+ # Routes.recognize_path('/ibocorp/foo').should == {:action=>'foo', :controller=>'ibocorp'}
264
+ end
265
+
266
+ ## internal hardcore stuff ##
267
+
268
+ it "should be able to guess the collection name" do
269
+ collection = mock
270
+ collection.expects(:total_pages).returns(1)
271
+
272
+ @template = '<%= will_paginate options %>'
273
+ controller.controller_name = 'developers'
274
+ assigns['developers'] = collection
275
+
276
+ paginate(nil)
277
+ end
278
+
279
+ it "should fail if the inferred collection is nil" do
280
+ @template = '<%= will_paginate options %>'
281
+ controller.controller_name = 'developers'
282
+
283
+ lambda {
284
+ paginate(nil)
285
+ }.should raise_error(ActionView::TemplateError, /@developers/)
286
+ end
287
+ end
288
+
289
+ class AdditionalLinkAttributesRenderer < WillPaginate::ViewHelpers::LinkRenderer
290
+ def initialize(link_attributes = nil)
291
+ super()
292
+ @additional_link_attributes = link_attributes || { :default => 'true' }
293
+ end
294
+
295
+ def link(text, target, attributes = {})
296
+ super(text, target, attributes.merge(@additional_link_attributes))
297
+ end
298
+ end
299
+
300
+ class DummyController
301
+ attr_reader :request
302
+ attr_accessor :controller_name
303
+
304
+ include ActionController::UrlFor
305
+ include Routes.url_helpers
306
+
307
+ def initialize
308
+ @request = DummyRequest.new
309
+ end
310
+
311
+ def params
312
+ @request.params
313
+ end
314
+ end
315
+
316
+ class IbocorpController < DummyController
317
+ end
318
+
319
+ class DummyRequest
320
+ attr_accessor :symbolized_path_parameters
321
+
322
+ def initialize
323
+ @get = true
324
+ @params = {}
325
+ @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
326
+ end
327
+
328
+ def get?
329
+ @get
330
+ end
331
+
332
+ def post
333
+ @get = false
334
+ end
335
+
336
+ def relative_url_root
337
+ ''
338
+ end
339
+
340
+ def script_name
341
+ ''
342
+ end
343
+
344
+ def params(more = nil)
345
+ @params.update(more) if more
346
+ @params
347
+ end
348
+
349
+ def host_with_port
350
+ 'example.com'
351
+ end
352
+
353
+ def protocol
354
+ 'http:'
355
+ end
356
+ end