will_paginate 3.2.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -5
  3. data/lib/will_paginate/active_record.rb +3 -3
  4. data/lib/will_paginate/i18n.rb +3 -3
  5. data/lib/will_paginate/locale/en.yml +2 -0
  6. data/lib/will_paginate/page_number.rb +1 -2
  7. data/lib/will_paginate/railtie.rb +2 -2
  8. data/lib/will_paginate/version.rb +2 -2
  9. data/lib/will_paginate/view_helpers/action_view.rb +7 -3
  10. data/lib/will_paginate/view_helpers/link_renderer.rb +7 -5
  11. data/lib/will_paginate.rb +0 -12
  12. metadata +12 -49
  13. data/lib/will_paginate/data_mapper.rb +0 -100
  14. data/lib/will_paginate/view_helpers/merb.rb +0 -26
  15. data/spec/collection_spec.rb +0 -139
  16. data/spec/console +0 -12
  17. data/spec/console_fixtures.rb +0 -28
  18. data/spec/database.yml +0 -29
  19. data/spec/fake_rubygems.rb +0 -18
  20. data/spec/finders/active_record_spec.rb +0 -417
  21. data/spec/finders/activerecord_test_connector.rb +0 -140
  22. data/spec/finders/data_mapper_spec.rb +0 -114
  23. data/spec/finders/data_mapper_test_connector.rb +0 -54
  24. data/spec/finders/mongoid_spec.rb +0 -145
  25. data/spec/finders/sequel_spec.rb +0 -65
  26. data/spec/finders/sequel_test_connector.rb +0 -15
  27. data/spec/fixtures/admin.rb +0 -3
  28. data/spec/fixtures/developer.rb +0 -9
  29. data/spec/fixtures/developers_projects.yml +0 -13
  30. data/spec/fixtures/project.rb +0 -13
  31. data/spec/fixtures/projects.yml +0 -6
  32. data/spec/fixtures/replies.yml +0 -29
  33. data/spec/fixtures/reply.rb +0 -8
  34. data/spec/fixtures/schema.rb +0 -38
  35. data/spec/fixtures/topic.rb +0 -8
  36. data/spec/fixtures/topics.yml +0 -30
  37. data/spec/fixtures/user.rb +0 -2
  38. data/spec/fixtures/users.yml +0 -35
  39. data/spec/matchers/deprecation_matcher.rb +0 -27
  40. data/spec/matchers/phrase_matcher.rb +0 -19
  41. data/spec/matchers/query_count_matcher.rb +0 -36
  42. data/spec/page_number_spec.rb +0 -82
  43. data/spec/per_page_spec.rb +0 -41
  44. data/spec/spec_helper.rb +0 -46
  45. data/spec/view_helpers/action_view_spec.rb +0 -480
  46. data/spec/view_helpers/base_spec.rb +0 -143
  47. data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
  48. data/spec/view_helpers/view_example_group.rb +0 -146
@@ -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,145 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if !ENV['SKIP_NONRAILS_TESTS']
4
- if defined?(Rails)
5
- old_rails = Rails
6
- # Mongoid sees the `Rails` constant and then proceeds to `require "rails"`
7
- # from its railtie. This tricks it into believing there is no Rails.
8
- Object.send(:remove_const, :Rails)
9
- end
10
- require 'will_paginate/mongoid'
11
- Object.send(:const_set, :Rails, old_rails) if old_rails
12
-
13
- Mongoid.connect_to 'will_paginate_test'
14
- class MongoidModel
15
- include Mongoid::Document
16
- end
17
-
18
- mongoid_loaded = true
19
- else
20
- mongoid_loaded = false
21
- end
22
-
23
- describe WillPaginate::Mongoid do
24
- before(:all) do
25
- MongoidModel.delete_all
26
- 4.times { MongoidModel.create! }
27
- end
28
-
29
- let(:criteria) { MongoidModel.criteria }
30
-
31
- describe "#page" do
32
- it "should forward to the paginate method" do
33
- criteria.expects(:paginate).with(:page => 2).returns("itself")
34
- criteria.page(2).should == "itself"
35
- end
36
-
37
- it "should not override per_page if set earlier in the chain" do
38
- criteria.paginate(:per_page => 10).page(1).per_page.should == 10
39
- criteria.paginate(:per_page => 20).page(1).per_page.should == 20
40
- end
41
- end
42
-
43
- describe "#per_page" do
44
- it "should set the limit if given an argument" do
45
- criteria.per_page(10).options[:limit].should == 10
46
- end
47
-
48
- it "should return the current limit if no argument is given" do
49
- criteria.per_page.should == nil
50
- criteria.per_page(10).per_page.should == 10
51
- end
52
-
53
- it "should be interchangable with limit" do
54
- criteria.limit(15).per_page.should == 15
55
- end
56
-
57
- it "should be nil'able" do
58
- criteria.per_page(nil).per_page.should be_nil
59
- end
60
- end
61
-
62
- describe "#paginate" do
63
- it "should use criteria" do
64
- criteria.paginate.should be_instance_of(::Mongoid::Criteria)
65
- end
66
-
67
- it "should not override page number if set earlier in the chain" do
68
- criteria.page(3).paginate.current_page.should == 3
69
- end
70
-
71
- it "should limit according to per_page parameter" do
72
- criteria.paginate(:per_page => 10).options.should include(:limit => 10)
73
- end
74
-
75
- it "should skip according to page and per_page parameters" do
76
- criteria.paginate(:page => 2, :per_page => 5).options.should include(:skip => 5)
77
- end
78
-
79
- specify "first fallback value for per_page option is the current limit" do
80
- criteria.limit(12).paginate.options.should include(:limit => 12)
81
- end
82
-
83
- specify "second fallback value for per_page option is WillPaginate.per_page" do
84
- criteria.paginate.options.should include(:limit => WillPaginate.per_page)
85
- end
86
-
87
- specify "page should default to 1" do
88
- criteria.paginate.options.should include(:skip => 0)
89
- end
90
-
91
- it "should convert strings to integers" do
92
- criteria.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3)
93
- end
94
-
95
- describe "collection compatibility" do
96
- describe "#total_count" do
97
- it "should be calculated correctly" do
98
- criteria.paginate(:per_page => 1).total_entries.should == 4
99
- criteria.paginate(:per_page => 3).total_entries.should == 4
100
- end
101
-
102
- it "should be cached" do
103
- criteria.expects(:count).once.returns(123)
104
- criteria.paginate
105
- 2.times { criteria.total_entries.should == 123 }
106
- end
107
- end
108
-
109
- it "should calculate total_pages" do
110
- criteria.paginate(:per_page => 1).total_pages.should == 4
111
- criteria.paginate(:per_page => 3).total_pages.should == 2
112
- criteria.paginate(:per_page => 10).total_pages.should == 1
113
- end
114
-
115
- it "should return per_page" do
116
- criteria.paginate(:per_page => 1).per_page.should == 1
117
- criteria.paginate(:per_page => 5).per_page.should == 5
118
- end
119
-
120
- describe "#current_page" do
121
- it "should return current_page" do
122
- criteria.paginate(:page => 1).current_page.should == 1
123
- criteria.paginate(:page => 3).current_page.should == 3
124
- end
125
-
126
- it "should be casted to PageNumber" do
127
- page = criteria.paginate(:page => 1).current_page
128
- (page.instance_of? WillPaginate::PageNumber).should be
129
- end
130
- end
131
-
132
- it "should return offset" do
133
- criteria.paginate(:page => 1).offset.should == 0
134
- criteria.paginate(:page => 2, :per_page => 5).offset.should == 5
135
- criteria.paginate(:page => 3, :per_page => 10).offset.should == 20
136
- end
137
-
138
- it "should not pollute plain mongoid criterias" do
139
- %w(total_entries total_pages current_page).each do |method|
140
- criteria.should_not respond_to(method)
141
- end
142
- end
143
- end
144
- end
145
- end if mongoid_loaded
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if !ENV['SKIP_NONRAILS_TESTS']
4
- require 'will_paginate/sequel'
5
- require File.expand_path('../sequel_test_connector', __FILE__)
6
- sequel_loaded = true
7
- else
8
- sequel_loaded = false
9
- end
10
-
11
- describe Sequel::Dataset::Pagination, 'extension' do
12
-
13
- class Car < Sequel::Model
14
- end
15
-
16
- it "should have the #paginate method" do
17
- Car.should respond_to(:paginate)
18
- end
19
-
20
- it "should NOT have the #paginate_by_sql method" do
21
- Car.should_not respond_to(:paginate_by_sql)
22
- end
23
-
24
- describe 'pagination' do
25
- before(:all) do
26
- Car.create(:name => 'Shelby', :notes => "Man's best friend")
27
- Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
28
- Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
29
- end
30
-
31
- it "should imitate WillPaginate::Collection" do
32
- result = Car.paginate(1, 2)
33
-
34
- result.should_not be_empty
35
- result.size.should == 2
36
- result.length.should == 2
37
- result.total_entries.should == 3
38
- result.total_pages.should == 2
39
- result.per_page.should == 2
40
- result.current_page.should == 1
41
- end
42
-
43
- it "should perform" do
44
- Car.paginate(1, 2).all.should == [Car[1], Car[2]]
45
- end
46
-
47
- it "should be empty" do
48
- result = Car.paginate(3, 2)
49
- result.should be_empty
50
- end
51
-
52
- it "should perform with #select and #order" do
53
- result = Car.select("name as foo".lit).order(:name).paginate(1, 2).all
54
- result.size.should == 2
55
- result.first.values[:foo].should == "Aston Martin"
56
- end
57
-
58
- it "should perform with #filter" do
59
- results = Car.filter(:name => 'Shelby').paginate(1, 2).all
60
- results.size.should == 1
61
- results.first.should == Car.find(:name => 'Shelby')
62
- end
63
- end
64
-
65
- 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
3
- end
@@ -1,9 +0,0 @@
1
- class Developer < User
2
- has_and_belongs_to_many :projects, :join_table => 'developers_projects'
3
-
4
- scope :poor, lambda {
5
- where(['salary <= ?', 80000]).order('salary')
6
- }
7
-
8
- def self.per_page() 10 end
9
- 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,13 +0,0 @@
1
- class Project < ActiveRecord::Base
2
- has_and_belongs_to_many :developers, :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
- where(['replies.created_at > ?', 15.minutes.ago])
11
- end
12
- end
13
- 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,8 +0,0 @@
1
- class Reply < ActiveRecord::Base
2
- scope :recent, lambda {
3
- where(['replies.created_at > ?', 15.minutes.ago]).
4
- order('replies.created_at DESC')
5
- }
6
-
7
- validates_presence_of :content
8
- 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,8 +0,0 @@
1
- class Topic < ActiveRecord::Base
2
- has_many :replies, :dependent => :destroy
3
- belongs_to :project
4
-
5
- scope :mentions_activerecord, lambda {
6
- where(['topics.title LIKE ?', '%ActiveRecord%'])
7
- }
8
- 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,27 +0,0 @@
1
- require 'stringio'
2
-
3
- class DeprecationMatcher
4
- def initialize(message)
5
- @message = message
6
- end
7
-
8
- def matches?(block)
9
- @actual = hijack_stderr(&block)
10
- PhraseMatcher.new("DEPRECATION WARNING: #{@message}").matches?(@actual)
11
- end
12
-
13
- def failure_message
14
- "expected deprecation warning #{@message.inspect}, got #{@actual.inspect}"
15
- end
16
-
17
- private
18
-
19
- def hijack_stderr
20
- err = $stderr
21
- $stderr = StringIO.new
22
- yield
23
- $stderr.string.rstrip
24
- ensure
25
- $stderr = err
26
- end
27
- end
@@ -1,19 +0,0 @@
1
- class PhraseMatcher
2
- def initialize(string)
3
- @string = string
4
- @pattern = /\b#{Regexp.escape string}\b/
5
- end
6
-
7
- def matches?(actual)
8
- @actual = actual.to_s
9
- @actual =~ @pattern
10
- end
11
-
12
- def failure_message
13
- "expected #{@actual.inspect} to contain phrase #{@string.inspect}"
14
- end
15
-
16
- def negative_failure_message
17
- "expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
18
- end
19
- end
@@ -1,36 +0,0 @@
1
- class QueryCountMatcher
2
- def initialize(num)
3
- @expected_count = num
4
- end
5
-
6
- def matches?(block)
7
- run(block)
8
-
9
- if @expected_count.respond_to? :include?
10
- @expected_count.include? @count
11
- else
12
- @count == @expected_count
13
- end
14
- end
15
-
16
- def run(block)
17
- $query_count = 0
18
- $query_sql = []
19
- block.call
20
- ensure
21
- @queries = $query_sql.dup
22
- @count = $query_count
23
- end
24
-
25
- def performed_queries
26
- @queries
27
- end
28
-
29
- def failure_message
30
- "expected #{@expected_count} queries, got #{@count}\n#{@queries.join("\n")}"
31
- end
32
-
33
- def negative_failure_message
34
- "expected query count not to be #{@expected_count}"
35
- end
36
- end
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
- require 'will_paginate/page_number'
3
-
4
- describe WillPaginate::PageNumber do
5
- describe "valid" do
6
- def num
7
- WillPaginate::PageNumber.new('12', 'page')
8
- end
9
-
10
- it "== 12" do
11
- num.should eq(12)
12
- end
13
-
14
- it "inspects to 'page 12'" do
15
- num.inspect.should eq('page 12')
16
- end
17
-
18
- it "is a PageNumber" do
19
- (num.instance_of? WillPaginate::PageNumber).should be
20
- end
21
-
22
- it "is a kind of Numeric" do
23
- (num.is_a? Numeric).should be
24
- end
25
-
26
- it "is a kind of Integer" do
27
- (num.is_a? Integer).should be
28
- end
29
-
30
- it "isn't directly a Integer" do
31
- (num.instance_of? Integer).should_not be
32
- end
33
-
34
- it "passes the PageNumber=== type check" do |variable|
35
- (WillPaginate::PageNumber === num).should be
36
- end
37
-
38
- it "passes the Numeric=== type check" do |variable|
39
- (Numeric === num).should be
40
- end
41
- end
42
-
43
- describe "invalid" do
44
- def create(value, name = 'page')
45
- described_class.new(value, name)
46
- end
47
-
48
- it "errors out on non-int values" do
49
- lambda { create(nil) }.should raise_error(WillPaginate::InvalidPage)
50
- lambda { create('') }.should raise_error(WillPaginate::InvalidPage)
51
- lambda { create('Schnitzel') }.should raise_error(WillPaginate::InvalidPage)
52
- end
53
-
54
- it "errors out on zero or less" do
55
- lambda { create(0) }.should raise_error(WillPaginate::InvalidPage)
56
- lambda { create(-1) }.should raise_error(WillPaginate::InvalidPage)
57
- end
58
-
59
- it "doesn't error out on zero for 'offset'" do
60
- lambda { create(0, 'offset') }.should_not raise_error
61
- lambda { create(-1, 'offset') }.should raise_error(WillPaginate::InvalidPage)
62
- end
63
- end
64
-
65
- describe "coercion method" do
66
- it "defaults to 'page' name" do
67
- num = WillPaginate::PageNumber(12)
68
- num.inspect.should eq('page 12')
69
- end
70
-
71
- it "accepts a custom name" do
72
- num = WillPaginate::PageNumber(12, 'monkeys')
73
- num.inspect.should eq('monkeys 12')
74
- end
75
-
76
- it "doesn't affect PageNumber instances" do
77
- num = WillPaginate::PageNumber(12)
78
- num2 = WillPaginate::PageNumber(num)
79
- num2.object_id.should eq(num.object_id)
80
- end
81
- end
82
- end