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 +1 -1
- data/lib/will_paginate/finder.rb +3 -3
- data/lib/will_paginate/version.rb +1 -1
- data/test/boot.rb +2 -2
- data/test/finder_test.rb +25 -2
- data/test/fixtures/project.rb +2 -0
- data/test/fixtures/topic.rb +2 -0
- data/test/lib/activerecord_test_connector.rb +2 -1
- metadata +4 -4
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
|
-
|
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
|
data/lib/will_paginate/finder.rb
CHANGED
@@ -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(
|
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:
|
data/test/boot.rb
CHANGED
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
|
data/test/fixtures/project.rb
CHANGED
data/test/fixtures/topic.rb
CHANGED
@@ -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.
|
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
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-
|
19
|
+
date: 2010-09-09 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|