jm81-paginate 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmY5OTAxYTBhN2U0NDA3MDJhNDFmNjgwMTRiYTg1YWFmYzBiMTU4Yg==
5
+ data.tar.gz: !binary |-
6
+ NGNhOTUzYTllYzdiM2Q4NWM0Y2QzMGE2OGJiZjFiNjQyNTcwYTJlMQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzBjMTk1NTllOTdkMjBmMmVjMDZhMjNmYzIwOGMwNmNhYzNmOTA1ZDA4ODlj
10
+ ZDM2MGIxMjllMjljNDA2ZDQyNGM0MTQwNTNjYjk4NjAyZTc0NTJlMTc1ODgz
11
+ NDYzMjY3NjIxMzAxY2Y4NTc0Y2E5MTI2MGZmY2E5OGM0ZjNjOWY=
12
+ data.tar.gz: !binary |-
13
+ NWJkZDM0MTI4NDE3ZGRjMjY2MWVhMGE1NWZkZGMwODMyNjI5MmFjYjg0ZDQy
14
+ NDJjMDljMzdlZjlkMGExZmE1NTg5MTU0YTE1MDgxMzlmZWU4NzY3ODk2OGFi
15
+ NDM1MjBkNWFhNmM0OGJiY2E1MzRjM2RiZGIwNjk2YTE4MzU0MDc=
data/Rakefile CHANGED
@@ -1,27 +1,11 @@
1
- require 'rubygems'
2
1
  require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+ require 'rubygems'
3
5
  require File.join(File.dirname(__FILE__), 'lib', 'jm81-paginate', 'version')
4
6
 
5
- begin
6
- require 'jeweler'
7
- Jeweler::Tasks.new do |gem|
8
- gem.name = "jm81-paginate"
9
- gem.version = Paginate::VERSION.dup
10
- gem.summary = "Pagination for DataMapper, ActiveRecord, and Array"
11
- gem.description = <<EOF
12
- This paginate library assists in paginating collections and results of database
13
- queries. It is particularly designed for use with DataMapper and ActiveRecord,
14
- and for the Merb and Rails frameworks, but can be used in many other situations.
15
- EOF
16
- gem.email = "jmorgan@morgancreative.net"
17
- gem.homepage = "http://github.com/jm81/paginate"
18
- gem.authors = ["Jared Morgan"]
19
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
- end
21
- Jeweler::GemcutterTasks.new
22
- rescue LoadError
23
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
- end
7
+ desc 'Default: run unit tests.'
8
+ task :default => :specs
25
9
 
26
10
  require 'spec/rake/spectask'
27
11
  Spec::Rake::SpecTask.new(:spec) do |spec|
@@ -35,20 +19,10 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
35
19
  spec.rcov = true
36
20
  end
37
21
 
38
-
39
- task :default => :spec
40
-
41
- require 'rake/rdoctask'
42
22
  Rake::RDocTask.new do |rdoc|
43
- if File.exist?('VERSION.yml')
44
- config = YAML.load(File.read('VERSION.yml'))
45
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
46
- else
47
- version = ""
48
- end
49
-
50
23
  rdoc.rdoc_dir = 'rdoc'
51
- rdoc.title = "svn-fixture #{version}"
24
+ rdoc.title = 'jm81-paginate'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
52
26
  rdoc.rdoc_files.include('README*')
53
27
  rdoc.rdoc_files.include('lib/**/*.rb')
54
28
  end
@@ -2,23 +2,23 @@ module Paginate
2
2
  module Helpers
3
3
  # Shared helper methods included in other Helper modules.
4
4
  module Shared
5
- # +page_set+ returns an Array of page numbers that can be used by a view
5
+ # +page_set+ returns an Array of page numbers that can be used by a view
6
6
  # for displaying page links. It includes the first page, the current page,
7
7
  # with up to +padding+ pages before and after, and the last page. If pages
8
8
  # are skipped between any of these groups, 0 stands in for them, as an
9
9
  # indicator to the view that, for example, elipses might be used here.
10
10
  # For example:
11
- #
11
+ #
12
12
  # page_set(3, 10, 3)
13
13
  # => [1, 2, 3, 4, 5, 6, 0, 10] TODO test this in particular
14
- #
14
+ #
15
15
  # The 0 at index 6 is an indication that there are skipped pages.
16
16
  def page_set(current_page, pages, padding = 3)
17
-
17
+
18
18
  # Determine first and last page in group around current page
19
19
  first = [1, current_page - padding].max
20
20
  last = [pages, current_page + padding].min
21
-
21
+
22
22
  # Determine if an additional "First page" is needed and whether any
23
23
  # pages are skipped between it and the first around the current page
24
24
  leader = case first
@@ -34,7 +34,7 @@ module Paginate
34
34
  when pages - 1 then [pages] # Last needed, but none skipped
35
35
  else [0, pages] # Last needed, some skipped
36
36
  end
37
-
37
+
38
38
  # Join Arrays together
39
39
  leader + (first..last).to_a + footer
40
40
  end
@@ -46,7 +46,7 @@ module Paginate
46
46
  # in the query string to be used in the page link.
47
47
  def url_for_pagination(page, path = request.path, q = request.query_string)
48
48
  # Remove any current reference to page in the query string
49
- q.to_s.gsub!(/page=(-?[\d]+)(&?)/, '')
49
+ q = q.to_s.gsub(/page=(-?[\d]+)(&?)/, '')
50
50
  # Assemble new link
51
51
  link = "#{path}?page=#{page}&#{q}"
52
52
  link = link[0..-2] if link[-1..-1] == '&' # Strip trailing ampersand
@@ -1,3 +1,3 @@
1
1
  module Paginate
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,113 +1,62 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jm81-paginate
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Jared Morgan
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-12-02 00:00:00 -06:00
19
- default_executable:
11
+ date: 2014-07-01 00:00:00.000000000 Z
20
12
  dependencies: []
13
+ description: ! 'This paginate library assists in paginating collections and results
14
+ of database
15
+
16
+ queries. It is particularly designed for use with DataMapper and ActiveRecord,
21
17
 
22
- description: |
23
- This paginate library assists in paginating collections and results of database
24
- queries. It is particularly designed for use with DataMapper and ActiveRecord,
25
18
  and for the Merb and Rails frameworks, but can be used in many other situations.
26
19
 
27
- email: jmorgan@morgancreative.net
20
+ '
21
+ email:
22
+ - jmorgan@morgancreative.net
28
23
  executables: []
29
-
30
24
  extensions: []
31
-
32
- extra_rdoc_files:
33
- - LICENSE
34
- - README.md
35
- - TODO
36
- files:
37
- - LICENSE
38
- - README.md
39
- - Rakefile
40
- - TODO
41
- - jm81-paginate.gemspec
25
+ extra_rdoc_files: []
26
+ files:
42
27
  - lib/helpers/merb.rb
43
28
  - lib/helpers/rails.rb
44
29
  - lib/helpers/shared.rb
45
- - lib/jm81-paginate.rb
46
- - lib/jm81-paginate/version.rb
47
- - lib/paginate/ar.rb
48
- - lib/paginate/dm.rb
49
- - lib/paginate/simple.rb
50
- - lib/paginators/orm.rb
51
30
  - lib/paginators/simple.rb
52
- - spec/fixtures/ar.rb
53
- - spec/fixtures/dm.rb
54
- - spec/helpers/merb_spec.rb
55
- - spec/helpers/rails_spec.rb
56
- - spec/helpers/shared_spec.rb
57
- - spec/paginate/ar_spec.rb
58
- - spec/paginate/config_spec.rb
59
- - spec/paginate/dm_spec.rb
60
- - spec/paginate/simple_spec.rb
61
- - spec/paginators/orm_spec.rb
62
- - spec/paginators/simple_spec.rb
63
- - spec/shared.rb
64
- - spec/spec.opts
65
- - spec/spec_helper.rb
66
- has_rdoc: true
31
+ - lib/paginators/orm.rb
32
+ - lib/paginate/simple.rb
33
+ - lib/paginate/dm.rb
34
+ - lib/paginate/ar.rb
35
+ - lib/jm81-paginate/version.rb
36
+ - lib/jm81-paginate.rb
37
+ - Rakefile
38
+ - README.md
67
39
  homepage: http://github.com/jm81/paginate
68
40
  licenses: []
69
-
41
+ metadata: {}
70
42
  post_install_message:
71
43
  rdoc_options: []
72
-
73
- require_paths:
44
+ require_paths:
74
45
  - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
76
- none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- hash: 3
81
- segments:
82
- - 0
83
- version: "0"
84
- required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
93
56
  requirements: []
94
-
95
57
  rubyforge_project:
96
- rubygems_version: 1.3.7
58
+ rubygems_version: 2.1.10
97
59
  signing_key:
98
- specification_version: 3
60
+ specification_version: 4
99
61
  summary: Pagination for DataMapper, ActiveRecord, and Array
100
- test_files:
101
- - spec/fixtures/ar.rb
102
- - spec/fixtures/dm.rb
103
- - spec/helpers/merb_spec.rb
104
- - spec/helpers/rails_spec.rb
105
- - spec/helpers/shared_spec.rb
106
- - spec/paginate/ar_spec.rb
107
- - spec/paginate/config_spec.rb
108
- - spec/paginate/dm_spec.rb
109
- - spec/paginate/simple_spec.rb
110
- - spec/paginators/orm_spec.rb
111
- - spec/paginators/simple_spec.rb
112
- - spec/shared.rb
113
- - spec/spec_helper.rb
62
+ test_files: []
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Jared Morgan
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/TODO DELETED
@@ -1,23 +0,0 @@
1
- TODO:
2
-
3
- - Rails helpers:
4
- Probably similar to Helpers::Merb. I just don't use Rails enough right now to
5
- work through it.
6
-
7
- - Check for dependencies:
8
- When, for example, Paginate::DM is extended into a class, verify that dm-core
9
- and dm-aggregates are loaded. This would give me more timely errors than
10
- finding out when #paginate is first called.
11
-
12
- - Generic ORM module:
13
- If dependencies are checked for, this would allow a way to use Paginators::ORM
14
- through a module without the dependency check.
15
-
16
- - Includes for ORM collections:
17
- For example:
18
-
19
- DataMapper::Collection.__send__(:include, Paginate::DM)
20
-
21
- What's the best way to do this?
22
- Something similar for AR?
23
- Maybe Paginate::auto_includes which would include such as the above
@@ -1,84 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{jm81-paginate}
8
- s.version = "0.2.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Jared Morgan"]
12
- s.date = %q{2010-12-02}
13
- s.description = %q{This paginate library assists in paginating collections and results of database
14
- queries. It is particularly designed for use with DataMapper and ActiveRecord,
15
- and for the Merb and Rails frameworks, but can be used in many other situations.
16
- }
17
- s.email = %q{jmorgan@morgancreative.net}
18
- s.extra_rdoc_files = [
19
- "LICENSE",
20
- "README.md",
21
- "TODO"
22
- ]
23
- s.files = [
24
- "LICENSE",
25
- "README.md",
26
- "Rakefile",
27
- "TODO",
28
- "jm81-paginate.gemspec",
29
- "lib/helpers/merb.rb",
30
- "lib/helpers/rails.rb",
31
- "lib/helpers/shared.rb",
32
- "lib/jm81-paginate.rb",
33
- "lib/jm81-paginate/version.rb",
34
- "lib/paginate/ar.rb",
35
- "lib/paginate/dm.rb",
36
- "lib/paginate/simple.rb",
37
- "lib/paginators/orm.rb",
38
- "lib/paginators/simple.rb",
39
- "spec/fixtures/ar.rb",
40
- "spec/fixtures/dm.rb",
41
- "spec/helpers/merb_spec.rb",
42
- "spec/helpers/rails_spec.rb",
43
- "spec/helpers/shared_spec.rb",
44
- "spec/paginate/ar_spec.rb",
45
- "spec/paginate/config_spec.rb",
46
- "spec/paginate/dm_spec.rb",
47
- "spec/paginate/simple_spec.rb",
48
- "spec/paginators/orm_spec.rb",
49
- "spec/paginators/simple_spec.rb",
50
- "spec/shared.rb",
51
- "spec/spec.opts",
52
- "spec/spec_helper.rb"
53
- ]
54
- s.homepage = %q{http://github.com/jm81/paginate}
55
- s.require_paths = ["lib"]
56
- s.rubygems_version = %q{1.3.7}
57
- s.summary = %q{Pagination for DataMapper, ActiveRecord, and Array}
58
- s.test_files = [
59
- "spec/fixtures/ar.rb",
60
- "spec/fixtures/dm.rb",
61
- "spec/helpers/merb_spec.rb",
62
- "spec/helpers/rails_spec.rb",
63
- "spec/helpers/shared_spec.rb",
64
- "spec/paginate/ar_spec.rb",
65
- "spec/paginate/config_spec.rb",
66
- "spec/paginate/dm_spec.rb",
67
- "spec/paginate/simple_spec.rb",
68
- "spec/paginators/orm_spec.rb",
69
- "spec/paginators/simple_spec.rb",
70
- "spec/shared.rb",
71
- "spec/spec_helper.rb"
72
- ]
73
-
74
- if s.respond_to? :specification_version then
75
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
76
- s.specification_version = 3
77
-
78
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
79
- else
80
- end
81
- else
82
- end
83
- end
84
-
@@ -1,7 +0,0 @@
1
- module Paginate
2
- module Fixtures
3
- class ArModel < ActiveRecord::Base
4
- extend Paginate::AR
5
- end
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- DataMapper.setup(:default, 'sqlite3::memory:')
2
-
3
- module Paginate
4
- module Fixtures
5
- class DmModel
6
- include DataMapper::Resource
7
- extend Paginate::DM
8
-
9
- property :id, Serial
10
- property :name, String
11
- end
12
- end
13
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Paginate::Helpers::Merb do
4
- before(:all) do
5
- @klass = Class.new
6
- @klass.__send__(:include, Paginate::Helpers::Merb)
7
- @object = @klass.new
8
- end
9
-
10
- it 'should include #page_set method from Shared' do
11
- @object.page_set(5, 10, 2).should ==
12
- [1,0,3,4,5,6,7,0,10]
13
- end
14
-
15
- # Being lazy and just using a mock here.
16
- describe '#pagination_partial' do
17
- it 'should call partial' do
18
- collection = (1..50).to_a
19
- collection.extend(Paginate::Simple)
20
- collection = collection.paginate(:page => 5, :limit => 5)
21
- vars = {
22
- :current_page => 5,
23
- :pages => 10,
24
- :padding => 4
25
- }
26
-
27
- @object.should_receive(:partial).with('partial_name', vars)
28
- @object.pagination_partial(collection, 'partial_name', 4)
29
- end
30
- end
31
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Paginate::Helpers::Rails do
4
- before(:all) do
5
- @klass = Class.new
6
- @klass.__send__(:include, Paginate::Helpers::Rails)
7
- @object = @klass.new
8
- end
9
-
10
- it 'should include #page_set method from Shared' do
11
- @object.page_set(5, 10, 2).should ==
12
- [1,0,3,4,5,6,7,0,10]
13
- end
14
-
15
- # Being lazy and just using a mock here.
16
- describe '#pagination_partial' do
17
- it 'should call render(:partial)' do
18
- collection = (1..50).to_a
19
- collection.extend(Paginate::Simple)
20
- collection = collection.paginate(:page => 5, :limit => 5)
21
- vars = {
22
- :current_page => 5,
23
- :pages => 10,
24
- :padding => 4
25
- }
26
-
27
- @object.should_receive(:render).with(:partial => 'partial_name', :locals => vars)
28
- @object.pagination_partial(collection, 'partial_name', 4)
29
- end
30
- end
31
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Paginate::Helpers::Shared do
4
- before(:all) do
5
- @klass = Class.new
6
- @klass.__send__(:include, Paginate::Helpers::Shared)
7
- @object = @klass.new
8
- end
9
-
10
- describe '#page_set' do
11
- it 'should pad around current page' do
12
- @object.page_set(5, 10, 2).should ==
13
- [1,0,3,4,5,6,7,0,10]
14
-
15
- @object.page_set(5, 10, 1).should ==
16
- [1,0,4,5,6,0,10]
17
-
18
- @object.page_set(5, 10, 0).should ==
19
- [1,0,5,0,10]
20
- end
21
-
22
- it 'should default padding to 3' do
23
- @object.page_set(10, 20).should ==
24
- [1,0,7,8,9,10,11,12,13,0,20]
25
- end
26
-
27
- it 'should not repeat first page' do
28
- @object.page_set(2, 10, 2).should ==
29
- [1,2,3,4,0,10]
30
-
31
- @object.page_set(1, 10, 2).should ==
32
- [1,2,3,0,10]
33
- end
34
-
35
- it 'should not repeat last page' do
36
- @object.page_set(9, 10, 2).should ==
37
- [1,0,7,8,9,10]
38
-
39
- @object.page_set(10, 10, 2).should ==
40
- [1,0,8,9,10]
41
- end
42
-
43
- it 'should include 0 when pages skipped' do
44
- @object.page_set(5, 10, 2).should ==
45
- [1,0,3,4,5,6,7,0,10]
46
- end
47
-
48
- it 'should not include 0 when padding is next to first or last' do
49
- @object.page_set(3, 10, 2).should ==
50
- [1,2,3,4,5,0,10]
51
-
52
- @object.page_set(8, 10, 2).should ==
53
- [1,0,6,7,8,9,10]
54
- end
55
-
56
- it 'should just return [1] if only 1 page' do
57
- @object.page_set(1, 1, 3).should ==
58
- [1]
59
- end
60
- end
61
-
62
- describe '#url_for_pagination' do
63
- it 'should add page query option' do
64
- @object.url_for_pagination(5, 'path', '').should ==
65
- 'path?page=5'
66
- end
67
-
68
- it 'should leave other query options' do
69
- @object.url_for_pagination(5, 'path', 'limit=10&something=text').should ==
70
- 'path?page=5&limit=10&something=text'
71
- end
72
-
73
- it 'should remove existing page option' do
74
- # middle
75
- @object.url_for_pagination(5, 'path', 'limit=10&page=10&something=text').should ==
76
- 'path?page=5&limit=10&something=text'
77
-
78
- # start
79
- @object.url_for_pagination(5, 'path', 'page=10&limit=10&something=text').should ==
80
- 'path?page=5&limit=10&something=text'
81
-
82
- # end
83
- @object.url_for_pagination(5, 'path', 'limit=10&something=text&page=10').should ==
84
- 'path?page=5&limit=10&something=text'
85
- end
86
-
87
- it 'should remove existing negative page option' do
88
- @object.url_for_pagination(5, 'path', 'limit=10&page=-10&something=text').should ==
89
- 'path?page=5&limit=10&something=text'
90
-
91
- @object.url_for_pagination(5, 'path', 'page=-5&limit=10&something=text').should ==
92
- 'path?page=5&limit=10&something=text'
93
- end
94
- end
95
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_record'
3
-
4
- # Setup AR connection, schema
5
- ActiveRecord::Base.establish_connection(
6
- :adapter => "sqlite3",
7
- :database => ":memory:"
8
- )
9
-
10
- ActiveRecord::Schema.define do
11
- create_table :ar_models do |table|
12
- table.column :name, :string
13
- end
14
- end
15
-
16
- require 'fixtures/ar'
17
-
18
- describe 'Paginate::AR' do
19
- before(:each) do
20
- @model = Paginate::Fixtures::ArModel
21
- @model.destroy_all
22
- 1.upto(50) do |i|
23
- @model.create(:name => "Person #{i}")
24
- end
25
- end
26
-
27
- def paginated(options = {})
28
- @model.paginate(options)
29
- end
30
-
31
- def paginated_collected(options = {})
32
- @model.paginate(options).collect {|r| r.name}
33
- end
34
-
35
- def destroy_all
36
- @model.destroy_all
37
- end
38
-
39
- describe '#paginate' do
40
- it_should_behave_like "all paginate methods"
41
- it_should_behave_like "ORM paginate methods"
42
-
43
- it 'should order per options passed' do
44
- paginated_collected(:limit => 3, :page => 1, :order => 'id desc').should ==
45
- ["Person 50", "Person 49", "Person 48"]
46
- end
47
-
48
- it 'should accept conditions (representative of options to .all)' do
49
- collection = paginated(:limit => 3, :page => 1, :conditions => ['name like ?', 'Person 3%'])
50
- collection.collect {|r| r.name}.should ==
51
- ["Person 3", "Person 30", "Person 31"]
52
- collection.pages.should == 4
53
- end
54
- end
55
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Paginate.config" do
4
- before(:each) do
5
- # Force to default state
6
- Paginate.instance_variable_set(:@config, nil)
7
- end
8
-
9
- after(:all) do
10
- # Force to default state for other specs
11
- Paginate.instance_variable_set(:@config, nil)
12
- end
13
-
14
- it 'should initialize with DEFAULTS' do
15
- Paginate.config.should == Paginate::DEFAULTS
16
- end
17
-
18
- it 'should be writable' do
19
- Paginate.config[:default_limit] = 1
20
- Paginate.instance_variable_get(:@config)[:default_limit].should == 1
21
- end
22
-
23
- describe ':default_limit' do
24
- it 'should be used as default limit' do
25
- Paginate.config[:default_limit] = 3
26
- ary = (1..20).collect {|i| 'Item #{i}'}
27
- ary.extend(Paginate::Simple)
28
- ary.paginate.length.should == 3
29
- end
30
- end
31
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
- require 'dm-core'
3
- require 'dm-aggregates'
4
- require 'dm-migrations'
5
- require 'fixtures/dm'
6
-
7
- describe Paginate::DM do
8
- before(:all) do
9
- @model = Paginate::Fixtures::DmModel
10
- @model.auto_migrate!
11
- end
12
-
13
- before(:each) do
14
- @model.all.destroy!
15
- 1.upto(50) do |i|
16
- @model.create(:name => "Person #{i}")
17
- end
18
- end
19
-
20
- def paginated(options = {})
21
- @model.paginate(options)
22
- end
23
-
24
- def paginated_collected(options = {})
25
- @model.paginate(options).collect {|r| r.name}
26
- end
27
-
28
- def destroy_all
29
- @model.all.destroy!
30
- end
31
-
32
- describe '#paginate' do
33
- it_should_behave_like "all paginate methods"
34
- it_should_behave_like "ORM paginate methods"
35
-
36
- it 'should order per options passed' do
37
- paginated_collected(:limit => 3, :page => 1, :order => [:id.desc]).should ==
38
- ["Person 50", "Person 49", "Person 48"]
39
- end
40
-
41
- it 'should accept conditions (representative of options to .all)' do
42
- collection = paginated(:limit => 3, :page => 1, :name.like => 'Person 3%')
43
- collection.collect {|r| r.name}.should ==
44
- ["Person 3", "Person 30", "Person 31"]
45
- collection.pages.should == 4
46
- end
47
- end
48
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Paginate::Simple do
4
- before(:each) do
5
- @full_collection = []
6
- 1.upto(50) do |i|
7
- @full_collection << "Person #{i}"
8
- end
9
- @full_collection.extend(Paginate::Simple)
10
- end
11
-
12
- def paginated(options = {})
13
- @full_collection.paginate(options)
14
- end
15
-
16
- def paginated_collected(options = {})
17
- paginated(options)
18
- end
19
-
20
- def destroy_all
21
- 50.times { @full_collection.pop }
22
- end
23
-
24
- describe '#paginate' do
25
- it_should_behave_like "all paginate methods"
26
- end
27
- end
@@ -1,49 +0,0 @@
1
- require 'dm-core'
2
- require 'dm-aggregates'
3
- require 'spec_helper'
4
- require 'fixtures/dm'
5
-
6
- describe Paginate::Paginators::ORM do
7
- Model = Paginate::Fixtures::DmModel
8
- before(:all) do
9
- Model.auto_migrate!
10
- end
11
-
12
- before(:each) do
13
- Model.all.destroy!
14
- 1.upto(50) do |i|
15
- Model.create(:name => "Person #{i}")
16
- end
17
- @model = Model
18
- @klass = Paginate::Paginators::ORM
19
- end
20
-
21
- def paginated(options = {})
22
- @klass.new(Model, options).paginate
23
- end
24
-
25
- def paginated_collected(options = {})
26
- paginated(options).collect {|r| r.name}
27
- end
28
-
29
- def destroy_all
30
- Model.all.destroy!
31
- end
32
-
33
- describe '#paginate' do
34
- it_should_behave_like "all paginate methods"
35
- it_should_behave_like "ORM paginate methods"
36
-
37
- it 'should order per options passed' do
38
- paginated_collected(:limit => 3, :page => 1, :order => [:id.desc]).should ==
39
- ["Person 50", "Person 49", "Person 48"]
40
- end
41
-
42
- it 'should accept conditions (representative of options to .all)' do
43
- collection = paginated(:limit => 3, :page => 1, :name.like => 'Person 3%')
44
- collection.collect {|r| r.name}.should ==
45
- ["Person 3", "Person 30", "Person 31"]
46
- collection.pages.should == 4
47
- end
48
- end
49
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Paginate::Paginators::Simple do
4
- # No instance variables are expected by the shared specs, only a +paginated+
5
- # and a +destroy_all+ method.
6
- before(:each) do
7
- @full_collection = []
8
- 1.upto(50) do |i|
9
- @full_collection << "Person #{i}"
10
- end
11
- @klass = Paginate::Paginators::Simple
12
- end
13
-
14
- # paginated is called by shared specs to get a paginated result for the
15
- # collection.
16
- def paginated(options = {})
17
- @klass.new(@full_collection, options).paginate
18
- end
19
-
20
- # paginated_collected returns results in a standard format: It should just
21
- # return an Array of Strings, such as:
22
- # ["Person 1", "Person 2"], so #collect may be needed in more complex
23
- # classes.
24
- def paginated_collected(options = {})
25
- paginated(options)
26
- end
27
-
28
- # destroy_all is called to make @full_collection an empty set. This may mean
29
- # that all records need to be deleted in, for example, an ORM Paginator.
30
- def destroy_all
31
- @full_collection = []
32
- end
33
-
34
- describe '#paginate' do
35
- it_should_behave_like "all paginate methods"
36
- end
37
- end
@@ -1,155 +0,0 @@
1
- # Specs shared by Paginator classes and Paginate modules. These test that the
2
- # Paginator (directly or via a module) returns the right results based on
3
- # +page+ and +limit+ options.
4
- #
5
- # +paginated+, +paginated_collected+ and +destroy_all+ methods are expected
6
- # by specs. A +@model+ instance variable is expected for "ORM paginate methods".
7
- # See simple_spec.rb for examples.
8
- #
9
- # +paginated+ is called by shared specs to get a paginated result for the
10
- # collection.
11
- #
12
- # +paginated_collected+ calls paginate, but returns an Array of Strings. If all
13
- # results were returned, it should return an Array of
14
- # ["Person 1", "Person 2", ..., "Person 50"] (50 records total). #collect may be
15
- # needed in more complex classes. For example:
16
- #
17
- # @klass.paginate(@full_collection, options).collect {|r| r.name}
18
- # Model.paginate(options).collect {|r| r.name}
19
- #
20
- # +destroy_all+ is called to make the full collection an empty set. This may
21
- # mean that all records need to be deleted in, for example, an ORM Paginator.
22
-
23
- shared_examples_for "all paginate methods" do
24
- describe ':page option' do
25
- it 'should return correct results per page (correct offset, limit)' do
26
- paginated_collected(:page => 1, :limit => 5).should ==
27
- ["Person 1", "Person 2", "Person 3", "Person 4", "Person 5"]
28
-
29
- paginated_collected(:page => 2, :limit => 5).should ==
30
- ["Person 6", "Person 7", "Person 8", "Person 9", "Person 10"]
31
- end
32
-
33
- it 'should return page 1 if options[:page] == 0' do
34
- paginated_collected(:page => 0, :limit => 3).should ==
35
- ["Person 1", "Person 2", "Person 3"]
36
- end
37
-
38
- it 'should return page 1 if options[:page] not set' do
39
- paginated_collected(:limit => 3, :page => -50).should ==
40
- ["Person 1", "Person 2", "Person 3"]
41
- end
42
-
43
- it 'should return last page if options[:page] > total pages' do
44
- paginated_collected(:limit => 5, :page => 11).should ==
45
- ["Person 46", "Person 47", "Person 48", "Person 49", "Person 50"]
46
-
47
- paginated_collected(:limit => 5, :page => 20).should ==
48
- ["Person 46", "Person 47", "Person 48", "Person 49", "Person 50"]
49
- end
50
-
51
- it 'should return last page for page == -1' do
52
- paginated_collected(:limit => 5, :page => -1).should ==
53
- ["Person 46", "Person 47", "Person 48", "Person 49", "Person 50"]
54
-
55
- paginated_collected(:limit => 3, :page => -1).should ==
56
- ["Person 49", "Person 50"]
57
- end
58
-
59
- it 'should return page from last for negative options[:page]' do
60
- paginated_collected(:limit => 3, :page => -2).should ==
61
- ["Person 46", "Person 47", "Person 48"]
62
-
63
- paginated_collected(:limit => 3, :page => -3).should ==
64
- ["Person 43", "Person 44", "Person 45"]
65
- end
66
-
67
- it 'should return first page for very negative options[:page] values' do
68
- paginated_collected(:limit => 3, :page => -50).should ==
69
- ["Person 1", "Person 2", "Person 3"]
70
- end
71
-
72
- it 'should have at least one result on the last page' do
73
- paginated(:limit => 5, :page => 10).should_not be_empty
74
-
75
- collection = paginated(:limit => 5, :page => 11)
76
- collection.should_not be_empty
77
- collection.current_page.should == 10
78
- end
79
-
80
- it 'should default limit to config[:default_limit]' do
81
- paginated().length.should == Paginate.config[:default_limit]
82
- end
83
- end
84
-
85
- describe '#current_page' do
86
- it 'should be added to collection' do
87
- collection = paginated(:limit => 10)
88
- # collection.methods.should include("current_page")
89
- # Not sure why the above won't work. #singleton_methods doesn't either.
90
- collection.current_page.should be_kind_of(Integer)
91
- end
92
-
93
- it 'should be the number of the current page' do
94
- paginated(:limit => 10, :page => 2).current_page.should == 2
95
- paginated(:limit => 10, :page => 5).current_page.should == 5
96
- end
97
-
98
- it 'should be 1 if there are no results' do
99
- destroy_all
100
- paginated(:limit => 10).current_page.should == 1
101
- end
102
-
103
- it 'should be >= 1 and <= #pages (ie actual page, not given page)' do
104
- paginated(:limit => 10, :page => -100).current_page.should == 1
105
- paginated(:limit => 10, :page => 100).current_page.should == 5
106
- paginated(:limit => 10, :page => -1).current_page.should == 5
107
- paginated(:limit => 10, :page => 0).current_page.should == 1
108
- end
109
- end
110
-
111
- describe '#pages' do
112
- it 'should be added to collection' do
113
- collection = paginated(:limit => 10)
114
- # collection.methods.should include("pages")
115
- # Not sure why the above won't work. #singleton_methods doesn't either.
116
- collection.pages.should be_kind_of(Integer)
117
- end
118
-
119
- it 'should be the total number of pages for the collection' do
120
- paginated(:limit => 10).pages.should == 5
121
- paginated(:limit => 49).pages.should == 2
122
- paginated(:limit => 50).pages.should == 1
123
- end
124
-
125
- it 'should be 1 if there are no results' do
126
- destroy_all
127
- paginated(:limit => 10).pages.should == 1
128
- end
129
- end
130
- end
131
-
132
- # These specs are specific to ORM classes/modules, testing that +all+ receives
133
- # the correct options.
134
- #
135
- # A +@model+ instance variable is expected.
136
- shared_examples_for "ORM paginate methods" do
137
- it "should set limit and offset options" do
138
- limit = 10
139
-
140
- @model.should_receive(:all).with(:offset => 0, :limit => limit)
141
- paginated(:page => 1, :limit => limit)
142
-
143
- @model.should_receive(:all).with(:offset => 0, :limit => limit + 1)
144
- paginated(:page => 1, :limit => limit + 1)
145
-
146
- @model.should_receive(:all).with(:offset => 0, :limit => limit + 2)
147
- paginated(:limit => limit + 2)
148
-
149
- @model.should_receive(:all).with(:offset => limit, :limit => limit)
150
- paginated(:page => 2, :limit => limit)
151
-
152
- @model.should_receive(:all).with(:offset => 40, :limit => limit)
153
- paginated(:page => -1, :limit => limit)
154
- end
155
- end
@@ -1,6 +0,0 @@
1
- --colour
2
- --format
3
- progress
4
- --loadby
5
- mtime
6
- --reverse
@@ -1,5 +0,0 @@
1
- require 'rubygems'
2
- require 'spec'
3
-
4
- require 'jm81-paginate'
5
- require 'shared'