will_paginate 3.0.4 → 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 (50) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +7 -10
  3. data/lib/will_paginate/active_record.rb +18 -17
  4. data/lib/will_paginate/deprecation.rb +3 -3
  5. data/lib/will_paginate/i18n.rb +3 -3
  6. data/lib/will_paginate/locale/en.yml +4 -0
  7. data/lib/will_paginate/mongoid.rb +48 -0
  8. data/lib/will_paginate/page_number.rb +7 -11
  9. data/lib/will_paginate/railtie.rb +19 -13
  10. data/lib/will_paginate/version.rb +2 -2
  11. data/lib/will_paginate/view_helpers/action_view.rb +12 -5
  12. data/lib/will_paginate/view_helpers/hanami.rb +41 -0
  13. data/lib/will_paginate/view_helpers/link_renderer.rb +23 -17
  14. data/lib/will_paginate/view_helpers/link_renderer_base.rb +1 -1
  15. data/lib/will_paginate/view_helpers.rb +3 -1
  16. data/lib/will_paginate.rb +0 -12
  17. metadata +29 -58
  18. data/Rakefile +0 -25
  19. data/lib/will_paginate/data_mapper.rb +0 -95
  20. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  21. data/spec/ci.rb +0 -29
  22. data/spec/collection_spec.rb +0 -139
  23. data/spec/console +0 -12
  24. data/spec/console_fixtures.rb +0 -28
  25. data/spec/database.yml +0 -22
  26. data/spec/finders/active_record_spec.rb +0 -556
  27. data/spec/finders/activerecord_test_connector.rb +0 -115
  28. data/spec/finders/data_mapper_spec.rb +0 -103
  29. data/spec/finders/data_mapper_test_connector.rb +0 -54
  30. data/spec/finders/sequel_spec.rb +0 -67
  31. data/spec/finders/sequel_test_connector.rb +0 -15
  32. data/spec/fixtures/admin.rb +0 -3
  33. data/spec/fixtures/developer.rb +0 -13
  34. data/spec/fixtures/developers_projects.yml +0 -13
  35. data/spec/fixtures/project.rb +0 -15
  36. data/spec/fixtures/projects.yml +0 -6
  37. data/spec/fixtures/replies.yml +0 -29
  38. data/spec/fixtures/reply.rb +0 -9
  39. data/spec/fixtures/schema.rb +0 -38
  40. data/spec/fixtures/topic.rb +0 -7
  41. data/spec/fixtures/topics.yml +0 -30
  42. data/spec/fixtures/user.rb +0 -2
  43. data/spec/fixtures/users.yml +0 -35
  44. data/spec/page_number_spec.rb +0 -65
  45. data/spec/per_page_spec.rb +0 -41
  46. data/spec/spec_helper.rb +0 -71
  47. data/spec/view_helpers/action_view_spec.rb +0 -423
  48. data/spec/view_helpers/base_spec.rb +0 -130
  49. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  50. data/spec/view_helpers/view_example_group.rb +0 -121
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- begin
4
- require 'will_paginate/data_mapper'
5
- require File.expand_path('../data_mapper_test_connector', __FILE__)
6
- rescue LoadError => error
7
- warn "Error running DataMapper specs: #{error.message}"
8
- datamapper_loaded = false
9
- else
10
- datamapper_loaded = true
11
- end
12
-
13
- describe WillPaginate::DataMapper do
14
-
15
- it "has per_page" do
16
- Animal.per_page.should == 30
17
- begin
18
- Animal.per_page = 10
19
- Animal.per_page.should == 10
20
-
21
- subclass = Class.new(Animal)
22
- subclass.per_page.should == 10
23
- ensure
24
- Animal.per_page = 30
25
- end
26
- end
27
-
28
- it "doesn't make normal collections appear paginated" do
29
- Animal.all.should_not be_paginated
30
- end
31
-
32
- it "paginates to first page by default" do
33
- animals = Animal.paginate(:page => nil)
34
-
35
- animals.should be_paginated
36
- animals.current_page.should == 1
37
- animals.per_page.should == 30
38
- animals.offset.should == 0
39
- animals.total_entries.should == 3
40
- animals.total_pages.should == 1
41
- end
42
-
43
- it "paginates to first page, explicit limit" do
44
- animals = Animal.paginate(:page => 1, :per_page => 2)
45
-
46
- animals.current_page.should == 1
47
- animals.per_page.should == 2
48
- animals.total_entries.should == 3
49
- animals.total_pages.should == 2
50
- animals.map {|a| a.name }.should == %w[ Dog Cat ]
51
- end
52
-
53
- it "paginates to second page" do
54
- animals = Animal.paginate(:page => 2, :per_page => 2)
55
-
56
- animals.current_page.should == 2
57
- animals.offset.should == 2
58
- animals.map {|a| a.name }.should == %w[ Lion ]
59
- end
60
-
61
- it "paginates a collection" do
62
- friends = Animal.all(:notes.like => '%friend%')
63
- friends.paginate(:page => 1).per_page.should == 30
64
- friends.paginate(:page => 1, :per_page => 1).total_entries.should == 2
65
- end
66
-
67
- it "paginates a limited collection" do
68
- animals = Animal.all(:limit => 2).paginate(:page => 1)
69
- animals.per_page.should == 2
70
- end
71
-
72
- it "has page() method" do
73
- Animal.page(2).per_page.should == 30
74
- Animal.page(2).offset.should == 30
75
- Animal.page(2).current_page.should == 2
76
- Animal.all(:limit => 2).page(2).per_page.should == 2
77
- end
78
-
79
- it "has total_pages at 1 for empty collections" do
80
- Animal.all(:conditions => ['1=2']).page(1).total_pages.should == 1
81
- end
82
-
83
- it "can iterate and then call WP methods" do
84
- animals = Animal.all(:limit => 2).page(1)
85
- animals.each { |a| }
86
- animals.total_entries.should == 3
87
- end
88
-
89
- it "augments to_a to return a WP::Collection" do
90
- animals = Animal.all(:limit => 2).page(1)
91
- array = animals.to_a
92
- array.size.should == 2
93
- array.is_a? WillPaginate::Collection
94
- array.current_page.should == 1
95
- array.per_page.should == 2
96
- end
97
-
98
- it "doesn't have a problem assigning has-one-through relationship" do
99
- human = Human.create :name => "Mislav"
100
- human.pet = Animal.first
101
- end
102
-
103
- end if datamapper_loaded
@@ -1,54 +0,0 @@
1
- require 'sqlite3'
2
- require 'dm-core'
3
- require 'dm-core/support/logger'
4
- require 'dm-migrations'
5
-
6
- DataMapper.setup :default, 'sqlite3::memory:'
7
-
8
- # Define models
9
- class Animal
10
- include DataMapper::Resource
11
- property :id, Serial
12
- property :name, String
13
- property :notes, Text
14
-
15
- def self.setup
16
- Animal.create(:name => 'Dog', :notes => "Man's best friend")
17
- Animal.create(:name => 'Cat', :notes => "Woman's best friend")
18
- Animal.create(:name => 'Lion', :notes => 'King of the Jungle')
19
- end
20
- end
21
-
22
- class Ownership
23
- include DataMapper::Resource
24
-
25
- belongs_to :animal, :key => true
26
- belongs_to :human, :key => true
27
-
28
- def self.setup
29
- end
30
- end
31
-
32
- class Human
33
- include DataMapper::Resource
34
-
35
- property :id, Serial
36
- property :name, String
37
-
38
- has n, :ownerships
39
- has 1, :pet, :model => 'Animal', :through => :ownerships, :via => :animal
40
-
41
- def self.setup
42
- end
43
- end
44
-
45
- # Load fixtures
46
- [Animal, Ownership, Human].each do |klass|
47
- klass.auto_migrate!
48
- klass.setup
49
- end
50
-
51
- if 'irb' == $0
52
- DataMapper.logger.set_log($stdout, :debug)
53
- DataMapper.logger.auto_flush = true
54
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- begin
4
- require 'will_paginate/sequel'
5
- require File.expand_path('../sequel_test_connector', __FILE__)
6
- rescue LoadError, ArgumentError => error
7
- warn "Error running Sequel specs: #{error.message}"
8
- sequel_loaded = false
9
- else
10
- sequel_loaded = true
11
- end
12
-
13
- describe Sequel::Dataset::Pagination, 'extension' do
14
-
15
- class Car < Sequel::Model
16
- end
17
-
18
- it "should have the #paginate method" do
19
- Car.should respond_to(:paginate)
20
- end
21
-
22
- it "should NOT have the #paginate_by_sql method" do
23
- Car.should_not respond_to(:paginate_by_sql)
24
- end
25
-
26
- describe 'pagination' do
27
- before(:all) do
28
- Car.create(:name => 'Shelby', :notes => "Man's best friend")
29
- Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
30
- Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
31
- end
32
-
33
- it "should imitate WillPaginate::Collection" do
34
- result = Car.paginate(1, 2)
35
-
36
- result.should_not be_empty
37
- result.size.should == 2
38
- result.length.should == 2
39
- result.total_entries.should == 3
40
- result.total_pages.should == 2
41
- result.per_page.should == 2
42
- result.current_page.should == 1
43
- end
44
-
45
- it "should perform" do
46
- Car.paginate(1, 2).all.should == [Car[1], Car[2]]
47
- end
48
-
49
- it "should be empty" do
50
- result = Car.paginate(3, 2)
51
- result.should be_empty
52
- end
53
-
54
- it "should perform with #select and #order" do
55
- result = Car.select("name as foo".lit).order(:name).paginate(1, 2).all
56
- result.size.should == 2
57
- result.first.values[:foo].should == "Aston Martin"
58
- end
59
-
60
- it "should perform with #filter" do
61
- results = Car.filter(:name => 'Shelby').paginate(1, 2).all
62
- results.size.should == 1
63
- results.first.should == Car.find(:name => 'Shelby')
64
- end
65
- end
66
-
67
- end if sequel_loaded
@@ -1,15 +0,0 @@
1
- require 'sequel'
2
-
3
- Symbol.class_eval do
4
- # Active Record calculations tries `as` on some objects but chokes when that
5
- # object was a Symbol and it gets a Sequel::SQL::AliasedExpression.
6
- undef as if method_defined? :as
7
- end
8
-
9
- db = Sequel.sqlite
10
-
11
- db.create_table :cars do
12
- primary_key :id, :integer, :auto_increment => true
13
- column :name, :text
14
- column :notes, :text
15
- end
@@ -1,3 +0,0 @@
1
- class Admin < User
2
- has_many :companies, :finder_sql => 'SELECT * FROM companies'
3
- end
@@ -1,13 +0,0 @@
1
- class Developer < User
2
- has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name', :join_table => 'developers_projects'
3
-
4
- def self.with_poor_ones(&block)
5
- with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'salary' } do
6
- yield
7
- end
8
- end
9
-
10
- scope :poor, :conditions => ['salary <= ?', 80000], :order => 'salary'
11
-
12
- def self.per_page() 10 end
13
- end
@@ -1,13 +0,0 @@
1
- david_action_controller:
2
- developer_id: 1
3
- project_id: 2
4
- joined_on: 2004-10-10
5
-
6
- david_active_record:
7
- developer_id: 1
8
- project_id: 1
9
- joined_on: 2004-10-10
10
-
11
- jamis_active_record:
12
- developer_id: 2
13
- project_id: 1
@@ -1,15 +0,0 @@
1
- class Project < ActiveRecord::Base
2
- has_and_belongs_to_many :developers, :uniq => true, :join_table => 'developers_projects'
3
-
4
- has_many :topics
5
- # :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})',
6
- # :counter_sql => 'SELECT COUNT(*) FROM topics WHERE (topics.project_id = #{id})'
7
-
8
- has_many :replies, :through => :topics do
9
- def only_recent(params = {})
10
- scoped.where(['replies.created_at > ?', 15.minutes.ago])
11
- end
12
- end
13
-
14
- has_many :unique_replies, :through => :topics, :source => :replies, :uniq => true
15
- end
@@ -1,6 +0,0 @@
1
- active_record:
2
- id: 1
3
- name: Active Record
4
- action_controller:
5
- id: 2
6
- name: Action Controller
@@ -1,29 +0,0 @@
1
- witty_retort:
2
- id: 1
3
- topic_id: 1
4
- content: Birdman is better!
5
- created_at: <%= 6.hours.ago.utc.to_s(:db) %>
6
-
7
- another:
8
- id: 2
9
- topic_id: 2
10
- content: Nuh uh!
11
- created_at: <%= 1.hour.ago.utc.to_s(:db) %>
12
-
13
- spam:
14
- id: 3
15
- topic_id: 1
16
- content: Nice site!
17
- created_at: <%= 1.hour.ago.utc.to_s(:db) %>
18
-
19
- decisive:
20
- id: 4
21
- topic_id: 4
22
- content: "I'm getting to the bottom of this"
23
- created_at: <%= 30.minutes.ago.utc.to_s(:db) %>
24
-
25
- brave:
26
- id: 5
27
- topic_id: 4
28
- content: "AR doesn't scare me a bit"
29
- created_at: <%= 10.minutes.ago.utc.to_s(:db) %>
@@ -1,9 +0,0 @@
1
- class Reply < ActiveRecord::Base
2
- belongs_to :topic, :include => [:replies]
3
-
4
- scope :recent,
5
- :conditions => ['replies.created_at > ?', 15.minutes.ago],
6
- :order => 'replies.created_at DESC'
7
-
8
- validates_presence_of :content
9
- end
@@ -1,38 +0,0 @@
1
- ActiveRecord::Schema.define do
2
-
3
- create_table "users", :force => true do |t|
4
- t.column "name", :text
5
- t.column "salary", :integer, :default => 70000
6
- t.column "created_at", :datetime
7
- t.column "updated_at", :datetime
8
- t.column "type", :text
9
- end
10
-
11
- create_table "projects", :force => true do |t|
12
- t.column "name", :text
13
- end
14
-
15
- create_table "developers_projects", :id => false, :force => true do |t|
16
- t.column "developer_id", :integer, :null => false
17
- t.column "project_id", :integer, :null => false
18
- t.column "joined_on", :date
19
- t.column "access_level", :integer, :default => 1
20
- end
21
-
22
- create_table "topics", :force => true do |t|
23
- t.column "project_id", :integer
24
- t.column "title", :string
25
- t.column "subtitle", :string
26
- t.column "content", :text
27
- t.column "created_at", :datetime
28
- t.column "updated_at", :datetime
29
- end
30
-
31
- create_table "replies", :force => true do |t|
32
- t.column "content", :text
33
- t.column "created_at", :datetime
34
- t.column "updated_at", :datetime
35
- t.column "topic_id", :integer
36
- end
37
-
38
- end
@@ -1,7 +0,0 @@
1
- class Topic < ActiveRecord::Base
2
- has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC'
3
- belongs_to :project
4
-
5
- scope :mentions_activerecord, :conditions => ['topics.title LIKE ?', '%ActiveRecord%']
6
- scope :distinct, :select => "DISTINCT #{table_name}.*"
7
- end
@@ -1,30 +0,0 @@
1
- futurama:
2
- id: 1
3
- title: Isnt futurama awesome?
4
- subtitle: It really is, isnt it.
5
- content: I like futurama
6
- created_at: <%= 1.day.ago.utc.to_s(:db) %>
7
- updated_at:
8
-
9
- harvey_birdman:
10
- id: 2
11
- title: Harvey Birdman is the king of all men
12
- subtitle: yup
13
- content: He really is
14
- created_at: <%= 2.hours.ago.utc.to_s(:db) %>
15
- updated_at:
16
-
17
- rails:
18
- id: 3
19
- project_id: 1
20
- title: Rails is nice
21
- subtitle: It makes me happy
22
- content: except when I have to hack internals to fix pagination. even then really.
23
- created_at: <%= 20.minutes.ago.utc.to_s(:db) %>
24
-
25
- ar:
26
- id: 4
27
- project_id: 1
28
- title: ActiveRecord sometimes freaks me out
29
- content: "I mean, what's the deal with eager loading?"
30
- created_at: <%= 15.minutes.ago.utc.to_s(:db) %>
@@ -1,2 +0,0 @@
1
- class User < ActiveRecord::Base
2
- end
@@ -1,35 +0,0 @@
1
- david:
2
- id: 1
3
- name: David
4
- salary: 80000
5
- type: Developer
6
-
7
- jamis:
8
- id: 2
9
- name: Jamis
10
- salary: 150000
11
- type: Developer
12
-
13
- <% for digit in 3..10 %>
14
- dev_<%= digit %>:
15
- id: <%= digit %>
16
- name: fixture_<%= digit %>
17
- salary: 100000
18
- type: Developer
19
- <% end %>
20
-
21
- poor_jamis:
22
- id: 11
23
- name: Jamis
24
- salary: 9000
25
- type: Developer
26
-
27
- admin:
28
- id: 12
29
- name: admin
30
- type: Admin
31
-
32
- goofy:
33
- id: 13
34
- name: Goofy
35
- type: Admin
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
- require 'will_paginate/page_number'
3
-
4
- describe WillPaginate::PageNumber do
5
- describe "valid" do
6
- subject { described_class.new('12', 'page') }
7
-
8
- it { should eq(12) }
9
- its(:inspect) { should eq('page 12') }
10
- it { should be_a(WillPaginate::PageNumber) }
11
- it { should be_instance_of(WillPaginate::PageNumber) }
12
- it { should be_a(Numeric) }
13
- it { should be_a(Fixnum) }
14
- it { should_not be_instance_of(Fixnum) }
15
-
16
- it "passes the PageNumber=== type check" do |variable|
17
- (WillPaginate::PageNumber === subject).should be
18
- end
19
-
20
- it "passes the Numeric=== type check" do |variable|
21
- (Numeric === subject).should be
22
- (Fixnum === subject).should be
23
- end
24
- end
25
-
26
- describe "invalid" do
27
- def create(value, name = 'page')
28
- described_class.new(value, name)
29
- end
30
-
31
- it "errors out on non-int values" do
32
- lambda { create(nil) }.should raise_error(WillPaginate::InvalidPage)
33
- lambda { create('') }.should raise_error(WillPaginate::InvalidPage)
34
- lambda { create('Schnitzel') }.should raise_error(WillPaginate::InvalidPage)
35
- end
36
-
37
- it "errors out on zero or less" do
38
- lambda { create(0) }.should raise_error(WillPaginate::InvalidPage)
39
- lambda { create(-1) }.should raise_error(WillPaginate::InvalidPage)
40
- end
41
-
42
- it "doesn't error out on zero for 'offset'" do
43
- lambda { create(0, 'offset') }.should_not raise_error
44
- lambda { create(-1, 'offset') }.should raise_error(WillPaginate::InvalidPage)
45
- end
46
- end
47
-
48
- describe "coercion method" do
49
- it "defaults to 'page' name" do
50
- num = WillPaginate::PageNumber(12)
51
- num.inspect.should eq('page 12')
52
- end
53
-
54
- it "accepts a custom name" do
55
- num = WillPaginate::PageNumber(12, 'monkeys')
56
- num.inspect.should eq('monkeys 12')
57
- end
58
-
59
- it "doesn't affect PageNumber instances" do
60
- num = WillPaginate::PageNumber(12)
61
- num2 = WillPaginate::PageNumber(num)
62
- num2.object_id.should eq(num.object_id)
63
- end
64
- end
65
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- require 'will_paginate/per_page'
3
-
4
- describe WillPaginate::PerPage do
5
-
6
- class MyModel
7
- extend WillPaginate::PerPage
8
- end
9
-
10
- it "has the default value" do
11
- MyModel.per_page.should == 30
12
-
13
- WillPaginate.per_page = 10
14
- begin
15
- MyModel.per_page.should == 10
16
- ensure
17
- WillPaginate.per_page = 30
18
- end
19
- end
20
-
21
- it "casts values to int" do
22
- WillPaginate.per_page = '10'
23
- begin
24
- MyModel.per_page.should == 10
25
- ensure
26
- WillPaginate.per_page = 30
27
- end
28
- end
29
-
30
- it "has an explicit value" do
31
- MyModel.per_page = 12
32
- begin
33
- MyModel.per_page.should == 12
34
- subclass = Class.new(MyModel)
35
- subclass.per_page.should == 12
36
- ensure
37
- MyModel.send(:remove_instance_variable, '@per_page')
38
- end
39
- end
40
-
41
- end
data/spec/spec_helper.rb DELETED
@@ -1,71 +0,0 @@
1
- require 'rspec'
2
- require File.expand_path('../view_helpers/view_example_group', __FILE__)
3
- begin
4
- require 'ruby-debug'
5
- rescue LoadError
6
- # no debugger available
7
- end
8
-
9
- RSpec.configure do |config|
10
- config.include Module.new {
11
- protected
12
-
13
- def include_phrase(string)
14
- PhraseMatcher.new(string)
15
- end
16
-
17
- def have_deprecation(msg)
18
- DeprecationMatcher.new(msg)
19
- end
20
- }
21
-
22
- config.mock_with :mocha
23
- end
24
-
25
- class PhraseMatcher
26
- def initialize(string)
27
- @string = string
28
- @pattern = /\b#{Regexp.escape string}\b/
29
- end
30
-
31
- def matches?(actual)
32
- @actual = actual.to_s
33
- @actual =~ @pattern
34
- end
35
-
36
- def failure_message
37
- "expected #{@actual.inspect} to contain phrase #{@string.inspect}"
38
- end
39
-
40
- def negative_failure_message
41
- "expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
42
- end
43
- end
44
-
45
- require 'stringio'
46
-
47
- class DeprecationMatcher
48
- def initialize(message)
49
- @message = message
50
- end
51
-
52
- def matches?(block)
53
- @actual = hijack_stderr(&block)
54
- PhraseMatcher.new("DEPRECATION WARNING: #{@message}").matches?(@actual)
55
- end
56
-
57
- def failure_message
58
- "expected deprecation warning #{@message.inspect}, got #{@actual.inspect}"
59
- end
60
-
61
- private
62
-
63
- def hijack_stderr
64
- err = $stderr
65
- $stderr = StringIO.new
66
- yield
67
- $stderr.string.rstrip
68
- ensure
69
- $stderr = err
70
- end
71
- end