mislav-will_paginate 2.3.6 → 2.3.7

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.
@@ -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
- behavior.call(message, callstack) if behavior && !silenced?
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, &block)
85
+ def self.create(page, per_page, total = nil)
86
86
  pager = new(page, per_page, total)
87
87
  yield pager
88
88
  pager
@@ -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, &block)
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 send(finder, *args, &block)
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 = {}, &block)
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(&block).size
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, &block) #:nodoc:
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
- return method_missing_without_paginate(method, *args, &block)
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, &block)
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 = {}, &block)
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, &block)
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, &block)
115
+ def initialize(proxy_scope, options)
116
116
  [options[:extend]].flatten.each { |extension| extend extension } if options[:extend]
117
- extend Module.new(&block) if block_given?
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, &block)
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, &block)
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, &block)
4
- @reflection.klass.send :with_scope, *args, &block
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, &block)
13
+ def method_missing_without_paginate(method, *args)
14
14
  if @reflection.klass.scopes.include?(method)
15
- @reflection.klass.scopes[method].call(self, *args, &block)
15
+ @reflection.klass.scopes[method].call(self, *args) { |*a| yield(*a) if block_given? }
16
16
  else
17
- method_missing_without_scopes(method, *args, &block)
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, &block)
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, &block)
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
 
@@ -141,8 +141,15 @@ module WillPaginate
141
141
  # blocks of pagination links sharing the same ID (which is invalid HTML).
142
142
  def paginated_section(*args, &block)
143
143
  pagination = will_paginate(*args).to_s
144
- content = pagination + capture(&block) + pagination
145
- concat content, block.binding
144
+
145
+ unless ActionView::Base.respond_to? :erb_variable
146
+ concat pagination
147
+ yield
148
+ concat pagination
149
+ else
150
+ content = pagination + capture(&block) + pagination
151
+ concat(content, block.binding)
152
+ end
146
153
  end
147
154
 
148
155
  # Renders a helpful message with numbers of displayed vs. total entries.
@@ -178,12 +185,11 @@ module WillPaginate
178
185
 
179
186
  def self.total_pages_for_collection(collection) #:nodoc:
180
187
  if collection.respond_to?('page_count') and !collection.respond_to?('total_pages')
181
- WillPaginate::Deprecation.warn <<-MSG
188
+ WillPaginate::Deprecation.warn %{
182
189
  You are using a paginated collection of class #{collection.class.name}
183
190
  which conforms to the old API of WillPaginate::Collection by using
184
191
  `page_count`, while the current method name is `total_pages`. Please
185
- upgrade yours or 3rd-party code that provides the paginated collection.
186
- MSG
192
+ upgrade yours or 3rd-party code that provides the paginated collection}, caller
187
193
  class << collection
188
194
  def total_pages; page_count; end
189
195
  end
@@ -41,6 +41,8 @@ class ActiveRecordTestConnector
41
41
  ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
42
42
  puts "using #{configuration['adapter']} adapter" unless ENV['DB'].blank?
43
43
 
44
+ gem 'sqlite3-ruby' if 'sqlite3' == db
45
+
44
46
  ActiveRecord::Base.establish_connection(configuration)
45
47
  ActiveRecord::Base.configurations = { db => configuration }
46
48
  prepare ActiveRecord::Base.connection
@@ -42,15 +42,21 @@ class WillPaginate::ViewTestCase < Test::Unit::TestCase
42
42
 
43
43
  locals = { :collection => collection, :options => options }
44
44
 
45
- if defined? ActionView::InlineTemplate
46
- # Rails 2.1
47
- args = [ ActionView::InlineTemplate.new(@view, @template, locals) ]
45
+ unless @view.respond_to? :render_template
46
+ # Rails 2.2
47
+ @html_result = ActionView::InlineTemplate.new(@template).render(@view, locals)
48
48
  else
49
- # older Rails versions
50
- args = [nil, @template, nil, locals]
49
+ if defined? ActionView::InlineTemplate
50
+ # Rails 2.1
51
+ args = [ ActionView::InlineTemplate.new(@view, @template, locals) ]
52
+ else
53
+ # older Rails versions
54
+ args = [nil, @template, nil, locals]
55
+ end
56
+
57
+ @html_result = @view.render_template(*args)
51
58
  end
52
59
 
53
- @html_result = @view.render_template(*args)
54
60
  @html_document = HTML::Document.new(@html_result, true, false)
55
61
 
56
62
  if block_given?
@@ -192,13 +192,15 @@ class ViewTest < WillPaginate::ViewTestCase
192
192
  @html_result
193
193
  end
194
194
 
195
- def test_page_entries_info_with_longer_class_name
196
- @template = '<%= page_entries_info collection %>'
197
- collection = ('a'..'z').to_a.paginate
198
- collection.first.stubs(:class).returns(mock('class', :name => 'ProjectType'))
195
+ uses_mocha 'class name' do
196
+ def test_page_entries_info_with_longer_class_name
197
+ @template = '<%= page_entries_info collection %>'
198
+ collection = ('a'..'z').to_a.paginate
199
+ collection.first.stubs(:class).returns(mock('class', :name => 'ProjectType'))
199
200
 
200
- paginate collection
201
- assert @html_result.index('project types'), "expected <#{@html_result.inspect}> to mention 'project types'"
201
+ paginate collection
202
+ assert @html_result.index('project types'), "expected <#{@html_result.inspect}> to mention 'project types'"
203
+ end
202
204
  end
203
205
 
204
206
  def test_page_entries_info_with_single_page_collection
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.6
4
+ version: 2.3.7
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: 2008-10-26 00:00:00 -07:00
13
+ date: 2009-02-10 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16