decisiv-will_paginate 2.3.6.1 → 2.3.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -13
- data/lib/will_paginate.rb +1 -5
- data/lib/will_paginate/collection.rb +1 -1
- data/lib/will_paginate/finder.rb +11 -7
- data/lib/will_paginate/named_scope.rb +6 -6
- data/lib/will_paginate/named_scope_patch.rb +7 -7
- data/lib/will_paginate/version.rb +1 -1
- data/lib/will_paginate/view_helpers.rb +18 -6
- data/test/helper.rb +4 -1
- data/test/lib/activerecord_test_case.rb +7 -0
- data/test/lib/view_test_process.rb +7 -0
- metadata +2 -10
data/Rakefile
CHANGED
@@ -32,18 +32,9 @@ desc %{Update ".manifest" with the latest list of project filenames. Respect\
|
|
32
32
|
.gitignore by excluding everything that git ignores. Update `files` and\
|
33
33
|
`test_files` arrays in "*.gemspec" file if it's present.}
|
34
34
|
task :manifest do
|
35
|
-
list =
|
36
|
-
spec_file = Dir['*.gemspec'].first
|
37
|
-
list -= [spec_file] if spec_file
|
35
|
+
list = `git ls-files --full-name --exclude=*.gemspec --exclude=.*`.chomp.split("\n")
|
38
36
|
|
39
|
-
|
40
|
-
glob = glob.chomp.sub(/^\//, '')
|
41
|
-
list -= Dir[glob]
|
42
|
-
list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
|
43
|
-
puts "excluding #{glob}"
|
44
|
-
end
|
45
|
-
|
46
|
-
if spec_file
|
37
|
+
if spec_file = Dir['*.gemspec'].first
|
47
38
|
spec = File.read spec_file
|
48
39
|
spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
|
49
40
|
assignment = $1
|
@@ -51,9 +42,9 @@ task :manifest do
|
|
51
42
|
'%s%%w(%s)' % [assignment, bunch.join(' ')]
|
52
43
|
end
|
53
44
|
|
54
|
-
File.open(spec_file,
|
45
|
+
File.open(spec_file, 'w') { |f| f << spec }
|
55
46
|
end
|
56
|
-
File.open('.manifest', 'w') {|f| f << list.join("\n") }
|
47
|
+
File.open('.manifest', 'w') { |f| f << list.join("\n") }
|
57
48
|
end
|
58
49
|
|
59
50
|
task :examples do
|
data/lib/will_paginate.rb
CHANGED
@@ -68,11 +68,7 @@ module WillPaginate
|
|
68
68
|
|
69
69
|
def self.warn(message, callstack = caller)
|
70
70
|
message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.silenced?
|
75
|
-
ActiveSupport::Deprecation.silenced?
|
71
|
+
ActiveSupport::Deprecation.warn(message, callstack)
|
76
72
|
end
|
77
73
|
end
|
78
74
|
end
|
@@ -82,7 +82,7 @@ module WillPaginate
|
|
82
82
|
#
|
83
83
|
# The Array#paginate API has since then changed, but this still serves as a
|
84
84
|
# fine example of WillPaginate::Collection usage.
|
85
|
-
def self.create(page, per_page, total = nil
|
85
|
+
def self.create(page, per_page, total = nil)
|
86
86
|
pager = new(page, per_page, total)
|
87
87
|
yield pager
|
88
88
|
pager
|
data/lib/will_paginate/finder.rb
CHANGED
@@ -61,7 +61,7 @@ module WillPaginate
|
|
61
61
|
#
|
62
62
|
# All other options (+conditions+, +order+, ...) are forwarded to +find+
|
63
63
|
# and +count+ calls.
|
64
|
-
def paginate(*args
|
64
|
+
def paginate(*args)
|
65
65
|
options = args.pop
|
66
66
|
page, per_page, total_entries = wp_parse_options(options)
|
67
67
|
finder = (options[:finder] || 'find').to_s
|
@@ -79,7 +79,7 @@ module WillPaginate
|
|
79
79
|
|
80
80
|
args << find_options
|
81
81
|
# @options_from_last_find = nil
|
82
|
-
pager.replace
|
82
|
+
pager.replace(send(finder, *args) { |*a| yield(*a) if block_given? })
|
83
83
|
|
84
84
|
# magic counting for user convenience:
|
85
85
|
pager.total_entries = wp_count(count_options, args, finder) unless pager.total_entries
|
@@ -96,7 +96,7 @@ module WillPaginate
|
|
96
96
|
#
|
97
97
|
# See {Faking Cursors in ActiveRecord}[http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord]
|
98
98
|
# where Jamis Buck describes this and a more efficient way for MySQL.
|
99
|
-
def paginated_each(options = {}
|
99
|
+
def paginated_each(options = {})
|
100
100
|
options = { :order => 'id', :page => 1 }.merge options
|
101
101
|
options[:page] = options[:page].to_i
|
102
102
|
options[:total_entries] = 0 # skip the individual count queries
|
@@ -106,7 +106,7 @@ module WillPaginate
|
|
106
106
|
collection = paginate(options)
|
107
107
|
with_exclusive_scope(:find => {}) do
|
108
108
|
# using exclusive scope so that the block is yielded in scope-free context
|
109
|
-
total += collection.each
|
109
|
+
total += collection.each { |item| yield item }.size
|
110
110
|
end
|
111
111
|
options[:page] += 1
|
112
112
|
end until collection.size < collection.per_page
|
@@ -161,10 +161,14 @@ module WillPaginate
|
|
161
161
|
|
162
162
|
protected
|
163
163
|
|
164
|
-
def method_missing_with_paginate(method, *args
|
164
|
+
def method_missing_with_paginate(method, *args) #:nodoc:
|
165
165
|
# did somebody tried to paginate? if not, let them be
|
166
166
|
unless method.to_s.index('paginate') == 0
|
167
|
-
|
167
|
+
if block_given?
|
168
|
+
return method_missing_without_paginate(method, *args) { |*a| yield(*a) }
|
169
|
+
else
|
170
|
+
return method_missing_without_paginate(method, *args)
|
171
|
+
end
|
168
172
|
end
|
169
173
|
|
170
174
|
# paginate finders are really just find_* with limit and offset
|
@@ -177,7 +181,7 @@ module WillPaginate
|
|
177
181
|
options[:finder] = finder
|
178
182
|
args << options
|
179
183
|
|
180
|
-
paginate(*args
|
184
|
+
paginate(*args) { |*a| yield(*a) if block_given? }
|
181
185
|
end
|
182
186
|
|
183
187
|
# Does the not-so-trivial job of finding out the total number of entries
|
@@ -83,7 +83,7 @@ module WillPaginate
|
|
83
83
|
#
|
84
84
|
# expected_options = { :conditions => { :colored => 'red' } }
|
85
85
|
# assert_equal expected_options, Shirt.colored('red').proxy_options
|
86
|
-
def named_scope(name, options = {}
|
86
|
+
def named_scope(name, options = {})
|
87
87
|
name = name.to_sym
|
88
88
|
scopes[name] = lambda do |parent_scope, *args|
|
89
89
|
Scope.new(parent_scope, case options
|
@@ -91,7 +91,7 @@ module WillPaginate
|
|
91
91
|
options
|
92
92
|
when Proc
|
93
93
|
options.call(*args)
|
94
|
-
end
|
94
|
+
end) { |*a| yield(*a) if block_given? }
|
95
95
|
end
|
96
96
|
(class << self; self end).instance_eval do
|
97
97
|
define_method name do |*args|
|
@@ -112,9 +112,9 @@ module WillPaginate
|
|
112
112
|
|
113
113
|
delegate :scopes, :with_scope, :to => :proxy_scope
|
114
114
|
|
115
|
-
def initialize(proxy_scope, options
|
115
|
+
def initialize(proxy_scope, options)
|
116
116
|
[options[:extend]].flatten.each { |extension| extend extension } if options[:extend]
|
117
|
-
extend Module.new(
|
117
|
+
extend Module.new { |*args| yield(*args) } if block_given?
|
118
118
|
@proxy_scope, @proxy_options = proxy_scope, options.except(:extend)
|
119
119
|
end
|
120
120
|
|
@@ -152,12 +152,12 @@ module WillPaginate
|
|
152
152
|
end
|
153
153
|
|
154
154
|
private
|
155
|
-
def method_missing(method, *args
|
155
|
+
def method_missing(method, *args)
|
156
156
|
if scopes.include?(method)
|
157
157
|
scopes[method].call(self, *args)
|
158
158
|
else
|
159
159
|
with_scope :find => proxy_options do
|
160
|
-
proxy_scope.send(method, *args
|
160
|
+
proxy_scope.send(method, *args) { |*a| yield(*a) if block_given? }
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
ActiveRecord::Associations::AssociationProxy.class_eval do
|
2
2
|
protected
|
3
|
-
def with_scope(*args
|
4
|
-
@reflection.klass.send
|
3
|
+
def with_scope(*args)
|
4
|
+
@reflection.klass.send(:with_scope, *args) { |*a| yield(*a) if block_given? }
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -10,11 +10,11 @@ end
|
|
10
10
|
klass.class_eval do
|
11
11
|
protected
|
12
12
|
alias :method_missing_without_scopes :method_missing_without_paginate
|
13
|
-
def method_missing_without_paginate(method, *args
|
13
|
+
def method_missing_without_paginate(method, *args)
|
14
14
|
if @reflection.klass.scopes.include?(method)
|
15
|
-
@reflection.klass.scopes[method].call(self, *args
|
15
|
+
@reflection.klass.scopes[method].call(self, *args) { |*a| yield(*a) if block_given? }
|
16
16
|
else
|
17
|
-
method_missing_without_scopes(method, *args
|
17
|
+
method_missing_without_scopes(method, *args) { |*a| yield(*a) if block_given? }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -23,14 +23,14 @@ end
|
|
23
23
|
# Rails 1.2.6
|
24
24
|
ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
|
25
25
|
protected
|
26
|
-
def method_missing(method, *args
|
26
|
+
def method_missing(method, *args)
|
27
27
|
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
|
28
28
|
super
|
29
29
|
elsif @reflection.klass.scopes.include?(method)
|
30
30
|
@reflection.klass.scopes[method].call(self, *args)
|
31
31
|
else
|
32
32
|
@reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do
|
33
|
-
@reflection.klass.send(method, *args
|
33
|
+
@reflection.klass.send(method, *args) { |*a| yield(*a) if block_given? }
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -99,7 +99,7 @@ module WillPaginate
|
|
99
99
|
|
100
100
|
options = options.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options
|
101
101
|
if options[:prev_label]
|
102
|
-
WillPaginate::Deprecation::warn(":prev_label view parameter is now :previous_label; the old name has been deprecated
|
102
|
+
WillPaginate::Deprecation::warn(":prev_label view parameter is now :previous_label; the old name has been deprecated", caller)
|
103
103
|
options[:previous_label] = options.delete(:prev_label)
|
104
104
|
end
|
105
105
|
|
@@ -185,12 +185,11 @@ module WillPaginate
|
|
185
185
|
|
186
186
|
def self.total_pages_for_collection(collection) #:nodoc:
|
187
187
|
if collection.respond_to?('page_count') and !collection.respond_to?('total_pages')
|
188
|
-
WillPaginate::Deprecation.warn
|
188
|
+
WillPaginate::Deprecation.warn %{
|
189
189
|
You are using a paginated collection of class #{collection.class.name}
|
190
190
|
which conforms to the old API of WillPaginate::Collection by using
|
191
191
|
`page_count`, while the current method name is `total_pages`. Please
|
192
|
-
upgrade yours or 3rd-party code that provides the paginated collection
|
193
|
-
MSG
|
192
|
+
upgrade yours or 3rd-party code that provides the paginated collection}, caller
|
194
193
|
class << collection
|
195
194
|
def total_pages; page_count; end
|
196
195
|
end
|
@@ -322,8 +321,7 @@ module WillPaginate
|
|
322
321
|
stringified_merge @url_params, @options[:params] if @options[:params]
|
323
322
|
|
324
323
|
if complex = param_name.index(/[^\w-]/)
|
325
|
-
page_param = (
|
326
|
-
parse_query_parameters("#{param_name}=#{page}")
|
324
|
+
page_param = parse_query_parameters("#{param_name}=#{page}")
|
327
325
|
|
328
326
|
stringified_merge @url_params, page_param
|
329
327
|
else
|
@@ -386,5 +384,19 @@ module WillPaginate
|
|
386
384
|
end
|
387
385
|
end
|
388
386
|
end
|
387
|
+
|
388
|
+
def parse_query_parameters(params)
|
389
|
+
if defined?(CGIMethods)
|
390
|
+
CGIMethods.parse_query_parameters(params)
|
391
|
+
elsif defined?(ActionController::AbstractRequest)
|
392
|
+
ActionController::AbstractRequest.parse_query_parameters(params)
|
393
|
+
elsif defined?(ActionController::UrlEncodedPairParser)
|
394
|
+
# For Rails > 2.2
|
395
|
+
ActionController::UrlEncodedPairParser.parse_query_parameters(params)
|
396
|
+
else
|
397
|
+
# For Rails > 2.3
|
398
|
+
Rack::Utils.parse_nested_query(params)
|
399
|
+
end
|
400
|
+
end
|
389
401
|
end
|
390
402
|
end
|
data/test/helper.rb
CHANGED
@@ -29,7 +29,10 @@ end
|
|
29
29
|
|
30
30
|
# Wrap tests that use Mocha and skip if unavailable.
|
31
31
|
def uses_mocha(test_name)
|
32
|
-
|
32
|
+
unless Object.const_defined?(:Mocha)
|
33
|
+
gem 'mocha', '>= 0.9.5'
|
34
|
+
require 'mocha'
|
35
|
+
end
|
33
36
|
rescue LoadError => load_error
|
34
37
|
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
|
35
38
|
else
|
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'lib/activerecord_test_connector'
|
2
2
|
|
3
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
|
4
11
|
# Set our fixture path
|
5
12
|
if ActiveRecordTestConnector.able_to_connect
|
6
13
|
self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
@@ -17,6 +17,13 @@ end
|
|
17
17
|
ActionController::Base.perform_caching = false
|
18
18
|
|
19
19
|
class WillPaginate::ViewTestCase < Test::Unit::TestCase
|
20
|
+
if defined?(ActionController::TestCase::Assertions)
|
21
|
+
include ActionController::TestCase::Assertions
|
22
|
+
end
|
23
|
+
if defined?(ActiveSupport::Testing::Deprecation)
|
24
|
+
include ActiveSupport::Testing::Deprecation
|
25
|
+
end
|
26
|
+
|
20
27
|
def setup
|
21
28
|
super
|
22
29
|
@controller = DummyController.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decisiv-will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.8.1
|
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:
|
13
|
+
date: 2009-05-05 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -29,15 +29,12 @@ files:
|
|
29
29
|
- LICENSE
|
30
30
|
- README.rdoc
|
31
31
|
- Rakefile
|
32
|
-
- examples
|
33
32
|
- examples/apple-circle.gif
|
34
33
|
- examples/index.haml
|
35
34
|
- examples/index.html
|
36
35
|
- examples/pagination.css
|
37
36
|
- examples/pagination.sass
|
38
37
|
- init.rb
|
39
|
-
- lib
|
40
|
-
- lib/will_paginate
|
41
38
|
- lib/will_paginate.rb
|
42
39
|
- lib/will_paginate/array.rb
|
43
40
|
- lib/will_paginate/collection.rb
|
@@ -47,13 +44,11 @@ files:
|
|
47
44
|
- lib/will_paginate/named_scope_patch.rb
|
48
45
|
- lib/will_paginate/version.rb
|
49
46
|
- lib/will_paginate/view_helpers.rb
|
50
|
-
- test
|
51
47
|
- test/boot.rb
|
52
48
|
- test/collection_test.rb
|
53
49
|
- test/console
|
54
50
|
- test/database.yml
|
55
51
|
- test/finder_test.rb
|
56
|
-
- test/fixtures
|
57
52
|
- test/fixtures/admin.rb
|
58
53
|
- test/fixtures/developer.rb
|
59
54
|
- test/fixtures/developers_projects.yml
|
@@ -67,7 +62,6 @@ files:
|
|
67
62
|
- test/fixtures/user.rb
|
68
63
|
- test/fixtures/users.yml
|
69
64
|
- test/helper.rb
|
70
|
-
- test/lib
|
71
65
|
- test/lib/activerecord_test_case.rb
|
72
66
|
- test/lib/activerecord_test_connector.rb
|
73
67
|
- test/lib/load_fixtures.rb
|
@@ -109,7 +103,6 @@ test_files:
|
|
109
103
|
- test/console
|
110
104
|
- test/database.yml
|
111
105
|
- test/finder_test.rb
|
112
|
-
- test/fixtures
|
113
106
|
- test/fixtures/admin.rb
|
114
107
|
- test/fixtures/developer.rb
|
115
108
|
- test/fixtures/developers_projects.yml
|
@@ -123,7 +116,6 @@ test_files:
|
|
123
116
|
- test/fixtures/user.rb
|
124
117
|
- test/fixtures/users.yml
|
125
118
|
- test/helper.rb
|
126
|
-
- test/lib
|
127
119
|
- test/lib/activerecord_test_case.rb
|
128
120
|
- test/lib/activerecord_test_connector.rb
|
129
121
|
- test/lib/load_fixtures.rb
|