mislav-will_paginate 2.3.8 → 2.3.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,7 @@ module WillPaginate
17
17
 
18
18
  # hooks WillPaginate::ViewHelpers into ActionView::Base
19
19
  def enable_actionpack
20
- return if ActionView::Base.instance_methods.include? 'will_paginate'
20
+ return if ActionView::Base.instance_methods.include_method? :will_paginate
21
21
  require 'will_paginate/view_helpers'
22
22
  ActionView::Base.send :include, ViewHelpers
23
23
 
@@ -44,6 +44,16 @@ module WillPaginate
44
44
  klass.send :include, Finder::ClassMethods
45
45
  klass.class_eval { alias_method_chain :method_missing, :paginate }
46
46
  end
47
+
48
+ # monkeypatch Rails ticket #2189: "count breaks has_many :through"
49
+ ActiveRecord::Base.class_eval do
50
+ protected
51
+ def self.construct_count_options_from_args(*args)
52
+ result = super
53
+ result[0] = '*' if result[0].is_a?(String) and result[0] =~ /\.\*$/
54
+ result
55
+ end
56
+ end
47
57
  end
48
58
 
49
59
  # Enable named_scope, a feature of Rails 2.1, even if you have older Rails
@@ -73,6 +83,7 @@ module WillPaginate
73
83
  end
74
84
  end
75
85
 
76
- if defined?(Rails) and defined?(ActiveRecord) and defined?(ActionController)
77
- WillPaginate.enable
86
+ if defined? Rails
87
+ WillPaginate.enable_activerecord if defined? ActiveRecord
88
+ WillPaginate.enable_actionpack if defined? ActionController
78
89
  end
@@ -1,7 +1,18 @@
1
1
  require 'set'
2
2
  require 'will_paginate/array'
3
3
 
4
- unless Hash.instance_methods.include? 'except'
4
+ # helper to check for method existance in ruby 1.8- and 1.9-compatible way
5
+ # because `methods`, `instance_methods` and others return strings in 1.8 and symbols in 1.9
6
+ #
7
+ # ['foo', 'bar'].include_method?(:foo) # => true
8
+ class Array
9
+ def include_method?(name)
10
+ name = name.to_sym
11
+ !!(find { |item| item.to_sym == name })
12
+ end
13
+ end
14
+
15
+ unless Hash.instance_methods.include_method? :except
5
16
  Hash.class_eval do
6
17
  # Returns a new hash without the given keys.
7
18
  def except(*keys)
@@ -16,7 +27,7 @@ unless Hash.instance_methods.include? 'except'
16
27
  end
17
28
  end
18
29
 
19
- unless Hash.instance_methods.include? 'slice'
30
+ unless Hash.instance_methods.include_method? :slice
20
31
  Hash.class_eval do
21
32
  # Returns a new hash with only the given keys.
22
33
  def slice(*keys)
@@ -141,7 +141,7 @@ module WillPaginate
141
141
  count_query = original_query.sub /\bORDER\s+BY\s+[\w`,\s]+$/mi, ''
142
142
  count_query = "SELECT COUNT(*) FROM (#{count_query})"
143
143
 
144
- unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase)
144
+ unless self.connection.adapter_name =~ /^(oracle|oci$)/i
145
145
  count_query << ' AS count_table'
146
146
  end
147
147
  # perform the count query
@@ -214,7 +214,7 @@ module WillPaginate
214
214
 
215
215
  # forget about includes if they are irrelevant (Rails 2.1)
216
216
  if count_options[:include] and
217
- klass.private_methods.include?('references_eager_loaded_tables?') and
217
+ klass.private_methods.include_method?(:references_eager_loaded_tables?) and
218
218
  !klass.send(:references_eager_loaded_tables?, count_options)
219
219
  count_options.delete :include
220
220
  end
@@ -2,7 +2,7 @@ module WillPaginate
2
2
  module VERSION
3
3
  MAJOR = 2
4
4
  MINOR = 3
5
- TINY = 8
5
+ TINY = 10
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -332,21 +332,21 @@ module WillPaginate
332
332
  return url if page_one
333
333
 
334
334
  if complex
335
- @url_string = url.sub(%r!((?:\?|&amp;)#{CGI.escape param_name}=)#{page}!, '\1@')
335
+ @url_string = url.sub(%r!((?:\?|&amp;)#{CGI.escape param_name}=)#{page}!, "\\1\0")
336
336
  return url
337
337
  else
338
338
  @url_string = url
339
339
  @url_params[param_name] = 3
340
340
  @template.url_for(@url_params).split(//).each_with_index do |char, i|
341
341
  if char == '3' and url[i, 1] == '2'
342
- @url_string[i] = '@'
342
+ @url_string[i] = "\0"
343
343
  break
344
344
  end
345
345
  end
346
346
  end
347
347
  end
348
348
  # finally!
349
- @url_string.sub '@', page.to_s
349
+ @url_string.sub "\0", page.to_s
350
350
  end
351
351
 
352
352
  private
@@ -386,16 +386,18 @@ module WillPaginate
386
386
  end
387
387
 
388
388
  def parse_query_parameters(params)
389
- if defined?(CGIMethods)
390
- CGIMethods.parse_query_parameters(params)
389
+ if defined? Rack::Utils
390
+ # For Rails > 2.3
391
+ Rack::Utils.parse_nested_query(params)
391
392
  elsif defined?(ActionController::AbstractRequest)
392
393
  ActionController::AbstractRequest.parse_query_parameters(params)
393
394
  elsif defined?(ActionController::UrlEncodedPairParser)
394
395
  # For Rails > 2.2
395
396
  ActionController::UrlEncodedPairParser.parse_query_parameters(params)
397
+ elsif defined?(CGIMethods)
398
+ CGIMethods.parse_query_parameters(params)
396
399
  else
397
- # For Rails > 2.3
398
- Rack::Utils.parse_nested_query(params)
400
+ raise "unsupported ActionPack version"
399
401
  end
400
402
  end
401
403
  end
@@ -284,11 +284,11 @@ class FinderTest < ActiveRecordTestCase
284
284
  # this functionality is temporarily removed
285
285
  def xtest_pagination_defines_method
286
286
  pager = "paginate_by_created_at"
287
- assert !User.methods.include?(pager), "User methods should not include `#{pager}` method"
287
+ assert !User.methods.include_method?(pager), "User methods should not include `#{pager}` method"
288
288
  # paginate!
289
289
  assert 0, User.send(pager, nil, :page => 1).total_entries
290
290
  # the paging finder should now be defined
291
- assert User.methods.include?(pager), "`#{pager}` method should be defined on User"
291
+ assert User.methods.include_method?(pager), "`#{pager}` method should be defined on User"
292
292
  end
293
293
 
294
294
  # Is this Rails 2.0? Find out by testing find_all which was removed in [6998]
@@ -361,18 +361,15 @@ class FinderTest < ActiveRecordTestCase
361
361
  end
362
362
 
363
363
  def test_paginate_by_sql
364
- assert_respond_to Developer, :paginate_by_sql
365
- Developer.expects(:find_by_sql).with(regexp_matches(/sql LIMIT 3(,| OFFSET) 3/)).returns([])
366
- Developer.expects(:count_by_sql).with('SELECT COUNT(*) FROM (sql) AS count_table').returns(0)
367
-
368
- entries = Developer.paginate_by_sql 'sql', :page => 2, :per_page => 3
364
+ sql = "SELECT * FROM users WHERE type = 'Developer' ORDER BY id"
365
+ entries = Developer.paginate_by_sql(sql, :page => 2, :per_page => 3)
366
+ assert_equal 11, entries.total_entries
367
+ assert_equal [users(:dev_4), users(:dev_5), users(:dev_6)], entries
369
368
  end
370
369
 
371
370
  def test_paginate_by_sql_respects_total_entries_setting
372
- Developer.expects(:find_by_sql).returns([])
373
- Developer.expects(:count_by_sql).never
374
-
375
- entries = Developer.paginate_by_sql 'sql', :page => 1, :total_entries => 999
371
+ sql = "SELECT * FROM users"
372
+ entries = Developer.paginate_by_sql(sql, :page => 1, :total_entries => 999)
376
373
  assert_equal 999, entries.total_entries
377
374
  end
378
375
 
@@ -440,7 +437,7 @@ class FinderTest < ActiveRecordTestCase
440
437
  end
441
438
 
442
439
  # detect ActiveRecord 2.1
443
- if ActiveRecord::Base.private_methods.include?('references_eager_loaded_tables?')
440
+ if ActiveRecord::Base.private_methods.include_method?(:references_eager_loaded_tables?)
444
441
  def test_removes_irrelevant_includes_in_count
445
442
  Developer.expects(:find).returns([1])
446
443
  Developer.expects(:count).with({}).returns(0)
@@ -1,3 +1,4 @@
1
+ require 'will_paginate/core_ext'
1
2
  require 'action_controller'
2
3
  require 'action_controller/test_process'
3
4
 
@@ -35,7 +35,7 @@ task :test_full => %w(test test_mysql test_postgres)
35
35
  desc %{Test everything with Rails 2.1.x, 2.0.x & 1.2.x gems}
36
36
  task :test_all do
37
37
  all = Rake::Task['test_full']
38
- versions = %w(2.1.0 2.0.4 1.2.6)
38
+ versions = %w(2.3.2 2.2.2 2.1.0 2.0.4 1.2.6)
39
39
  versions.each do |version|
40
40
  ENV['RAILS_VERSION'] = "~> #{version}"
41
41
  all.invoke
@@ -277,6 +277,14 @@ class ViewTest < WillPaginate::ViewTestCase
277
277
  end
278
278
  end
279
279
  end
280
+
281
+ def test_will_paginate_with_atmark_url
282
+ @request.symbolized_path_parameters[:action] = "@tag"
283
+ renderer = WillPaginate::LinkRenderer.new
284
+
285
+ paginate({ :page => 1 }, :renderer=>renderer)
286
+ assert_links_match %r[/foo/@tag\?page=\d]
287
+ end
280
288
 
281
289
  def test_complex_custom_page_param
282
290
  @request.params :developers => { :page => 2 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mislav-will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.8
4
+ version: 2.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Mislav Marohni\xC4\x87"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-03-09 00:00:00 -07:00
13
+ date: 2009-05-21 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16