will_paginate 3.2.0 → 4.0.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -5
  3. data/lib/will_paginate/active_record.rb +3 -3
  4. data/lib/will_paginate/i18n.rb +3 -3
  5. data/lib/will_paginate/locale/en.yml +2 -0
  6. data/lib/will_paginate/page_number.rb +1 -2
  7. data/lib/will_paginate/railtie.rb +2 -2
  8. data/lib/will_paginate/version.rb +2 -2
  9. data/lib/will_paginate/view_helpers/action_view.rb +7 -3
  10. data/lib/will_paginate/view_helpers/link_renderer.rb +7 -5
  11. data/lib/will_paginate.rb +0 -12
  12. metadata +12 -49
  13. data/lib/will_paginate/data_mapper.rb +0 -100
  14. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  15. data/spec/collection_spec.rb +0 -139
  16. data/spec/console +0 -12
  17. data/spec/console_fixtures.rb +0 -28
  18. data/spec/database.yml +0 -29
  19. data/spec/fake_rubygems.rb +0 -18
  20. data/spec/finders/active_record_spec.rb +0 -417
  21. data/spec/finders/activerecord_test_connector.rb +0 -140
  22. data/spec/finders/data_mapper_spec.rb +0 -114
  23. data/spec/finders/data_mapper_test_connector.rb +0 -54
  24. data/spec/finders/mongoid_spec.rb +0 -145
  25. data/spec/finders/sequel_spec.rb +0 -65
  26. data/spec/finders/sequel_test_connector.rb +0 -15
  27. data/spec/fixtures/admin.rb +0 -3
  28. data/spec/fixtures/developer.rb +0 -9
  29. data/spec/fixtures/developers_projects.yml +0 -13
  30. data/spec/fixtures/project.rb +0 -13
  31. data/spec/fixtures/projects.yml +0 -6
  32. data/spec/fixtures/replies.yml +0 -29
  33. data/spec/fixtures/reply.rb +0 -8
  34. data/spec/fixtures/schema.rb +0 -38
  35. data/spec/fixtures/topic.rb +0 -8
  36. data/spec/fixtures/topics.yml +0 -30
  37. data/spec/fixtures/user.rb +0 -2
  38. data/spec/fixtures/users.yml +0 -35
  39. data/spec/matchers/deprecation_matcher.rb +0 -27
  40. data/spec/matchers/phrase_matcher.rb +0 -19
  41. data/spec/matchers/query_count_matcher.rb +0 -36
  42. data/spec/page_number_spec.rb +0 -82
  43. data/spec/per_page_spec.rb +0 -41
  44. data/spec/spec_helper.rb +0 -46
  45. data/spec/view_helpers/action_view_spec.rb +0 -480
  46. data/spec/view_helpers/base_spec.rb +0 -143
  47. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  48. data/spec/view_helpers/view_example_group.rb +0 -146
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 751b354f97d844f6679cec31ce90298e6d6ff77217446d77e729421caa52c8da
4
- data.tar.gz: 5a18d970f3e6b0ca1e1949aa3eb14856ee80f1feea4b919f808e5d02f623bf58
3
+ metadata.gz: 95d6a838948c59686c5768a47e8e7e52b99c55868775645285022bc0d7c0e280
4
+ data.tar.gz: c92449392a8191a656e19d5e722314a2f2c1c50d646f5d98359b0d8193539dd2
5
5
  SHA512:
6
- metadata.gz: 1196350bf1e40de517c21fd8f085df09c682709894d1edd688402d33fab8d15c2b9af91b84c0df5dc5aad2eda9e6e8fbc006474b8ee3829af13879a6c66f24ed
7
- data.tar.gz: 5ef9ce7f70c5cc3ba0b1e024e4c4cfeb8e8afbb20cea2b983abfb31cb29eb850931b652f68d95579acaa5b69b71ffdfc384716640e4168e49c108fe3a525441d
6
+ metadata.gz: 4511c22cbbf023ab6e32fc457c487ec393c2fdf6f8a3910ee0c0d8385061a98307b6a8a8f02a25af33f9f648f735c5d20d942412b3a7ff5a40d2d7ba67491917
7
+ data.tar.gz: a062b0bce8e25a24b818b926957b98f970e86b79f89fbb1e2cdfbce382a030d02b3f02800cce6dd1671d84d3251e33879095a1bbe669a7348df90a3664be95ec
data/README.md CHANGED
@@ -1,16 +1,14 @@
1
1
  # will_paginate
2
2
 
3
- will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, Merb, DataMapper and Sequel.
4
-
5
- Installation:
3
+ will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, and Sequel.
6
4
 
7
5
  ``` ruby
8
- ## Gemfile for Rails 3+, Sinatra, and Merb
9
- gem 'will_paginate', '~> 3.1.0'
6
+ gem 'will_paginate', '~> 3.3'
10
7
  ```
11
8
 
12
9
  See [installation instructions][install] on the wiki for more info.
13
10
 
11
+ ℹ️ will_paginate is now in _maintenance mode_ and it will not be receiving new features. [See alternatives](https://www.ruby-toolbox.com/categories/pagination)
14
12
 
15
13
  ## Basic will_paginate use
16
14
 
@@ -105,9 +105,7 @@ module WillPaginate
105
105
  # overloaded to be pagination-aware
106
106
  def empty?
107
107
  if !loaded? and offset_value
108
- result = count
109
- result = result.size if result.respond_to?(:size) and !result.is_a?(Integer)
110
- result <= offset_value
108
+ total_entries <= offset_value
111
109
  else
112
110
  super
113
111
  end
@@ -212,6 +210,8 @@ module WillPaginate
212
210
  WHERE rownum <= #{pager.offset + pager.per_page}
213
211
  ) WHERE rnum >= #{pager.offset}
214
212
  SQL
213
+ elsif (self.connection.adapter_name =~ /^sqlserver/i)
214
+ query << " OFFSET #{pager.offset} ROWS FETCH NEXT #{pager.per_page} ROWS ONLY"
215
215
  else
216
216
  query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
217
217
  end
@@ -8,11 +8,11 @@ module WillPaginate
8
8
  Dir["#{locale_dir}/*.{rb,yml}"]
9
9
  end
10
10
 
11
- def will_paginate_translate(keys, options = {})
11
+ def will_paginate_translate(keys, options = {}, &block)
12
12
  if defined? ::I18n
13
13
  defaults = Array(keys).dup
14
- defaults << Proc.new if block_given?
15
- ::I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => :will_paginate))
14
+ defaults << block if block_given?
15
+ ::I18n.translate(defaults.shift, **options.merge(:default => defaults, :scope => :will_paginate))
16
16
  else
17
17
  key = Array === keys ? keys.first : keys
18
18
  yield key, options
@@ -1,7 +1,9 @@
1
1
  en:
2
2
  will_paginate:
3
3
  previous_label: "&#8592; Previous"
4
+ previous_aria_label: "Previous page"
4
5
  next_label: "Next &#8594;"
6
+ next_aria_label: "Next page"
5
7
  page_gap: "&hellip;"
6
8
  container_aria_label: "Pagination"
7
9
  page_aria_label: "Page %{page}"
@@ -1,4 +1,3 @@
1
- require 'delegate'
2
1
  require 'forwardable'
3
2
 
4
3
  module WillPaginate
@@ -28,7 +27,7 @@ module WillPaginate
28
27
  @value
29
28
  end
30
29
 
31
- def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/
30
+ def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/, :to_json
32
31
 
33
32
  def inspect
34
33
  "#{@name} #{to_i}"
@@ -59,11 +59,11 @@ module WillPaginate
59
59
  end
60
60
 
61
61
  module ControllerRescuePatch
62
- def rescue_from(*args, &block)
62
+ def rescue_from(*args, **kwargs, &block)
63
63
  if idx = args.index(WillPaginate::InvalidPage)
64
64
  args[idx] = args[idx].name
65
65
  end
66
- super(*args, &block)
66
+ super(*args, **kwargs, &block)
67
67
  end
68
68
  end
69
69
  end
@@ -1,7 +1,7 @@
1
1
  module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
- MAJOR = 3
4
- MINOR = 2
3
+ MAJOR = 4
4
+ MINOR = 0
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -80,7 +80,7 @@ module WillPaginate
80
80
  defaults = nil
81
81
  key = keys
82
82
  end
83
- translate(key, options.merge(:default => defaults, :scope => :will_paginate))
83
+ translate(key, **options.merge(:default => defaults, :scope => :will_paginate))
84
84
  else
85
85
  super
86
86
  end
@@ -119,8 +119,12 @@ module WillPaginate
119
119
  end
120
120
 
121
121
  def merge_get_params(url_params)
122
- if @template.respond_to? :request and @template.request and @template.request.get?
123
- symbolized_update(url_params, @template.params, GET_PARAMS_BLACKLIST)
122
+ if @template.respond_to?(:request) and @template.request
123
+ if @template.request.get?
124
+ symbolized_update(url_params, @template.params, GET_PARAMS_BLACKLIST)
125
+ elsif @template.request.respond_to?(:query_parameters)
126
+ symbolized_update(url_params, @template.request.query_parameters, GET_PARAMS_BLACKLIST)
127
+ end
124
128
  end
125
129
  url_params
126
130
  end
@@ -59,19 +59,21 @@ module WillPaginate
59
59
 
60
60
  def previous_page
61
61
  num = @collection.current_page > 1 && @collection.current_page - 1
62
- previous_or_next_page(num, @options[:previous_label], 'previous_page')
62
+ aria_label = @template.will_paginate_translate(:previous_aria_label) { "Previous page" }
63
+ previous_or_next_page(num, @options[:previous_label], 'previous_page', aria_label)
63
64
  end
64
65
 
65
66
  def next_page
66
67
  num = @collection.current_page < total_pages && @collection.current_page + 1
67
- previous_or_next_page(num, @options[:next_label], 'next_page')
68
+ aria_label = @template.will_paginate_translate(:next_aria_label) { "Next page" }
69
+ previous_or_next_page(num, @options[:next_label], 'next_page', aria_label)
68
70
  end
69
71
 
70
- def previous_or_next_page(page, text, classname)
72
+ def previous_or_next_page(page, text, classname, aria_label = nil)
71
73
  if page
72
- link(text, page, :class => classname)
74
+ link(text, page, :class => classname, :'aria-label' => aria_label)
73
75
  else
74
- tag(:span, text, :class => classname + ' disabled')
76
+ tag(:span, text, :class => classname + ' disabled', :'aria-label' => aria_label)
75
77
  end
76
78
  end
77
79
 
data/lib/will_paginate.rb CHANGED
@@ -8,18 +8,6 @@ elsif defined?(Rails::Initializer)
8
8
  raise "will_paginate 3.0 is not compatible with Rails 2.3 or older"
9
9
  end
10
10
 
11
- if defined?(Merb::AbstractController)
12
- require 'will_paginate/view_helpers/merb'
13
-
14
- Merb::BootLoader.before_app_loads do
15
- adapters = { :datamapper => 'data_mapper', :activerecord => 'active_record', :sequel => 'sequel' }
16
- # auto-load the right ORM adapter
17
- if adapter = adapters[Merb.orm]
18
- require "will_paginate/#{adapter}"
19
- end
20
- end
21
- end
22
-
23
11
  if defined?(Sinatra) and Sinatra.respond_to? :register
24
12
  require 'will_paginate/view_helpers/sinatra'
25
13
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mislav Marohnić
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: will_paginate provides a simple API for performing paginated queries
14
- with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
15
- links in Rails, Sinatra, Hanami, and Merb web apps.
14
+ with Active Record and Sequel, and includes helpers for rendering pagination links
15
+ in Rails, Sinatra, and Hanami web apps.
16
16
  email: mislav.marohnic@gmail.com
17
17
  executables: []
18
18
  extensions: []
@@ -27,7 +27,6 @@ files:
27
27
  - lib/will_paginate/array.rb
28
28
  - lib/will_paginate/collection.rb
29
29
  - lib/will_paginate/core_ext.rb
30
- - lib/will_paginate/data_mapper.rb
31
30
  - lib/will_paginate/deprecation.rb
32
31
  - lib/will_paginate/i18n.rb
33
32
  - lib/will_paginate/locale/en.yml
@@ -42,52 +41,17 @@ files:
42
41
  - lib/will_paginate/view_helpers/hanami.rb
43
42
  - lib/will_paginate/view_helpers/link_renderer.rb
44
43
  - lib/will_paginate/view_helpers/link_renderer_base.rb
45
- - lib/will_paginate/view_helpers/merb.rb
46
44
  - lib/will_paginate/view_helpers/sinatra.rb
47
- - spec/collection_spec.rb
48
- - spec/console
49
- - spec/console_fixtures.rb
50
- - spec/database.yml
51
- - spec/fake_rubygems.rb
52
- - spec/finders/active_record_spec.rb
53
- - spec/finders/activerecord_test_connector.rb
54
- - spec/finders/data_mapper_spec.rb
55
- - spec/finders/data_mapper_test_connector.rb
56
- - spec/finders/mongoid_spec.rb
57
- - spec/finders/sequel_spec.rb
58
- - spec/finders/sequel_test_connector.rb
59
- - spec/fixtures/admin.rb
60
- - spec/fixtures/developer.rb
61
- - spec/fixtures/developers_projects.yml
62
- - spec/fixtures/project.rb
63
- - spec/fixtures/projects.yml
64
- - spec/fixtures/replies.yml
65
- - spec/fixtures/reply.rb
66
- - spec/fixtures/schema.rb
67
- - spec/fixtures/topic.rb
68
- - spec/fixtures/topics.yml
69
- - spec/fixtures/user.rb
70
- - spec/fixtures/users.yml
71
- - spec/matchers/deprecation_matcher.rb
72
- - spec/matchers/phrase_matcher.rb
73
- - spec/matchers/query_count_matcher.rb
74
- - spec/page_number_spec.rb
75
- - spec/per_page_spec.rb
76
- - spec/spec_helper.rb
77
- - spec/view_helpers/action_view_spec.rb
78
- - spec/view_helpers/base_spec.rb
79
- - spec/view_helpers/link_renderer_base_spec.rb
80
- - spec/view_helpers/view_example_group.rb
81
45
  homepage: https://github.com/mislav/will_paginate
82
46
  licenses:
83
47
  - MIT
84
48
  metadata:
85
49
  bug_tracker_uri: https://github.com/mislav/will_paginate/issues
86
- changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v3.2.0
87
- documentation_uri: https://www.rubydoc.info/gems/will_paginate/3.2.0
88
- source_code_uri: https://github.com/mislav/will_paginate/tree/v3.2.0
50
+ changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v4.0.0
51
+ documentation_uri: https://www.rubydoc.info/gems/will_paginate/4.0.0
52
+ source_code_uri: https://github.com/mislav/will_paginate/tree/v4.0.0
89
53
  wiki_uri: https://github.com/mislav/will_paginate/wiki
90
- post_install_message:
54
+ post_install_message:
91
55
  rdoc_options:
92
56
  - "--main"
93
57
  - README.md
@@ -98,16 +62,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
62
  requirements:
99
63
  - - ">="
100
64
  - !ruby/object:Gem::Version
101
- version: '0'
65
+ version: '2.0'
102
66
  required_rubygems_version: !ruby/object:Gem::Requirement
103
67
  requirements:
104
68
  - - ">="
105
69
  - !ruby/object:Gem::Version
106
70
  version: '0'
107
71
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.7.6
110
- signing_key:
72
+ rubygems_version: 3.4.6
73
+ signing_key:
111
74
  specification_version: 4
112
75
  summary: Pagination plugin for web frameworks and other apps
113
76
  test_files: []
@@ -1,100 +0,0 @@
1
- require 'dm-core'
2
- require 'dm-aggregates'
3
- require 'will_paginate/per_page'
4
- require 'will_paginate/page_number'
5
- require 'will_paginate/collection'
6
-
7
- module WillPaginate
8
- module DataMapper
9
- module Pagination
10
- def page(num)
11
- pagenum = ::WillPaginate::PageNumber(num.nil? ? 1 : num)
12
- per_page = query.limit || self.per_page
13
- options = {:offset => pagenum.to_offset(per_page).to_i}
14
- options[:limit] = per_page unless query.limit
15
- col = new_collection(query.merge(options))
16
- col.current_page = pagenum
17
- col
18
- end
19
-
20
- def paginate(options)
21
- options = options.dup
22
- pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
23
- per_page = options.delete(:per_page) || self.per_page
24
- total = options.delete(:total_entries)
25
-
26
- options.delete(:page)
27
- options[:limit] = per_page.to_i
28
-
29
-
30
- col = all(options).page(pagenum)
31
- col.total_entries = total.to_i unless total.nil? || (total.kind_of?(String) && total.strip.empty?)
32
- col
33
- end
34
- end
35
-
36
- module CollectionMethods
37
- include WillPaginate::CollectionMethods
38
-
39
- attr_accessor :current_page
40
- attr_writer :total_entries
41
-
42
- def paginated?
43
- !current_page.nil?
44
- end
45
-
46
- def per_page
47
- query.limit || model.per_page
48
- end
49
-
50
- def offset
51
- query.offset
52
- end
53
-
54
- def total_entries
55
- @total_entries ||= begin
56
- if loaded? and @array.size < per_page and (current_page == 1 or @array.size > 0)
57
- offset + @array.size
58
- else
59
- # :reload prevents Collection.filter from being run, which
60
- # would cause a stack overflow
61
- clean_query = query.merge(:reload => true)
62
- # seems like the only way
63
- clean_query.instance_variable_set('@limit', nil)
64
- clean_query.instance_variable_set('@offset', 0)
65
- new_collection(clean_query).count
66
- end
67
- end
68
- end
69
-
70
- def to_a
71
- if paginated?
72
- ::WillPaginate::Collection.create(current_page, per_page) do |col|
73
- col.replace super
74
- col.total_entries ||= total_entries
75
- end
76
- else
77
- super
78
- end
79
- end
80
-
81
- private
82
-
83
- def new_collection(query, resources = nil)
84
- col = super
85
- col.current_page = self.current_page
86
- col
87
- end
88
-
89
- def initialize_copy(original)
90
- super
91
- @total_entries = nil
92
- end
93
- end
94
-
95
- ::DataMapper::Model.append_extensions PerPage
96
- ::DataMapper::Model.append_extensions Pagination
97
- ::DataMapper::Collection.send(:include, Pagination)
98
- ::DataMapper::Collection.send(:include, CollectionMethods)
99
- end
100
- end
@@ -1,26 +0,0 @@
1
- require 'will_paginate/core_ext'
2
- require 'will_paginate/view_helpers'
3
- require 'will_paginate/view_helpers/link_renderer'
4
-
5
- module WillPaginate
6
- module Merb
7
- include ViewHelpers
8
-
9
- def will_paginate(collection, options = {}) #:nodoc:
10
- options = options.merge(:renderer => LinkRenderer) unless options[:renderer]
11
- super(collection, options)
12
- end
13
-
14
- class LinkRenderer < ViewHelpers::LinkRenderer
15
- protected
16
-
17
- def url(page)
18
- params = @template.request.params.except(:action, :controller).merge(param_name => page)
19
- @template.url(:this, params)
20
- end
21
- end
22
-
23
- ::Merb::AbstractController.send(:include, self)
24
- end
25
- end
26
-
@@ -1,139 +0,0 @@
1
- require 'will_paginate/array'
2
- require 'spec_helper'
3
-
4
- describe WillPaginate::Collection do
5
-
6
- before :all do
7
- @simple = ('a'..'e').to_a
8
- end
9
-
10
- it "should be a subset of original collection" do
11
- @simple.paginate(:page => 1, :per_page => 3).should == %w( a b c )
12
- end
13
-
14
- it "can be shorter than per_page if on last page" do
15
- @simple.paginate(:page => 2, :per_page => 3).should == %w( d e )
16
- end
17
-
18
- it "should include whole collection if per_page permits" do
19
- @simple.paginate(:page => 1, :per_page => 5).should == @simple
20
- end
21
-
22
- it "should be empty if out of bounds" do
23
- @simple.paginate(:page => 2, :per_page => 5).should be_empty
24
- end
25
-
26
- it "should default to 1 as current page and 30 per-page" do
27
- result = (1..50).to_a.paginate
28
- result.current_page.should == 1
29
- result.size.should == 30
30
- end
31
-
32
- it "should give total_entries precedence over actual size" do
33
- %w(a b c).paginate(:total_entries => 5).total_entries.should == 5
34
- end
35
-
36
- it "should be an augmented Array" do
37
- entries = %w(a b c)
38
- collection = create(2, 3, 10) do |pager|
39
- pager.replace(entries).should == entries
40
- end
41
-
42
- collection.should == entries
43
- for method in %w(total_pages each offset size current_page per_page total_entries)
44
- collection.should respond_to(method)
45
- end
46
- collection.should be_kind_of(Array)
47
- collection.entries.should be_instance_of(Array)
48
- # TODO: move to another expectation:
49
- collection.offset.should == 3
50
- collection.total_pages.should == 4
51
- collection.should_not be_out_of_bounds
52
- end
53
-
54
- describe "previous/next pages" do
55
- it "should have previous_page nil when on first page" do
56
- collection = create(1, 1, 3)
57
- collection.previous_page.should be_nil
58
- collection.next_page.should == 2
59
- end
60
-
61
- it "should have both prev/next pages" do
62
- collection = create(2, 1, 3)
63
- collection.previous_page.should == 1
64
- collection.next_page.should == 3
65
- end
66
-
67
- it "should have next_page nil when on last page" do
68
- collection = create(3, 1, 3)
69
- collection.previous_page.should == 2
70
- collection.next_page.should be_nil
71
- end
72
- end
73
-
74
- describe "out of bounds" do
75
- it "is out of bounds when page number is too high" do
76
- create(2, 3, 2).should be_out_of_bounds
77
- end
78
-
79
- it "isn't out of bounds when inside collection" do
80
- create(1, 3, 2).should_not be_out_of_bounds
81
- end
82
-
83
- it "isn't out of bounds when the collection is empty" do
84
- collection = create(1, 3, 0)
85
- collection.should_not be_out_of_bounds
86
- collection.total_pages.should == 1
87
- end
88
- end
89
-
90
- describe "guessing total count" do
91
- it "can guess when collection is shorter than limit" do
92
- collection = create { |p| p.replace array }
93
- collection.total_entries.should == 8
94
- end
95
-
96
- it "should allow explicit total count to override guessed" do
97
- collection = create(2, 5, 10) { |p| p.replace array }
98
- collection.total_entries.should == 10
99
- end
100
-
101
- it "should not be able to guess when collection is same as limit" do
102
- collection = create { |p| p.replace array(5) }
103
- collection.total_entries.should be_nil
104
- end
105
-
106
- it "should not be able to guess when collection is empty" do
107
- collection = create { |p| p.replace array(0) }
108
- collection.total_entries.should be_nil
109
- end
110
-
111
- it "should be able to guess when collection is empty and this is the first page" do
112
- collection = create(1) { |p| p.replace array(0) }
113
- collection.total_entries.should == 0
114
- end
115
- end
116
-
117
- it "should not respond to page_count anymore" do
118
- Proc.new { create.page_count }.should raise_error(NoMethodError)
119
- end
120
-
121
- it "inherits per_page from global value" do
122
- collection = described_class.new(1)
123
- collection.per_page.should == 30
124
- end
125
-
126
- private
127
-
128
- def create(page = 2, limit = 5, total = nil, &block)
129
- if block_given?
130
- described_class.create(page, limit, total, &block)
131
- else
132
- described_class.new(page, limit, total)
133
- end
134
- end
135
-
136
- def array(size = 3)
137
- Array.new(size)
138
- end
139
- end
data/spec/console DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
3
- opts = %w[ --simple-prompt -rirb/completion ]
4
- if ARGV.include? '-dm'
5
- opts << '-rwill_paginate/data_mapper' << '-rfinders/data_mapper_test_connector'
6
- elsif ARGV.include? '-seq'
7
- opts << '-rwill_paginate/sequel' << '-rfinders/sequel_test_connector'
8
- else
9
- opts << '-rconsole_fixtures'
10
- end
11
-
12
- exec 'bundle', 'exec', irb, '-Ilib:spec', *opts
@@ -1,28 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- require 'will_paginate/active_record'
5
- require 'finders/activerecord_test_connector'
6
-
7
- ActiverecordTestConnector.setup
8
-
9
- windows = RUBY_PLATFORM =~ /(:?mswin|mingw)/
10
- # used just for the `color` method
11
- log_subscriber = ActiveSupport::LogSubscriber.log_subscribers.first
12
-
13
- IGNORE_SQL = /\b(sqlite_master|sqlite_version)\b|^(CREATE TABLE|PRAGMA)\b/
14
-
15
- ActiveSupport::Notifications.subscribe(/^sql\./) do |*args|
16
- data = args.last
17
- unless data[:name] =~ /^Fixture/ or data[:sql] =~ IGNORE_SQL
18
- if windows
19
- puts data[:sql]
20
- else
21
- puts log_subscriber.send(:color, data[:sql], :cyan)
22
- end
23
- end
24
- end
25
-
26
- # load all fixtures
27
- ActiverecordTestConnector::Fixtures.create_fixtures \
28
- ActiverecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables
data/spec/database.yml DELETED
@@ -1,29 +0,0 @@
1
- sqlite3:
2
- database: ":memory:"
3
- adapter: sqlite3
4
- timeout: 500
5
-
6
- mysql: &mysql
7
- adapter: mysql
8
- database: will_paginate
9
- username: root
10
- encoding: utf8
11
- <% if File.exist?("/var/run/mysql5/mysqld.sock") %>
12
- host: localhost
13
- socket: /var/run/mysql5/mysqld.sock
14
- <% elsif File.exist? "/tmp/mysql.sock" %>
15
- host: localhost
16
- socket: /tmp/mysql.sock
17
- <% else %>
18
- host: 127.0.0.1
19
- <% end %>
20
-
21
- mysql2:
22
- <<: *mysql
23
- adapter: mysql2
24
-
25
- postgres:
26
- adapter: postgresql
27
- database: will_paginate
28
- username: <%= "postgres" if ENV["TRAVIS"] %>
29
- min_messages: warning
@@ -1,18 +0,0 @@
1
- # Makes the test suite compatible with Bundler standalone mode (used in CI)
2
- # because Active Record uses `gem` for loading adapters.
3
- Kernel.module_eval do
4
-
5
- remove_method :gem if 'method' == defined? gem
6
-
7
- def gem(*args)
8
- return if $VERBOSE.nil?
9
- $stderr << "warning: gem(#{args.map {|o| o.inspect }.join(', ')}) ignored"
10
- $stderr << "; called from:\n " << caller[0,5].join("\n ") if $DEBUG
11
- $stderr << "\n"
12
- end
13
-
14
- private :gem
15
-
16
- end
17
-
18
- $" << "rubygems.rb"