paginate 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paginate (0.1.3)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ abstract (1.0.0)
10
+ actionpack (3.0.3)
11
+ activemodel (= 3.0.3)
12
+ activesupport (= 3.0.3)
13
+ builder (~> 2.1.2)
14
+ erubis (~> 2.6.6)
15
+ i18n (~> 0.4)
16
+ rack (~> 1.2.1)
17
+ rack-mount (~> 0.6.13)
18
+ rack-test (~> 0.5.6)
19
+ tzinfo (~> 0.3.23)
20
+ activemodel (3.0.3)
21
+ activesupport (= 3.0.3)
22
+ builder (~> 2.1.2)
23
+ i18n (~> 0.4)
24
+ activerecord (3.0.3)
25
+ activemodel (= 3.0.3)
26
+ activesupport (= 3.0.3)
27
+ arel (~> 2.0.2)
28
+ tzinfo (~> 0.3.23)
29
+ activesupport (3.0.3)
30
+ archive-tar-minitar (0.5.2)
31
+ arel (2.0.6)
32
+ builder (2.1.2)
33
+ columnize (0.3.2)
34
+ diff-lcs (1.1.2)
35
+ erubis (2.6.6)
36
+ abstract (>= 1.0.0)
37
+ i18n (0.5.0)
38
+ linecache19 (0.5.11)
39
+ ruby_core_source (>= 0.1.4)
40
+ nokogiri (1.4.4)
41
+ notifier (0.1.2)
42
+ rack (1.2.1)
43
+ rack-mount (0.6.13)
44
+ rack (>= 1.0.0)
45
+ rack-test (0.5.7)
46
+ rack (>= 1.0)
47
+ rspec (2.4.0)
48
+ rspec-core (~> 2.4.0)
49
+ rspec-expectations (~> 2.4.0)
50
+ rspec-mocks (~> 2.4.0)
51
+ rspec-core (2.4.0)
52
+ rspec-expectations (2.4.0)
53
+ diff-lcs (~> 1.1.2)
54
+ rspec-mocks (2.4.0)
55
+ ruby-debug-base19 (0.11.24)
56
+ columnize (>= 0.3.1)
57
+ linecache19 (>= 0.5.11)
58
+ ruby_core_source (>= 0.1.4)
59
+ ruby-debug19 (0.11.6)
60
+ columnize (>= 0.3.1)
61
+ linecache19 (>= 0.5.11)
62
+ ruby-debug-base19 (>= 0.11.19)
63
+ ruby_core_source (0.1.4)
64
+ archive-tar-minitar (>= 0.5.2)
65
+ sqlite3-ruby (1.3.2)
66
+ test_notifier (0.3.6)
67
+ notifier
68
+ tzinfo (0.3.23)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ actionpack (~> 3.0.0)
75
+ activerecord (~> 3.0.0)
76
+ activesupport (~> 3.0.0)
77
+ nokogiri
78
+ paginate!
79
+ rspec (~> 2.4.0)
80
+ ruby-debug19
81
+ sqlite3-ruby
82
+ test_notifier
data/README.rdoc CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support.
4
4
 
5
+ Works only with <b>Rails 3+</b>.
6
+
5
7
  == Install
6
8
 
7
9
  sudo gem install paginate
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
- require "rake/testtask"
2
- require "./lib/paginate/version"
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
3
 
4
+ require "rake/testtask"
4
5
  Rake::TestTask.new do |t|
5
6
  t.libs += %w[ test lib ]
6
7
  t.test_files = FileList["test/**/*_test.rb"]
@@ -8,20 +9,5 @@ Rake::TestTask.new do |t|
8
9
  t.ruby_opts = %w[ -rubygems ]
9
10
  end
10
11
 
11
- begin
12
- require "jeweler"
13
-
14
- Jeweler::Tasks.new do |gem|
15
- gem.name = "paginate"
16
- gem.version = Paginate::Version::STRING
17
- gem.summary = "Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support."
18
- gem.email = "fnando.vieira@gmail.com"
19
- gem.homepage = "http://github.com/fnando/paginate"
20
- gem.authors = ["Nando Vieira"]
21
- gem.files = FileList["lib/**/*", "Rakefile", "README.rdoc"]
22
- end
23
-
24
- Jeweler::GemcutterTasks.new
25
- rescue LoadError => e
26
- puts "You don't have Jeweler installed, so you won't be able to build this gem."
27
- end
12
+ require "rspec/core/rake_task"
13
+ RSpec::Core::RakeTask.new
data/lib/paginate.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "i18n"
2
+ require "active_record"
2
3
  require "paginate/base"
3
4
  require "paginate/config"
4
5
  require "paginate/helper"
@@ -6,8 +7,6 @@ require "paginate/renderer"
6
7
  require "paginate/active_record"
7
8
  require "paginate/action_controller"
8
9
 
9
- I18n.load_path += Dir[File.dirname(__FILE__) + "/paginate/locales/**/*.yml"]
10
-
11
10
  module Paginate
12
11
  def self.setup(&block)
13
12
  yield Config
@@ -1 +1,5 @@
1
- require "paginate/active_record/ext" if defined?(ActiveRecord)
1
+ module ActiveRecord
2
+ class Base
3
+ scope :paginate, proc {|*args| Paginate::Base.new(*args).to_options }
4
+ end
5
+ end
data/lib/paginate/base.rb CHANGED
@@ -29,7 +29,7 @@ module Paginate
29
29
  end
30
30
 
31
31
  def offset
32
- (page - 1) * limit
32
+ (page - 1) * (limit - 1)
33
33
  end
34
34
 
35
35
  def limit
@@ -32,9 +32,8 @@ module Paginate
32
32
  Paginate::Renderer.new(options).render
33
33
  end
34
34
 
35
- # In order to iterate the correct items you have to skip the latest collection's item.
36
- # We added this helper to automatically skip the latest item only if there's a next page,
37
- # which means that we have an extra item.
35
+ # In order to iterate the correct items you have to skip the last collection's item.
36
+ # We added this helper to automatically skip the last item only if there's a next page.
38
37
  #
39
38
  # <% iterate @items do |item| %>
40
39
  # <% end %>
@@ -44,7 +43,6 @@ module Paginate
44
43
  # <% iterate @items do |item, i|
45
44
  # <% end %>
46
45
  #
47
- #
48
46
  # If you set a custom size while fetching items from database, you need to inform it while iterating.
49
47
  #
50
48
  # @items = Item.paginate(:page => 1, :size => 5)
@@ -54,12 +52,16 @@ module Paginate
54
52
  # <% iterate @items, :size => 5 do |item| %>
55
53
  # <% end %>
56
54
  #
55
+ # You can receive the iteration counter by expecting two arguments.
56
+ #
57
+ # <% iterate @items do |item, i| do %>
58
+ # <% end %>
59
+ #
57
60
  def iterate(collection, options = {}, &block)
58
61
  options.reverse_merge!(:size => Paginate::Config.size)
59
- block_arity = block.arity
60
62
 
61
63
  collection[0, options[:size]].each_with_index do |item, i|
62
- if block_arity == 1
64
+ if block.arity == 1
63
65
  yield item
64
66
  else
65
67
  yield item, i
@@ -67,11 +67,7 @@ module Paginate
67
67
 
68
68
  html << %[</ul>]
69
69
 
70
- if html.respond_to?(:html_safe)
71
- html.html_safe
72
- else
73
- html
74
- end
70
+ html.html_safe
75
71
  end
76
72
  end
77
73
  end
@@ -1,8 +1,8 @@
1
1
  module Paginate
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 1
5
- PATCH = 3
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/paginate.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "paginate/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "paginate"
7
+ s.version = Paginate::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nando Vieira"]
10
+ s.email = ["fnando.vieira@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/kitabu"
12
+ s.summary = "Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support."
13
+ s.description = s.summary
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "nokogiri"
21
+ s.add_development_dependency "test_notifier"
22
+ s.add_development_dependency "sqlite3-ruby"
23
+ s.add_development_dependency "activesupport", "~> 3.0.0"
24
+ s.add_development_dependency "activerecord", "~> 3.0.0"
25
+ s.add_development_dependency "actionpack", "~> 3.0.0"
26
+ s.add_development_dependency "rspec", "~> 2.4.0"
27
+ s.add_development_dependency "ruby-debug19"
28
+ end
@@ -1,8 +1,8 @@
1
- # encoding: utf-8
2
- require "test_helper"
1
+ # -*- encoding: utf-8 -*-
2
+ require "spec_helper"
3
3
 
4
- class ActionViewTest < Test::Unit::TestCase
5
- def setup
4
+ describe "ActionView support" do
5
+ before do
6
6
  @request = OpenStruct.new
7
7
  @params = Hash.new
8
8
 
@@ -12,7 +12,7 @@ class ActionViewTest < Test::Unit::TestCase
12
12
  @view = ActionView::Base.new
13
13
  @view.controller = @controller
14
14
  @view.extend(Paginate::Helper)
15
- @view.stubs(:request).returns(@request)
15
+ @view.stub :request => @request
16
16
 
17
17
  @helper = Object.new
18
18
  @helper.extend(Paginate::Helper)
@@ -25,98 +25,97 @@ class ActionViewTest < Test::Unit::TestCase
25
25
  I18n.locale = :en
26
26
  end
27
27
 
28
- def test_display_pagination_list
28
+ it "should display pagination list" do
29
29
  @request.fullpath = "/some/path?page=1"
30
30
  html = render(:default, [])
31
31
 
32
- assert_equal 1, html.css("ul.paginate").count
33
- assert_equal 3, html.css("ul.paginate > li").count
32
+ html.css("ul.paginate").count.should == 1
33
+ html.css("ul.paginate > li").count.should == 3
34
34
  end
35
35
 
36
- def test_disabled
36
+ it "should add .disabled class when have no items" do
37
37
  @request.fullpath = "/some/path"
38
38
  html = render(:default, [])
39
39
 
40
- assert_not_nil html.css("ul.paginate.disabled").first
40
+ html.css("ul.paginate.disabled").first.should_not be_nil
41
41
  end
42
42
 
43
- def test_display_next_page_link
43
+ it "should display next page link" do
44
44
  @request.fullpath = "/some/path?page=1"
45
45
  html = render(:default, Array.new(11))
46
46
  link = html.css("li.next-page > a").first
47
47
 
48
- assert_not_nil link
49
- assert_equal "/some/path?page=2", link["href"]
50
- assert_equal "Next page", link.text
48
+ link.should_not be_nil
49
+ link["href"].should == "/some/path?page=2"
50
+ link.text.should == "Next page"
51
51
  end
52
52
 
53
- def test_display_next_page_link_from_block
53
+ it "should display next page link using proc as url" do
54
54
  @request.fullpath = "/some/path?page=1"
55
55
  html = render(:block_as_url, Array.new(11))
56
56
  link = html.css("li.next-page > a").first
57
57
 
58
- assert_not_nil link
59
- assert_equal "/some/path/2", link["href"]
60
- assert_equal "Next page", link.text
58
+ link.should_not be_nil
59
+ link["href"].should == "/some/path/2"
60
+ link.text.should == "Next page"
61
61
  end
62
62
 
63
- def test_display_previous_page_link
64
- $DEBUG = 1
63
+ it "should display previous page link" do
65
64
  @params[:page] = 2
66
65
  @request.fullpath = "/some/path?page=2"
67
66
  html = render(:default, Array.new(11))
68
67
  link = html.css("li.previous-page > a").first
69
- $DEBUG = 0
70
- assert_not_nil link
71
- assert_equal "/some/path?page=1", link["href"]
72
- assert_equal "Previous page", link.text
68
+
69
+ link.should_not be_nil
70
+ link["href"].should == "/some/path?page=1"
71
+ link.text.should == "Previous page"
73
72
  end
74
73
 
75
- def test_display_next_page_as_disabled
74
+ it "should disable element when have no next page" do
76
75
  @request.fullpath = "/some/path?page=1"
77
76
  html = render(:default, Array.new(10))
78
77
  link = html.css("li.next-page > a").first
79
78
  span = html.css("li.next-page.disabled > span").first
80
79
 
81
- assert_nil link
82
- assert_not_nil span
83
- assert_equal "Next page", span.text
80
+ link.should be_nil
81
+ span.should_not be_nil
82
+ span.text.should == "Next page"
84
83
  end
85
84
 
86
- def test_display_previous_page_as_disabled
85
+ it "should disable element when have no previous page" do
87
86
  @request.fullpath = "/some/path?page=1"
88
87
  html = render(:default, Array.new(10))
89
88
  link = html.css("li.previous-page > a").first
90
89
  span = html.css("li.previous-page.disabled > span").first
91
90
 
92
- assert_nil link
93
- assert_not_nil span
94
- assert_equal "Previous page", span.text
91
+ link.should be_nil
92
+ span.should_not be_nil
93
+ span.text.should == "Previous page"
95
94
  end
96
95
 
97
- def test_display_current_page
96
+ it "should display current page" do
98
97
  @params[:page] = 10
99
98
  @request.fullpath = "/some/path?page=10"
100
99
  html = render(:default, [])
101
100
  span = html.css("li.page > span").first
102
101
 
103
- assert_not_nil span
104
- assert_equal "Page 10", span.text
102
+ span.should_not be_nil
103
+ span.text.should == "Page 10"
105
104
  end
106
105
 
107
- def test_translate_strings
108
- I18n.locale = :pt
106
+ it "should translate strings" do
107
+ I18n.locale = :"pt-BR"
109
108
 
110
109
  @params[:page] = 10
111
110
  @request.fullpath = "/some/path?page=10"
112
111
  html = render(:default, Array.new(11))
113
112
 
114
- assert_equal "Página 10", html.css("li.page > span").text
115
- assert_equal "Próxima página", html.css("li.next-page > a").text
116
- assert_equal "Página anterior", html.css("li.previous-page > a").text
113
+ html.css("li.page > span").text.should == "Página 10"
114
+ html.css("li.next-page > a").text.should == "Próxima página"
115
+ html.css("li.previous-page > a").text.should == "Página anterior"
117
116
  end
118
117
 
119
- def test_iterate
118
+ it "should skip the last item while iterating" do
120
119
  values = []
121
120
  items = Array.new(11) {|i| "User#{i}" }
122
121
 
@@ -124,10 +123,10 @@ class ActionViewTest < Test::Unit::TestCase
124
123
  values << item
125
124
  end
126
125
 
127
- assert_equal items[0, 10], values
126
+ values.should == items[0, 10]
128
127
  end
129
128
 
130
- def test_iterate_with_fewer_records
129
+ it "should iterate all items when have less records than size" do
131
130
  values = []
132
131
  items = Array.new(8) {|i| "User#{i}" }
133
132
 
@@ -135,10 +134,10 @@ class ActionViewTest < Test::Unit::TestCase
135
134
  values << item
136
135
  end
137
136
 
138
- assert_equal items[0, 8], values
137
+ values.should == items[0, 8]
139
138
  end
140
139
 
141
- def test_iterate_with_index
140
+ it "should yield iteration counter" do
142
141
  values = []
143
142
  indices = []
144
143
  items = Array.new(11) {|i| "User#{i}" }
@@ -148,8 +147,8 @@ class ActionViewTest < Test::Unit::TestCase
148
147
  indices << i
149
148
  end
150
149
 
151
- assert_equal items[0, 10], values
152
- assert_equal (0...10).to_a, indices
150
+ values.should == items[0, 10]
151
+ indices.should == (0...10).to_a
153
152
  end
154
153
 
155
154
  private
@@ -158,6 +157,6 @@ class ActionViewTest < Test::Unit::TestCase
158
157
  end
159
158
 
160
159
  def load_view(name)
161
- File.read(File.dirname(__FILE__) + "/../resources/views/#{name}.erb")
160
+ File.read(File.dirname(__FILE__) + "/../support/views/#{name}.erb")
162
161
  end
163
162
  end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe Thing do
4
+ let!(:things) { Array.new(15) {|i| Thing.create!(:name => "Thing #{i}") } }
5
+ before { Paginate::Config.size = 10 }
6
+
7
+ specify { Thing.should respond_to(:paginate) }
8
+
9
+ it "should use default options" do
10
+ Thing.paginate.all.should == Thing.all(:limit => 11)
11
+ Thing.paginate(:page => 2).all.should == Thing.all(:limit => 11, :offset => 10)
12
+ end
13
+
14
+ it "should use custom options" do
15
+ Thing.paginate(:size => 5).should == Thing.all(:limit => 6)
16
+ Thing.paginate(:size => 5, :page => 2).should == Thing.all(:limit => 6, :offset => 5)
17
+ end
18
+ end
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe Paginate::Base do
4
+ it "should return page from integer" do
5
+ Paginate::Base.new(12).page.should == 12
6
+ end
7
+
8
+ it "should return page from string" do
9
+ Paginate::Base.new("12").page.should == 12
10
+ end
11
+
12
+ it "should default to page 1" do
13
+ Paginate::Base.new.page == 1
14
+ end
15
+
16
+ it "should return page from options" do
17
+ Paginate::Base.new(:page => 12).page == 12
18
+ end
19
+
20
+ it "should return limit from configuration" do
21
+ Paginate::Config.size = 25
22
+ Paginate::Base.new.limit.should == 26
23
+ end
24
+
25
+ it "should return limit from options" do
26
+ Paginate::Config.size = 25
27
+ Paginate::Base.new(:size => 13).limit.should == 14
28
+ end
29
+
30
+ it "should return default limit" do
31
+ Paginate::Config.size = nil
32
+ Paginate::Base.new.limit.should == 11
33
+ end
34
+
35
+ it "should return offset from configuration" do
36
+ Paginate::Config.size = 15
37
+ Paginate::Base.new(:page => 2).offset.should == 15
38
+ end
39
+
40
+ it "should return offset from options" do
41
+ Paginate::Base.new(:page => 2, :size => 5).offset.should == 5
42
+ end
43
+
44
+ it "should return finder options" do
45
+ actual = Paginate::Base.new(:page => 3, :size => 5).to_options
46
+ expected = {:limit => 6, :offset => 10}
47
+
48
+ actual.should == expected
49
+ end
50
+
51
+ specify {
52
+ Paginate::Base.new(:page => 1, :size => 5, :collection => Array.new(6)).should have_next_page
53
+ }
54
+
55
+ specify {
56
+ Paginate::Base.new(:page => 1, :size => 5, :collection => Array.new(5)).should_not have_next_page
57
+ }
58
+
59
+ specify {
60
+ Paginate::Base.new(:page => 2).should have_previous_page
61
+ }
62
+
63
+ specify {
64
+ Paginate::Base.new(:page => 1).should_not have_previous_page
65
+ }
66
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Paginate::Config do
4
+ it "should yield configuration class" do
5
+ Paginate.setup do |config|
6
+ config.param_name = :p
7
+ config.size = 50
8
+ end
9
+
10
+ Paginate::Config.param_name.should == :p
11
+ Paginate::Config.size.should == 50
12
+ end
13
+
14
+ it "should return configuration as hash" do
15
+ Paginate.setup do |config|
16
+ config.param_name = :p
17
+ config.size = 25
18
+ end
19
+
20
+ options = {:param_name => :p, :size => 25}
21
+ Paginate::Config.to_hash.should == options
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Paginate::Renderer do
4
+ before do
5
+ Paginate.setup do |config|
6
+ config.param_name = :page
7
+ config.size = 10
8
+ end
9
+
10
+ I18n.locale = :en
11
+
12
+ @renderer = Paginate::Renderer.new({
13
+ :collection => Array.new(11),
14
+ :page => 1,
15
+ :fullpath => "/some/path"
16
+ })
17
+ end
18
+
19
+ specify { @renderer.render.should be_html_safe }
20
+
21
+ it "should parse simple url" do
22
+ @renderer.options[:url] = "/some/path"
23
+ @renderer.url_for(1).should == "/some/path?page=1"
24
+ end
25
+
26
+ it "should parse url with page param" do
27
+ @renderer.options[:url] = "/some/path?page=3"
28
+ @renderer.url_for(1).should == "/some/path?page=1"
29
+ end
30
+
31
+ it "should parse url with page as first param" do
32
+ @renderer.options[:url] = "/some/path?page=3&a=1&b=2&c=3"
33
+ @renderer.url_for(1).should == "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1"
34
+ end
35
+
36
+ it "should parse url with page as last param" do
37
+ @renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=3"
38
+ @renderer.url_for(1).should == "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1"
39
+ end
40
+
41
+ it "should parse url with page param in the middle" do
42
+ @renderer.options[:url] = "/some/path?a=1&b=2&page=3&c=3"
43
+ @renderer.url_for(1).should == "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1"
44
+ end
45
+
46
+ it "should parse url with page as arbitrary string" do
47
+ @renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=abc"
48
+ @renderer.url_for(1).should == "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1"
49
+ end
50
+
51
+ it "should escape url from blocks" do
52
+ @renderer.options[:url] = proc {|page| "/some/path/#{page}?a=1&b=2"}
53
+ @renderer.url_for(1).should == "/some/path/1?a=1&amp;b=2"
54
+ end
55
+ end
File without changes
@@ -1,21 +1,23 @@
1
- gem "test-unit"
1
+ require "bundler"
2
+ Bundler.setup
3
+ Bundler.require(:default, :development)
2
4
 
3
- require "test/unit"
4
- require "mocha"
5
+ require "rspec"
5
6
  require "nokogiri"
6
7
  require "ostruct"
8
+ require "sqlite3"
9
+ require "test_notifier/runner/rspec"
10
+
7
11
  require "active_support/all"
8
- require "active_record"
9
12
  require "action_view"
10
13
  require "action_controller"
11
- require "sqlite3"
12
14
 
13
15
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
14
-
15
16
  Rails = OpenStruct.new(:version => ActiveRecord::VERSION::STRING)
16
17
 
17
18
  require "paginate"
18
19
 
19
- load "resources/schema.rb"
20
- require "resources/model"
21
- require "resources/controller"
20
+ load "spec/schema.rb"
21
+
22
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file}
23
+ I18n.load_path << File.dirname(__FILE__) + "/support/translations.yml"
@@ -1,3 +1,2 @@
1
1
  class ThingsController < ActionController::Base
2
-
3
- end
2
+ end
@@ -0,0 +1,11 @@
1
+ RSpec::Matchers.define :have_next_page do
2
+ match do |base|
3
+ base.next_page?
4
+ end
5
+ end
6
+
7
+ RSpec::Matchers.define :have_previous_page do
8
+ match do |base|
9
+ base.previous_page?
10
+ end
11
+ end
File without changes
@@ -1,8 +1,11 @@
1
- pt: &pt
1
+ en:
2
+ paginate:
3
+ next: "Next page"
4
+ previous: "Previous page"
5
+ page: "Page %{page}"
6
+
7
+ pt-BR:
2
8
  paginate:
3
9
  next: "Próxima página"
4
10
  previous: "Página anterior"
5
11
  page: "Página %{page}"
6
-
7
- pt-BR:
8
- <<: *pt
@@ -0,0 +1,2 @@
1
+ <%= paginate items, proc {|page| "/some/path/#{page}"} %>
2
+
@@ -0,0 +1 @@
1
+ <%= paginate items %>
metadata CHANGED
@@ -3,10 +3,10 @@ name: paginate
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 0
7
6
  - 1
8
- - 3
9
- version: 0.1.3
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nando Vieira
@@ -14,48 +14,165 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-23 00:00:00 -03:00
17
+ date: 2011-01-13 00:00:00 -02:00
18
18
  default_executable:
19
- dependencies: []
20
-
21
- description:
22
- email: fnando.vieira@gmail.com
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: test_notifier
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3-ruby
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: activesupport
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 3
69
+ - 0
70
+ - 0
71
+ version: 3.0.0
72
+ type: :development
73
+ version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: activerecord
76
+ prerelease: false
77
+ requirement: &id005 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 3
84
+ - 0
85
+ - 0
86
+ version: 3.0.0
87
+ type: :development
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ name: actionpack
91
+ prerelease: false
92
+ requirement: &id006 !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 3
99
+ - 0
100
+ - 0
101
+ version: 3.0.0
102
+ type: :development
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: rspec
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 2
114
+ - 4
115
+ - 0
116
+ version: 2.4.0
117
+ type: :development
118
+ version_requirements: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ name: ruby-debug19
121
+ prerelease: false
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ type: :development
131
+ version_requirements: *id008
132
+ description: Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support.
133
+ email:
134
+ - fnando.vieira@gmail.com
23
135
  executables: []
24
136
 
25
137
  extensions: []
26
138
 
27
- extra_rdoc_files:
28
- - README.rdoc
139
+ extra_rdoc_files: []
140
+
29
141
  files:
142
+ - .gitignore
143
+ - Gemfile
144
+ - Gemfile.lock
30
145
  - README.rdoc
31
146
  - Rakefile
32
147
  - lib/paginate.rb
33
148
  - lib/paginate/action_controller.rb
34
149
  - lib/paginate/active_record.rb
35
- - lib/paginate/active_record/ext.rb
36
150
  - lib/paginate/base.rb
37
151
  - lib/paginate/config.rb
38
152
  - lib/paginate/helper.rb
39
- - lib/paginate/locales/en.yml
40
- - lib/paginate/locales/pt.yml
41
153
  - lib/paginate/renderer.rb
42
154
  - lib/paginate/version.rb
43
- - test/paginate/action_view_test.rb
44
- - test/paginate/active_record_test.rb
45
- - test/paginate/base_test.rb
46
- - test/paginate/config_test.rb
47
- - test/paginate/renderer_test.rb
48
- - test/resources/controller.rb
49
- - test/resources/model.rb
50
- - test/resources/schema.rb
51
- - test/test_helper.rb
155
+ - paginate.gemspec
156
+ - spec/paginate/action_view_spec.rb
157
+ - spec/paginate/activerecord_spec.rb
158
+ - spec/paginate/base_spec.rb
159
+ - spec/paginate/config_spec.rb
160
+ - spec/paginate/renderer_spec.rb
161
+ - spec/schema.rb
162
+ - spec/spec_helper.rb
163
+ - spec/support/controller.rb
164
+ - spec/support/matchers.rb
165
+ - spec/support/model.rb
166
+ - spec/support/translations.yml
167
+ - spec/support/views/block_as_url.erb
168
+ - spec/support/views/default.erb
52
169
  has_rdoc: true
53
- homepage: http://github.com/fnando/paginate
170
+ homepage: http://rubygems.org/gems/kitabu
54
171
  licenses: []
55
172
 
56
173
  post_install_message:
57
- rdoc_options:
58
- - --charset=UTF-8
174
+ rdoc_options: []
175
+
59
176
  require_paths:
60
177
  - lib
61
178
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -82,12 +199,16 @@ signing_key:
82
199
  specification_version: 3
83
200
  summary: Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support.
84
201
  test_files:
85
- - test/paginate/action_view_test.rb
86
- - test/paginate/active_record_test.rb
87
- - test/paginate/base_test.rb
88
- - test/paginate/config_test.rb
89
- - test/paginate/renderer_test.rb
90
- - test/resources/controller.rb
91
- - test/resources/model.rb
92
- - test/resources/schema.rb
93
- - test/test_helper.rb
202
+ - spec/paginate/action_view_spec.rb
203
+ - spec/paginate/activerecord_spec.rb
204
+ - spec/paginate/base_spec.rb
205
+ - spec/paginate/config_spec.rb
206
+ - spec/paginate/renderer_spec.rb
207
+ - spec/schema.rb
208
+ - spec/spec_helper.rb
209
+ - spec/support/controller.rb
210
+ - spec/support/matchers.rb
211
+ - spec/support/model.rb
212
+ - spec/support/translations.yml
213
+ - spec/support/views/block_as_url.erb
214
+ - spec/support/views/default.erb
@@ -1,17 +0,0 @@
1
- class ActiveRecord::Base
2
- class << self
3
- alias_method :original_inherited, :inherited
4
- end
5
-
6
- def self.inherited(child)
7
- original_inherited(child)
8
-
9
- child.class_eval do
10
- if Rails.version >= "3.0"
11
- scope :paginate, proc {|*args| Paginate::Base.new(*args).to_options }
12
- else
13
- named_scope :paginate, proc {|*args| Paginate::Base.new(*args).to_options }
14
- end
15
- end
16
- end
17
- end
@@ -1,5 +0,0 @@
1
- en:
2
- paginate:
3
- next: "Next page"
4
- previous: "Previous page"
5
- page: "Page %{page}"
@@ -1,28 +0,0 @@
1
- require "test_helper"
2
-
3
- class ActiveRecordTest < Test::Unit::TestCase
4
- def setup
5
- 15.times {|i| Thing.create(:name => "Thing #{i}") }
6
- Paginate::Config.size = 10
7
- end
8
-
9
- def test_respond_to_paginate_method
10
- assert_respond_to Thing, :paginate
11
- end
12
-
13
- def test_paginate_with_defaults
14
- things = Thing.all(:limit => 11)
15
- assert_equal things, Thing.paginate.all
16
-
17
- things = Thing.all(:limit => 11, :offset => 11)
18
- assert_equal things, Thing.paginate(:page => 2).all
19
- end
20
-
21
- def test_paginate_with_options
22
- things = Thing.all(:limit => 6)
23
- assert_equal things, Thing.paginate(:size => 5)
24
-
25
- things = Thing.all(:limit => 6, :offset => 6)
26
- assert_equal things, Thing.paginate(:size => 5, :page => 2)
27
- end
28
- end
@@ -1,84 +0,0 @@
1
- require "test_helper"
2
-
3
- class BaseTest < Test::Unit::TestCase
4
- def test_page_from_integer
5
- @base = Paginate::Base.new(12)
6
- assert_equal 12, @base.page
7
- end
8
-
9
- def test_page_from_string
10
- @base = Paginate::Base.new("12")
11
- assert_equal 12, @base.page
12
- end
13
-
14
- def test_default_page_value
15
- @base = Paginate::Base.new
16
- assert_equal 1, @base.page
17
- end
18
-
19
- def test_page
20
- @base = Paginate::Base.new(:page => 0)
21
- assert_equal 1, @base.page
22
- end
23
-
24
- def test_limit_from_config
25
- Paginate::Config.size = 25
26
- @base = Paginate::Base.new
27
-
28
- assert_equal 26, @base.limit
29
- end
30
-
31
- def test_limit_from_options
32
- Paginate::Config.size = 25
33
- @base = Paginate::Base.new(:size => 13)
34
-
35
- assert_equal 14, @base.limit
36
- end
37
-
38
- def test_default_limit
39
- Paginate::Config.size = nil
40
- @base = Paginate::Base.new
41
-
42
- assert_equal 11, @base.limit
43
- end
44
-
45
- def test_offset_from_config
46
- Paginate::Config.size = 15
47
- @base = Paginate::Base.new(:page => 2)
48
-
49
- assert_equal 16, @base.offset
50
- end
51
-
52
- def test_offset_from_options
53
- @base = Paginate::Base.new(:page => 2, :size => 5)
54
-
55
- assert_equal 6, @base.offset
56
- end
57
-
58
- def test_return_finder_options
59
- @base = Paginate::Base.new(:page => 3, :size => 5)
60
-
61
- options = {:limit => 6, :offset => 12}
62
- assert_equal options, @base.to_options
63
- end
64
-
65
- def test_next_page
66
- @base = Paginate::Base.new(:page => 1, :size => 5, :collection => Array.new(6))
67
- assert @base.next_page?
68
- end
69
-
70
- def test_no_next_page
71
- @base = Paginate::Base.new(:page => 1, :size => 5, :collection => Array.new(5))
72
- assert !@base.next_page?
73
- end
74
-
75
- def test_previous_page
76
- @base = Paginate::Base.new(:page => 2)
77
- assert @base.previous_page?
78
- end
79
-
80
- def test_no_previous_page
81
- @base = Paginate::Base.new(:page => 1)
82
- assert !@base.previous_page?
83
- end
84
- end
@@ -1,23 +0,0 @@
1
- require "test_helper"
2
-
3
- class ConfigTest < Test::Unit::TestCase
4
- def test_yield_configuration_class
5
- Paginate.setup do |config|
6
- config.param_name = :p
7
- config.size = 50
8
- end
9
-
10
- assert_equal :p, Paginate::Config.param_name
11
- assert_equal 50, Paginate::Config.size
12
- end
13
-
14
- def test_return_config_as_hash
15
- Paginate.setup do |config|
16
- config.param_name = :p
17
- config.size = 25
18
- end
19
-
20
- options = {:param_name => :p, :size => 25}
21
- assert_equal options, Paginate::Config.to_hash
22
- end
23
- end
@@ -1,71 +0,0 @@
1
- require "test_helper"
2
-
3
- class RendererTest < Test::Unit::TestCase
4
- def setup
5
- Paginate.setup do |config|
6
- config.param_name = :page
7
- config.size = 10
8
- end
9
-
10
- I18n.locale = :en
11
-
12
- @renderer = Paginate::Renderer.new({
13
- :collection => Array.new(11),
14
- :page => 1,
15
- :fullpath => "/some/path"
16
- })
17
- end
18
-
19
- def test_safe_html
20
- string = String.new
21
- string.expects(:respond_to?).with(:html_safe).returns(true)
22
- string.expects(:html_safe)
23
- String.expects(:new).returns(string)
24
-
25
- @renderer.render
26
- end
27
-
28
- def test_no_safe_html
29
- string = String.new
30
- string.expects(:respond_to?).with(:html_safe).returns(false)
31
- string.expects(:html_safe).never
32
- String.expects(:new).returns(string)
33
-
34
- @renderer.render
35
- end
36
-
37
- def test_simple_url
38
- @renderer.options[:url] = "/some/path"
39
- assert_equal "/some/path?page=1", @renderer.url_for(1)
40
- end
41
-
42
- def test_simple_url_with_page_param
43
- @renderer.options[:url] = "/some/path?page=3"
44
- assert_equal "/some/path?page=1", @renderer.url_for(1)
45
- end
46
-
47
- def test_simple_url_with_page_as_first_param
48
- @renderer.options[:url] = "/some/path?page=3&a=1&b=2&c=3"
49
- assert_equal "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1", @renderer.url_for(1)
50
- end
51
-
52
- def test_simple_url_with_page_as_last_param
53
- @renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=3"
54
- assert_equal "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1", @renderer.url_for(1)
55
- end
56
-
57
- def test_simple_url_with_page_param_in_the_middle
58
- @renderer.options[:url] = "/some/path?a=1&b=2&page=3&c=3"
59
- assert_equal "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1", @renderer.url_for(1)
60
- end
61
-
62
- def test_simple_url_with_page_as_text
63
- @renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=abc"
64
- assert_equal "/some/path?a=1&amp;b=2&amp;c=3&amp;page=1", @renderer.url_for(1)
65
- end
66
-
67
- def test_escape_url_from_blocks
68
- @renderer.options[:url] = proc {|page| "/some/path/#{page}?a=1&b=2"}
69
- assert_equal "/some/path/1?a=1&amp;b=2", @renderer.url_for(1)
70
- end
71
- end