will_paginate 3.0.3 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of will_paginate might be problematic. Click here for more details.
- data/lib/will_paginate/active_record.rb +31 -1
- data/lib/will_paginate/railtie.rb +0 -1
- data/lib/will_paginate/version.rb +1 -1
- data/lib/will_paginate/view_helpers.rb +1 -2
- data/lib/will_paginate/view_helpers/link_renderer.rb +1 -1
- data/spec/finders/active_record_spec.rb +15 -2
- data/spec/finders/activerecord_test_connector.rb +3 -1
- data/spec/finders/sequel_test_connector.rb +6 -0
- data/spec/fixtures/developer.rb +1 -1
- data/spec/fixtures/project.rb +1 -1
- data/spec/view_helpers/action_view_spec.rb +4 -4
- data/spec/view_helpers/view_example_group.rb +8 -1
- metadata +3 -3
@@ -39,6 +39,26 @@ module WillPaginate
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
# dirty hack to enable `first` after `limit` behavior above
|
43
|
+
def first(*args)
|
44
|
+
if current_page
|
45
|
+
rel = clone
|
46
|
+
rel.current_page = nil
|
47
|
+
rel.first(*args)
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# fix for Rails 3.0
|
54
|
+
def find_last
|
55
|
+
if !loaded? and offset_value || limit_value
|
56
|
+
@last ||= to_a.last
|
57
|
+
else
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
42
62
|
def offset(value = nil)
|
43
63
|
if value.nil? then offset_value
|
44
64
|
else super(value)
|
@@ -138,7 +158,17 @@ module WillPaginate
|
|
138
158
|
end
|
139
159
|
|
140
160
|
def page(num)
|
141
|
-
rel =
|
161
|
+
rel = if ::ActiveRecord::Relation === self
|
162
|
+
self
|
163
|
+
elsif !defined?(::ActiveRecord::Scoping) or ::ActiveRecord::Scoping::ClassMethods.method_defined? :with_scope
|
164
|
+
# Active Record 3
|
165
|
+
scoped
|
166
|
+
else
|
167
|
+
# Active Record 4
|
168
|
+
all
|
169
|
+
end
|
170
|
+
|
171
|
+
rel = rel.extending(RelationMethods)
|
142
172
|
pagenum = ::WillPaginate::PageNumber(num.nil? ? 1 : num)
|
143
173
|
per_page = rel.limit_value || self.per_page
|
144
174
|
rel = rel.offset(pagenum.to_offset(per_page).to_i)
|
@@ -40,7 +40,6 @@ module WillPaginate
|
|
40
40
|
module ShowExceptionsPatch
|
41
41
|
extend ActiveSupport::Concern
|
42
42
|
included { alias_method_chain :status_code, :paginate }
|
43
|
-
private
|
44
43
|
def status_code_with_paginate(exception = @exception)
|
45
44
|
if exception.is_a?(WillPaginate::InvalidPage) or
|
46
45
|
(exception.respond_to?(:original_exception) &&
|
@@ -47,7 +47,6 @@ module WillPaginate
|
|
47
47
|
# * <tt>:class</tt> -- CSS class name for the generated DIV (default: "pagination")
|
48
48
|
# * <tt>:previous_label</tt> -- default: "« Previous"
|
49
49
|
# * <tt>:next_label</tt> -- default: "Next »"
|
50
|
-
# * <tt>:page_links</tt> -- when false, only previous/next links are rendered (default: true)
|
51
50
|
# * <tt>:inner_window</tt> -- how many links are shown around the current page (default: 4)
|
52
51
|
# * <tt>:outer_window</tt> -- how many links are around the first and the last page (default: 1)
|
53
52
|
# * <tt>:link_separator</tt> -- string separator for page HTML elements (default: single space)
|
@@ -137,7 +136,7 @@ module WillPaginate
|
|
137
136
|
i18n_key = :"page_entries_info.single_page#{html_key}"
|
138
137
|
keys = [:"#{model_key}.#{i18n_key}", i18n_key]
|
139
138
|
|
140
|
-
will_paginate_translate keys, :count => collection.
|
139
|
+
will_paginate_translate keys, :count => collection.total_entries, :model => model_name do |_, opts|
|
141
140
|
case opts[:count]
|
142
141
|
when 0; "No #{opts[:model]} found"
|
143
142
|
when 1; "Displaying #{b}1#{eb} #{opts[:model]}"
|
@@ -59,7 +59,7 @@ module WillPaginate
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def next_page
|
62
|
-
num = @collection.current_page <
|
62
|
+
num = @collection.current_page < total_pages && @collection.current_page + 1
|
63
63
|
previous_or_next_page(num, @options[:next_label], 'next_page')
|
64
64
|
end
|
65
65
|
|
@@ -92,6 +92,19 @@ describe WillPaginate::ActiveRecord do
|
|
92
92
|
rel.offset.should == 6
|
93
93
|
end
|
94
94
|
|
95
|
+
it "supports #first" do
|
96
|
+
rel = Developer.order('id').page(2).per_page(4)
|
97
|
+
rel.first.should == users(:dev_5)
|
98
|
+
rel.first(2).should == users(:dev_5, :dev_6)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "supports #last" do
|
102
|
+
rel = Developer.order('id').page(2).per_page(4)
|
103
|
+
rel.last.should == users(:dev_8)
|
104
|
+
rel.last(2).should == users(:dev_7, :dev_8)
|
105
|
+
rel.page(3).last.should == users(:poor_jamis)
|
106
|
+
end
|
107
|
+
|
95
108
|
it "keeps pagination data after 'scoped'" do
|
96
109
|
rel = Developer.page(2).scoped
|
97
110
|
rel.per_page.should == 10
|
@@ -207,7 +220,7 @@ describe WillPaginate::ActiveRecord do
|
|
207
220
|
sql = "select content from topics where content like '%futurama%'"
|
208
221
|
topics = Topic.paginate_by_sql sql, :page => 1, :per_page => 1
|
209
222
|
topics.total_entries.should == 1
|
210
|
-
topics.first
|
223
|
+
topics.first.attributes.has_key?('title').should be_false
|
211
224
|
}.should run_queries(2)
|
212
225
|
end
|
213
226
|
|
@@ -368,7 +381,7 @@ describe WillPaginate::ActiveRecord do
|
|
368
381
|
end
|
369
382
|
|
370
383
|
it "should paginate through association extension" do
|
371
|
-
project = Project.
|
384
|
+
project = Project.order('id').first
|
372
385
|
expected = [replies(:brave)]
|
373
386
|
|
374
387
|
lambda {
|
@@ -30,7 +30,9 @@ module ActiverecordTestConnector
|
|
30
30
|
|
31
31
|
FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
|
32
32
|
|
33
|
-
Fixtures = defined?(ActiveRecord::
|
33
|
+
Fixtures = defined?(ActiveRecord::FixtureSet) ? ActiveRecord::FixtureSet :
|
34
|
+
defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures :
|
35
|
+
::Fixtures
|
34
36
|
|
35
37
|
# Set our defaults
|
36
38
|
self.connected = false
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'sequel'
|
2
2
|
|
3
|
+
Symbol.class_eval do
|
4
|
+
# Active Record calculations tries `as` on some objects but chokes when that
|
5
|
+
# object was a Symbol and it gets a Sequel::SQL::AliasedExpression.
|
6
|
+
undef as if method_defined? :as
|
7
|
+
end
|
8
|
+
|
3
9
|
db = Sequel.sqlite
|
4
10
|
|
5
11
|
db.create_table :cars do
|
data/spec/fixtures/developer.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Developer < User
|
2
|
-
has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name'
|
2
|
+
has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name', :join_table => 'developers_projects'
|
3
3
|
|
4
4
|
def self.with_poor_ones(&block)
|
5
5
|
with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'salary' } do
|
data/spec/fixtures/project.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Project < ActiveRecord::Base
|
2
|
-
has_and_belongs_to_many :developers, :uniq => true
|
2
|
+
has_and_belongs_to_many :developers, :uniq => true, :join_table => 'developers_projects'
|
3
3
|
|
4
4
|
has_many :topics
|
5
5
|
# :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})',
|
@@ -7,12 +7,12 @@ require 'will_paginate/collection'
|
|
7
7
|
Routes = ActionDispatch::Routing::RouteSet.new
|
8
8
|
|
9
9
|
Routes.draw do
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
get 'dummy/page/:page' => 'dummy#index'
|
11
|
+
get 'dummy/dots/page.:page' => 'dummy#dots'
|
12
|
+
get 'ibocorp(/:page)' => 'ibocorp#index',
|
13
13
|
:constraints => { :page => /\d+/ }, :defaults => { :page => 1 }
|
14
14
|
|
15
|
-
|
15
|
+
get ':controller(/:action(/:id(.:format)))'
|
16
16
|
end
|
17
17
|
|
18
18
|
describe WillPaginate::ActionView do
|
@@ -1,11 +1,18 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
begin
|
3
|
+
require 'minitest/unit'
|
4
|
+
rescue LoadError
|
5
|
+
# Fails on Ruby 1.8, but it's OK since we only need MiniTest::Assertions
|
6
|
+
# on Rails 4 which doesn't support 1.8 anyway.
|
7
|
+
end
|
2
8
|
require 'action_dispatch/testing/assertions'
|
3
9
|
require 'will_paginate/array'
|
4
10
|
|
5
11
|
module ViewExampleGroup
|
6
12
|
|
7
13
|
include ActionDispatch::Assertions::SelectorAssertions
|
8
|
-
|
14
|
+
include MiniTest::Assertions if defined? MiniTest
|
15
|
+
|
9
16
|
def assert(value, message)
|
10
17
|
raise message unless value
|
11
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: will_paginate provides a simple API for performing paginated queries
|
15
15
|
with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.23
|
101
101
|
signing_key:
|
102
102
|
specification_version: 3
|
103
103
|
summary: Pagination plugin for web frameworks and other apps
|