simply_paginate 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39276d355bff6efc4caf226f0c12651ceb5f57cb
4
+ data.tar.gz: 74c736370477949887a729652a116d43ff0cf880
5
+ SHA512:
6
+ metadata.gz: 828ca2c53d150cd0e29e9da3aea11e573dd89e843a3d663ccaa2bfe3e4b7a9e24bb647f5a030ba50b5e7daa6899a9d63eeae4c6f3dc7887d09eaa07fd744d164
7
+ data.tar.gz: 61ded93564918688aecc72ca5d1243b02464bc536303f5e053459b6dd4355cfa341bc292b247b2641844a69bb2774ef1f1e3ee9dc77940cae7ad42bb6b1c3d79
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/.travis.yml CHANGED
@@ -1,11 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
3
6
  - 1.9.3
4
- - 1.9.2
5
- - jruby-18mode
6
- - jruby-19mode
7
- - rbx-18mode
8
- - rbx-19mode
9
- - jruby-head
10
- - 1.8.7
11
- - ree
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in simply_paginate.gemspec
4
4
  gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simply_paginate (0.0.5)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.0.4)
11
+ rspec (3.5.0)
12
+ rspec-core (~> 3.5.0)
13
+ rspec-expectations (~> 3.5.0)
14
+ rspec-mocks (~> 3.5.0)
15
+ rspec-core (3.5.3)
16
+ rspec-support (~> 3.5.0)
17
+ rspec-expectations (3.5.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.5.0)
20
+ rspec-mocks (3.5.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.5.0)
23
+ rspec-support (3.5.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.3)
30
+ rake
31
+ rspec
32
+ simply_paginate!
33
+
34
+ BUNDLED WITH
35
+ 1.12.5
data/Rakefile CHANGED
@@ -1,10 +1,7 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
3
4
 
4
- task :default => [:spec]
5
+ RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- Rake::TestTask.new :spec do |test|
7
- test.libs = ['lib', 'spec']
8
- test.verbose = true
9
- test.test_files = FileList['spec/*_spec.rb']
10
- end
7
+ task :default => :spec
@@ -8,8 +8,8 @@ module SimplyPaginate
8
8
  @size = size
9
9
 
10
10
  @move_page = lambda do |number|
11
- new_index = @index + number
12
- Page.new(new_index, @collection, @size) unless (new_index == 0) || (new_index > (@collection.count.to_f / @size.to_f).ceil)
11
+ new_index = index + number
12
+ Page.new(new_index, collection, size) unless (new_index <= 0) || (new_index > (collection.count.to_f / size.to_f).ceil)
13
13
  end
14
14
  end
15
15
 
@@ -29,7 +29,7 @@ module SimplyPaginate
29
29
  end
30
30
 
31
31
  def ==(other)
32
- (index == other.index) && (elements == other.elements) if other.respond_to?(:index) && other.respond_to?(:elements)
32
+ (index == other.index) && (elements == other.elements)
33
33
  end
34
34
  end
35
35
  end
@@ -33,19 +33,19 @@ module SimplyPaginate
33
33
  (@collection.count.to_f / @per_page.to_f).ceil
34
34
  end
35
35
 
36
- def [](pos)
37
- Page.new(pos, @collection) unless pos == 0 || pos > total_pages
36
+ def [](index)
37
+ Page.new(index, @collection, @per_page) unless collection.empty? || index <= 0 || index > total_pages
38
38
  end
39
39
 
40
40
  ## Iteration
41
41
 
42
42
  def next!
43
- raise NoMethodError.new("You need to start before iterating") unless @current
44
- @current = @current.next
43
+ raise NoMethodError.new("You need to start before iterating") unless current
44
+ @current = current.next
45
45
  end
46
46
 
47
47
  def next?
48
- @current != nil
48
+ current != nil
49
49
  end
50
50
 
51
51
  def start
@@ -1,3 +1,3 @@
1
1
  module SimplyPaginate
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "minitest"
22
+ spec.add_development_dependency "rspec"
23
23
  spec.add_development_dependency "rake"
24
24
  end
data/spec/page_spec.rb CHANGED
@@ -1,39 +1,94 @@
1
- require 'spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  include SimplyPaginate
4
4
 
5
5
  describe Page do
6
- include Helpers
6
+ context "when is empty" do
7
+ let(:page) { Page.new(0, []) }
8
+ subject { page }
7
9
 
8
- let(:first_page) { build_page 1 }
10
+ describe "#elements" do
11
+ specify { expect(subject.elements).to be_nil }
12
+ end
9
13
 
10
- let(:second_page) { build_page 2 }
14
+ describe "#next" do
15
+ specify { expect(subject.next).to be_nil }
16
+ end
11
17
 
12
- let(:last_page) { build_page 4 }
18
+ describe "#previous" do
19
+ specify { expect(subject.previous).to be_nil }
20
+ end
13
21
 
14
- it "must represent a specific page on a collection" do
15
- first_page.elements.must_equal [1, 2, 3]
16
- first_page.index.must_equal SimplyPaginate::FIRST_PAGE_INDEX
17
- end
22
+ describe "#==" do
23
+ subject { page == other_page }
24
+ let(:other_page) { double }
18
25
 
19
- it "must be able to retrieve it's elements" do
20
- first_page.elements.must_equal [1, 2, 3]
21
- end
26
+ context "when they are equal" do
22
27
 
23
- it "must be able to compare with other page" do
24
- first_page.must_equal first_page
25
- first_page.wont_equal second_page
26
- first_page.wont_equal Page.new(1, page_array_collection, 5)
27
- first_page.must_equal Page.new(1, [1, 2, 3], 3)
28
- end
28
+ before(:each) do
29
+ allow(other_page).to receive(:index).and_return(0)
30
+ allow(other_page).to receive(:elements).and_return(nil)
31
+ end
32
+
33
+ specify { expect(subject).to eq(true) }
34
+ end
29
35
 
30
- it "must be able to move forward" do
31
- first_page.next.must_equal second_page
32
- last_page.next.must_be_nil
36
+ context "when they are different" do
37
+ context "and the second has different values" do
38
+ before(:each) do
39
+ allow(other_page).to receive(:index).and_return(1)
40
+ allow(other_page).to receive(:elements).and_return([])
41
+ end
42
+
43
+ specify { expect(subject).to eq(false) }
44
+ end
45
+ end
46
+ end
33
47
  end
34
48
 
35
- it "must be able to move backwards" do
36
- first_page.previous.must_be_nil
37
- second_page.previous.must_equal first_page
49
+ context "when has elements" do
50
+ let(:page) { Page.new(1, [1,2,3,4,5,6,7,8,9], 3) }
51
+ subject { page }
52
+
53
+ describe "#elements" do
54
+ specify { expect(subject.elements).to eq([1,2,3]) }
55
+ end
56
+
57
+ describe "#next" do
58
+ specify { expect(subject.next).to be_instance_of(Page) }
59
+ specify { expect(subject.next.index).to eq(subject.index + 1) }
60
+ end
61
+
62
+ describe "#previous" do
63
+ before(:each) { allow(page).to receive(:index).and_return(2) }
64
+
65
+ specify { expect(subject.previous).to be_instance_of(Page) }
66
+ specify { expect(subject.previous.index).to eq(subject.index - 1) }
67
+ end
68
+
69
+ describe "#==" do
70
+ let(:other_page) { double }
71
+ subject { page == other_page }
72
+
73
+ context "when both are equal" do
74
+ before(:each) do
75
+ allow(other_page).to receive(:index).and_return(1)
76
+ allow(other_page).to receive(:elements).and_return([1,2,3])
77
+ end
78
+
79
+ specify { expect(subject).to eq(true) }
80
+ end
81
+
82
+ context "when they are different" do
83
+ context "because the second has different values" do
84
+ before(:each) do
85
+ allow(other_page).to receive(:index).and_return(1)
86
+ allow(other_page).to receive(:elements).and_return([])
87
+ end
88
+
89
+ specify { expect(subject).to eq(false) }
90
+ end
91
+ end
92
+ end
38
93
  end
39
94
  end
@@ -1,77 +1,76 @@
1
- require 'spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
- Paginator.per_page = 3
3
+ include SimplyPaginate
4
4
 
5
5
  describe Paginator do
6
- include Helpers
6
+ let(:paginator) { Paginator.new([1,2,3,4,5,6,7,8,9], 3) }
7
+ subject { paginator }
7
8
 
8
- let(:pages) { Paginator.new page_array_collection }
9
+ describe "#[]" do
10
+ let (:index) { 1 }
11
+ context "there are no elements to paginate" do
12
+ before(:each) { allow(subject).to receive(:collection).and_return([]) }
9
13
 
10
- let(:first_page) { build_page 1 }
14
+ specify { expect(subject[index]).to be_nil }
15
+ end
11
16
 
12
- let(:last_page) { build_page 4 }
17
+ context "there is at least one element" do
18
+ let(:elements) { [1] }
19
+ before(:each) { allow(subject).to receive(:collection).and_return(elements) }
13
20
 
14
- it "must be able to iterate using each" do
15
- count = 0
16
- results = []
21
+ specify { expect(subject[index]).to be_instance_of(Page) }
22
+ end
17
23
 
18
- pages.each do |page|
19
- page.wont_be_nil
20
- results << page.elements
24
+ context "index is zero" do
25
+ let(:zero_index) { 0 }
26
+ specify { expect(subject[zero_index]).to be_nil }
27
+ end
21
28
 
22
- count += 1
29
+ context "index is negative" do
30
+ let(:negative_index) { -1 }
31
+ specify { expect(subject[negative_index]).to be_nil }
23
32
  end
24
33
 
25
- count.must_equal 4
26
- results.must_equal [[1,2,3], [4,5,6], [7,8,9], [10]]
34
+ context "index greater than amount of pages" do
35
+ specify { expect(subject[4]).to be_nil }
36
+ end
27
37
  end
28
38
 
29
- it "must be able to tell how many pages there are" do
30
- pages.total_pages.must_equal 4
31
- end
39
+ describe "iteration" do
40
+ describe "next!" do
41
+ context "iteration hasn't started" do
42
+ specify { expect { subject.next! }.to raise_error("You need to start before iterating") }
43
+ end
32
44
 
33
- it "must be able to retrieve a certain page" do
34
- pages[0].must_be_nil
35
- pages[1].wont_be_nil
36
- pages[1].must_equal first_page
37
- pages[4].must_equal last_page
38
- pages[5].must_be_nil
39
- end
45
+ context "iteration started" do
46
+ before(:each) { subject.start }
40
47
 
41
- it "must be able to retrieve the first page" do
42
- pages.first.must_equal first_page
43
- end
48
+ specify do
49
+ expect(subject.next!).to be_instance_of(Page)
50
+ end
51
+ end
44
52
 
45
- it "must be able to retrieve the last page" do
46
- pages.last.must_equal pages[4]
47
- end
53
+ context "there are no more pages" do
54
+ before(:each) { allow(subject).to receive(:current).and_return(nil) }
48
55
 
49
- describe "when iterating using 'start', 'next!' and 'next?'" do
50
- it "must need to start before moving to the next " do
51
- lambda { pages.next! }.must_raise NoMethodError
52
- end
53
-
54
- it "must move to the next page using 'next!'" do
55
- iteration_pages = pages
56
- iteration_pages.start
57
- iteration_pages.next!
58
- iteration_pages.current.must_equal build_page(2)
56
+ specify { expect { subject.next! }.to raise_error("You need to start before iterating") }
57
+ end
59
58
  end
59
+ end
60
60
 
61
- it "must retrieve the current page using 'current'" do
62
- iteration_pages = pages
63
- iteration_pages.current.must_be_nil
64
- iteration_pages.start
65
- iteration_pages.current.must_equal first_page
61
+ describe "initialize" do
62
+ describe "without setting a per page" do
63
+ specify "it falls back to class level per_page" do
64
+ paginator = Paginator.new([0,1,2,3,4,5,6,7,8,9])
65
+ expect(paginator.first.elements.count).to eq(10)
66
+ end
66
67
  end
67
68
 
68
- it "must retrieve if we can get a next value using 'next?'" do
69
- iteration_pages = pages
70
- iteration_pages.next?.must_equal false
71
- iteration_pages.start
72
- iteration_pages.next?.must_equal true
73
- 4.times { iteration_pages.next! }
74
- iteration_pages.next?.must_equal false
69
+ describe "setting a per page" do
70
+ specify "it falls back to class level per_page" do
71
+ paginator = Paginator.new([0,1,2,3,4,5,6,7,8,9], 3)
72
+ expect(paginator.first.elements.count).to eq(3)
73
+ end
75
74
  end
76
75
  end
77
76
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,2 @@
1
- require 'bundler'
2
- require 'minitest/autorun'
3
- Bundler.require
4
-
5
- module Helpers
6
- def page_array_collection
7
- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
8
- end
9
-
10
- def build_page(number)
11
- lambda { Page.new number, page_array_collection, 3 }.call
12
- end
13
- end
1
+ require 'rspec'
2
+ require 'simply_paginate'
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simply_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Álvaro F. Lara
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-26 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
27
  - !ruby/object:Gem::Dependency
31
- name: minitest
28
+ name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: This gem is a simple paginator for Enumerable collections
@@ -66,9 +59,10 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .gitignore
70
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".travis.yml"
71
64
  - Gemfile
65
+ - Gemfile.lock
72
66
  - LICENSE.txt
73
67
  - README.md
74
68
  - Rakefile
@@ -86,30 +80,28 @@ files:
86
80
  homepage: https://github.com/guiman/simply_paginate
87
81
  licenses:
88
82
  - MIT
83
+ metadata: {}
89
84
  post_install_message:
90
85
  rdoc_options: []
91
86
  require_paths:
92
87
  - lib
93
88
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
89
  requirements:
96
- - - ! '>='
90
+ - - ">="
97
91
  - !ruby/object:Gem::Version
98
92
  version: '0'
99
93
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
94
  requirements:
102
- - - ! '>='
95
+ - - ">="
103
96
  - !ruby/object:Gem::Version
104
97
  version: '0'
105
98
  requirements: []
106
99
  rubyforge_project:
107
- rubygems_version: 1.8.23
100
+ rubygems_version: 2.5.1
108
101
  signing_key:
109
- specification_version: 3
102
+ specification_version: 4
110
103
  summary: You enumerate it we will simply paginate it
111
104
  test_files:
112
105
  - spec/page_spec.rb
113
106
  - spec/paginator_spec.rb
114
107
  - spec/spec_helper.rb
115
- has_rdoc: