will_paginate 2.3.14 → 2.3.15

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.

Potentially problematic release.


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

data/lib/will_paginate.rb CHANGED
@@ -36,7 +36,7 @@ module WillPaginate
36
36
 
37
37
  # support pagination on associations
38
38
  a = ActiveRecord::Associations
39
- returning([ a::AssociationCollection ]) { |classes|
39
+ [ a::AssociationCollection ].tap { |classes|
40
40
  # detect http://dev.rubyonrails.org/changeset/9230
41
41
  unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
42
42
  classes << a::HasManyThroughAssociation
@@ -155,7 +155,7 @@ module WillPaginate
155
155
  when :paginate, :paginate_by_sql
156
156
  true
157
157
  else
158
- super(method.to_s.sub(/^paginate/, 'find'), include_priv)
158
+ super || super(method.to_s.sub(/^paginate/, 'find'), include_priv)
159
159
  end
160
160
  end
161
161
 
@@ -198,7 +198,7 @@ module WillPaginate
198
198
 
199
199
  if options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
200
200
  # Remove quoting and check for table_name.*-like statement.
201
- if options[:select].gsub('`', '') =~ /\w+\.\*/
201
+ if options[:select].gsub(/[`"]/, '') =~ /\w+\.\*/
202
202
  options[:select] = "DISTINCT #{klass.table_name}.#{klass.primary_key}"
203
203
  end
204
204
  else
@@ -235,7 +235,7 @@ module WillPaginate
235
235
  counter.call
236
236
  end
237
237
 
238
- count.respond_to?(:length) ? count.length : count
238
+ (!count.is_a?(Integer) && count.respond_to?(:length)) ? count.length : count
239
239
  end
240
240
 
241
241
  def wp_parse_options(options) #:nodoc:
@@ -2,7 +2,7 @@ module WillPaginate
2
2
  module VERSION
3
3
  MAJOR = 2
4
4
  MINOR = 3
5
- TINY = 14
5
+ TINY = 15
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/boot.rb CHANGED
@@ -15,7 +15,7 @@ else
15
15
  if version
16
16
  gem 'rails', version
17
17
  else
18
- gem 'actionpack'
19
- gem 'activerecord'
18
+ gem 'actionpack', '< 3.0.0.a'
19
+ gem 'activerecord', '< 3.0.0.a'
20
20
  end
21
21
  end
data/test/finder_test.rb CHANGED
@@ -9,7 +9,7 @@ class FinderTest < ActiveRecordTestCase
9
9
  fixtures :topics, :replies, :users, :projects, :developers_projects
10
10
 
11
11
  def test_new_methods_presence
12
- assert_respond_to_all Topic, %w(per_page paginate paginate_by_sql)
12
+ assert_respond_to_all Topic, %w(per_page paginate paginate_by_sql paginate_by_definition_in_class)
13
13
  end
14
14
 
15
15
  def test_simple_paginate
@@ -39,6 +39,22 @@ class FinderTest < ActiveRecordTestCase
39
39
  assert_nothing_raised { Topic.paginate :page => 1, :count => nil }
40
40
  end
41
41
 
42
+ def test_counting_when_integer_has_length_method
43
+ Integer.module_eval { def length; to_s.length; end }
44
+ begin
45
+ assert_equal 2, 11.length
46
+ entries = Developer.paginate :page => 1, :per_page => 5
47
+ assert_equal 11, entries.total_entries
48
+ assert_equal 5, entries.size
49
+ assert_equal 3, entries.total_pages
50
+ ensure
51
+ begin
52
+ Integer.module_eval { remove_method :length }
53
+ rescue
54
+ end
55
+ end
56
+ end
57
+
42
58
  def test_paginate_with_per_page
43
59
  entries = Topic.paginate :page => 1, :per_page => 1
44
60
  assert_equal 1, entries.size
@@ -197,7 +213,7 @@ class FinderTest < ActiveRecordTestCase
197
213
 
198
214
  def test_paginate_with_dynamic_finder
199
215
  expected = [replies(:witty_retort), replies(:spam)]
200
- assert_equal expected, Reply.paginate_by_topic_id(1, :page => 1)
216
+ assert_equal expected, Reply.paginate_by_topic_id(1, :page => 1, :order => :created_at)
201
217
 
202
218
  entries = Developer.paginate :conditions => { :salary => 100000 }, :page => 1, :per_page => 5
203
219
  assert_equal 8, entries.total_entries
@@ -469,5 +485,12 @@ class FinderTest < ActiveRecordTestCase
469
485
 
470
486
  # I cannot reproduce any of the failures from those reports :(
471
487
  end
488
+
489
+ def test_hmt_with_uniq
490
+ project = Project.find(1)
491
+ result = project.unique_replies.paginate :page => 1, :per_page => 1,
492
+ :order => 'replies.id'
493
+ assert_equal replies(:decisive), result.first
494
+ end
472
495
  end
473
496
  end
@@ -12,4 +12,6 @@ class Project < ActiveRecord::Base
12
12
  end
13
13
  end
14
14
  end
15
+
16
+ has_many :unique_replies, :through => :topics, :source => :replies, :uniq => true
15
17
  end
@@ -7,4 +7,6 @@ class Topic < ActiveRecord::Base
7
7
  named_scope :with_replies_starting_with, lambda { |text|
8
8
  { :conditions => "replies.content LIKE '#{text}%' ", :include => :replies }
9
9
  }
10
+
11
+ def self.paginate_by_definition_in_class; end
10
12
  end
@@ -28,7 +28,8 @@ class ActiveRecordTestConnector
28
28
 
29
29
  def self.add_load_path(path)
30
30
  dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
31
- dep.load_paths.unshift path
31
+ autoload_paths = dep.respond_to?(:autoload_paths) ? dep.autoload_paths : dep.load_paths
32
+ autoload_paths.unshift path
32
33
  end
33
34
 
34
35
  def self.setup_connection
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 14
10
- version: 2.3.14
9
+ - 15
10
+ version: 2.3.15
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Mislav Marohni\xC4\x87"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-05-26 00:00:00 +02:00
19
+ date: 2010-09-09 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies: []
22
22