will_paginate 3.1.5 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +8 -11
- data/lib/will_paginate/active_record.rb +7 -11
- data/lib/will_paginate/deprecation.rb +2 -2
- data/lib/will_paginate/i18n.rb +3 -3
- data/lib/will_paginate/locale/en.yml +4 -0
- data/lib/will_paginate/mongoid.rb +2 -0
- data/lib/will_paginate/page_number.rb +7 -11
- data/lib/will_paginate/railtie.rb +3 -4
- data/lib/will_paginate/version.rb +3 -3
- data/lib/will_paginate/view_helpers/action_view.rb +8 -4
- data/lib/will_paginate/view_helpers/hanami.rb +41 -0
- data/lib/will_paginate/view_helpers/link_renderer.rb +19 -14
- data/lib/will_paginate.rb +0 -12
- metadata +17 -48
- data/lib/will_paginate/data_mapper.rb +0 -100
- data/lib/will_paginate/view_helpers/merb.rb +0 -26
- data/spec/collection_spec.rb +0 -139
- data/spec/console +0 -12
- data/spec/console_fixtures.rb +0 -28
- data/spec/database.yml +0 -29
- data/spec/fake_rubygems.rb +0 -18
- data/spec/finders/active_record_spec.rb +0 -418
- data/spec/finders/activerecord_test_connector.rb +0 -132
- data/spec/finders/data_mapper_spec.rb +0 -116
- data/spec/finders/data_mapper_test_connector.rb +0 -54
- data/spec/finders/mongoid_spec.rb +0 -140
- data/spec/finders/sequel_spec.rb +0 -67
- data/spec/finders/sequel_test_connector.rb +0 -15
- data/spec/fixtures/admin.rb +0 -3
- data/spec/fixtures/developer.rb +0 -9
- data/spec/fixtures/developers_projects.yml +0 -13
- data/spec/fixtures/project.rb +0 -13
- data/spec/fixtures/projects.yml +0 -6
- data/spec/fixtures/replies.yml +0 -29
- data/spec/fixtures/reply.rb +0 -8
- data/spec/fixtures/schema.rb +0 -38
- data/spec/fixtures/topic.rb +0 -8
- data/spec/fixtures/topics.yml +0 -30
- data/spec/fixtures/user.rb +0 -2
- data/spec/fixtures/users.yml +0 -35
- data/spec/matchers/deprecation_matcher.rb +0 -27
- data/spec/matchers/phrase_matcher.rb +0 -19
- data/spec/matchers/query_count_matcher.rb +0 -36
- data/spec/page_number_spec.rb +0 -83
- data/spec/per_page_spec.rb +0 -41
- data/spec/spec_helper.rb +0 -46
- data/spec/view_helpers/action_view_spec.rb +0 -468
- data/spec/view_helpers/base_spec.rb +0 -143
- data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
- data/spec/view_helpers/view_example_group.rb +0 -146
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'active_record/fixtures'
|
3
|
-
require 'active_support/multibyte' # needed for Ruby 1.9.1
|
4
|
-
require 'stringio'
|
5
|
-
require 'erb'
|
6
|
-
|
7
|
-
# https://travis-ci.org/mislav/will_paginate/jobs/99999001
|
8
|
-
require 'active_support/core_ext/string/conversions'
|
9
|
-
class String
|
10
|
-
alias to_datetime_without_patch to_datetime
|
11
|
-
def to_datetime
|
12
|
-
to_datetime_without_patch
|
13
|
-
rescue ArgumentError
|
14
|
-
return nil
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
$query_count = 0
|
19
|
-
$query_sql = []
|
20
|
-
|
21
|
-
ignore_sql = /
|
22
|
-
^(
|
23
|
-
PRAGMA | SHOW\ (max_identifier_length|search_path) |
|
24
|
-
SELECT\ (currval|CAST|@@IDENTITY|@@ROWCOUNT) |
|
25
|
-
SHOW\ ((FULL\ )?FIELDS|TABLES)
|
26
|
-
)\b |
|
27
|
-
\bFROM\ (sqlite_master|pg_tables|pg_attribute)\b
|
28
|
-
/x
|
29
|
-
|
30
|
-
ActiveSupport::Notifications.subscribe(/^sql\./) do |*args|
|
31
|
-
payload = args.last
|
32
|
-
unless payload[:name] =~ /^Fixture/ or payload[:sql] =~ ignore_sql
|
33
|
-
$query_count += 1
|
34
|
-
$query_sql << payload[:sql]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module ActiverecordTestConnector
|
39
|
-
extend self
|
40
|
-
|
41
|
-
attr_accessor :able_to_connect
|
42
|
-
attr_accessor :connected
|
43
|
-
|
44
|
-
FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
|
45
|
-
|
46
|
-
Fixtures = defined?(ActiveRecord::FixtureSet) ? ActiveRecord::FixtureSet :
|
47
|
-
defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures :
|
48
|
-
::Fixtures
|
49
|
-
|
50
|
-
# Set our defaults
|
51
|
-
self.connected = false
|
52
|
-
self.able_to_connect = true
|
53
|
-
|
54
|
-
def setup
|
55
|
-
unless self.connected || !self.able_to_connect
|
56
|
-
setup_connection
|
57
|
-
load_schema
|
58
|
-
add_load_path FIXTURES_PATH
|
59
|
-
self.connected = true
|
60
|
-
end
|
61
|
-
rescue Exception => e # errors from ActiveRecord setup
|
62
|
-
$stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
|
63
|
-
self.able_to_connect = false
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def add_load_path(path)
|
69
|
-
dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
|
70
|
-
dep.autoload_paths.unshift path
|
71
|
-
end
|
72
|
-
|
73
|
-
def setup_connection
|
74
|
-
db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
|
75
|
-
|
76
|
-
erb = ERB.new(File.read(File.expand_path('../../database.yml', __FILE__)))
|
77
|
-
configurations = YAML.load(erb.result)
|
78
|
-
raise "no configuration for '#{db}'" unless configurations.key? db
|
79
|
-
configuration = configurations[db]
|
80
|
-
|
81
|
-
# ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
|
82
|
-
puts "using #{configuration['adapter']} adapter"
|
83
|
-
|
84
|
-
ActiveRecord::Base.configurations = { db => configuration }
|
85
|
-
ActiveRecord::Base.establish_connection(db.to_sym)
|
86
|
-
ActiveRecord::Base.default_timezone = :utc
|
87
|
-
end
|
88
|
-
|
89
|
-
def load_schema
|
90
|
-
begin
|
91
|
-
$stdout = StringIO.new
|
92
|
-
ActiveRecord::Migration.verbose = false
|
93
|
-
load File.join(FIXTURES_PATH, 'schema.rb')
|
94
|
-
ensure
|
95
|
-
$stdout = STDOUT
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
module FixtureSetup
|
100
|
-
def fixtures(*tables)
|
101
|
-
table_names = tables.map { |t| t.to_s }
|
102
|
-
|
103
|
-
fixtures = Fixtures.create_fixtures ActiverecordTestConnector::FIXTURES_PATH, table_names
|
104
|
-
@@loaded_fixtures = {}
|
105
|
-
@@fixture_cache = {}
|
106
|
-
|
107
|
-
unless fixtures.nil?
|
108
|
-
if fixtures.instance_of?(Fixtures)
|
109
|
-
@@loaded_fixtures[fixtures.table_name] = fixtures
|
110
|
-
else
|
111
|
-
fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
table_names.each do |table_name|
|
116
|
-
define_method(table_name) do |*fixtures|
|
117
|
-
@@fixture_cache[table_name] ||= {}
|
118
|
-
|
119
|
-
instances = fixtures.map do |fixture|
|
120
|
-
if @@loaded_fixtures[table_name][fixture.to_s]
|
121
|
-
@@fixture_cache[table_name][fixture] ||= @@loaded_fixtures[table_name][fixture.to_s].find
|
122
|
-
else
|
123
|
-
raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
instances.size == 1 ? instances.first : instances
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
@@ -1,116 +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 "overrides total_entries count with a fixed value" do
|
84
|
-
lambda {
|
85
|
-
animals = Animal.paginate :page => 1, :per_page => 3, :total_entries => 999
|
86
|
-
animals.total_entries.should == 999
|
87
|
-
}.should run_queries(0)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "supports a non-int for total_entries" do
|
91
|
-
topics = Animal.paginate :page => 1, :per_page => 3, :total_entries => "999"
|
92
|
-
topics.total_entries.should == 999
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
it "can iterate and then call WP methods" do
|
97
|
-
animals = Animal.all(:limit => 2).page(1)
|
98
|
-
animals.each { |a| }
|
99
|
-
animals.total_entries.should == 3
|
100
|
-
end
|
101
|
-
|
102
|
-
it "augments to_a to return a WP::Collection" do
|
103
|
-
animals = Animal.all(:limit => 2).page(1)
|
104
|
-
array = animals.to_a
|
105
|
-
array.size.should == 2
|
106
|
-
array.should be_kind_of(WillPaginate::Collection)
|
107
|
-
array.current_page.should == 1
|
108
|
-
array.per_page.should == 2
|
109
|
-
end
|
110
|
-
|
111
|
-
it "doesn't have a problem assigning has-one-through relationship" do
|
112
|
-
human = Human.create :name => "Mislav"
|
113
|
-
human.pet = Animal.first
|
114
|
-
end
|
115
|
-
|
116
|
-
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,140 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'will_paginate/mongoid'
|
5
|
-
rescue LoadError => error
|
6
|
-
warn "Error running Mongoid specs: #{error.message}"
|
7
|
-
mongoid_loaded = false
|
8
|
-
else
|
9
|
-
Mongoid.connect_to 'will_paginate_test'
|
10
|
-
|
11
|
-
class MongoidModel
|
12
|
-
include Mongoid::Document
|
13
|
-
end
|
14
|
-
|
15
|
-
mongoid_loaded = true
|
16
|
-
end
|
17
|
-
|
18
|
-
describe WillPaginate::Mongoid do
|
19
|
-
before(:all) do
|
20
|
-
MongoidModel.delete_all
|
21
|
-
4.times { MongoidModel.create! }
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:criteria) { MongoidModel.criteria }
|
25
|
-
|
26
|
-
describe "#page" do
|
27
|
-
it "should forward to the paginate method" do
|
28
|
-
criteria.expects(:paginate).with(:page => 2).returns("itself")
|
29
|
-
criteria.page(2).should == "itself"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should not override per_page if set earlier in the chain" do
|
33
|
-
criteria.paginate(:per_page => 10).page(1).per_page.should == 10
|
34
|
-
criteria.paginate(:per_page => 20).page(1).per_page.should == 20
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#per_page" do
|
39
|
-
it "should set the limit if given an argument" do
|
40
|
-
criteria.per_page(10).options[:limit].should == 10
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return the current limit if no argument is given" do
|
44
|
-
criteria.per_page.should == nil
|
45
|
-
criteria.per_page(10).per_page.should == 10
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should be interchangable with limit" do
|
49
|
-
criteria.limit(15).per_page.should == 15
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should be nil'able" do
|
53
|
-
criteria.per_page(nil).per_page.should be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#paginate" do
|
58
|
-
it "should use criteria" do
|
59
|
-
criteria.paginate.should be_instance_of(::Mongoid::Criteria)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not override page number if set earlier in the chain" do
|
63
|
-
criteria.page(3).paginate.current_page.should == 3
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should limit according to per_page parameter" do
|
67
|
-
criteria.paginate(:per_page => 10).options.should include(:limit => 10)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should skip according to page and per_page parameters" do
|
71
|
-
criteria.paginate(:page => 2, :per_page => 5).options.should include(:skip => 5)
|
72
|
-
end
|
73
|
-
|
74
|
-
specify "first fallback value for per_page option is the current limit" do
|
75
|
-
criteria.limit(12).paginate.options.should include(:limit => 12)
|
76
|
-
end
|
77
|
-
|
78
|
-
specify "second fallback value for per_page option is WillPaginate.per_page" do
|
79
|
-
criteria.paginate.options.should include(:limit => WillPaginate.per_page)
|
80
|
-
end
|
81
|
-
|
82
|
-
specify "page should default to 1" do
|
83
|
-
criteria.paginate.options.should include(:skip => 0)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should convert strings to integers" do
|
87
|
-
criteria.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3)
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "collection compatibility" do
|
91
|
-
describe "#total_count" do
|
92
|
-
it "should be calculated correctly" do
|
93
|
-
criteria.paginate(:per_page => 1).total_entries.should == 4
|
94
|
-
criteria.paginate(:per_page => 3).total_entries.should == 4
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should be cached" do
|
98
|
-
criteria.expects(:count).once.returns(123)
|
99
|
-
criteria.paginate
|
100
|
-
2.times { criteria.total_entries.should == 123 }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should calculate total_pages" do
|
105
|
-
criteria.paginate(:per_page => 1).total_pages.should == 4
|
106
|
-
criteria.paginate(:per_page => 3).total_pages.should == 2
|
107
|
-
criteria.paginate(:per_page => 10).total_pages.should == 1
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should return per_page" do
|
111
|
-
criteria.paginate(:per_page => 1).per_page.should == 1
|
112
|
-
criteria.paginate(:per_page => 5).per_page.should == 5
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "#current_page" do
|
116
|
-
it "should return current_page" do
|
117
|
-
criteria.paginate(:page => 1).current_page.should == 1
|
118
|
-
criteria.paginate(:page => 3).current_page.should == 3
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should be casted to PageNumber" do
|
122
|
-
page = criteria.paginate(:page => 1).current_page
|
123
|
-
(page.instance_of? WillPaginate::PageNumber).should be
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should return offset" do
|
128
|
-
criteria.paginate(:page => 1).offset.should == 0
|
129
|
-
criteria.paginate(:page => 2, :per_page => 5).offset.should == 5
|
130
|
-
criteria.paginate(:page => 3, :per_page => 10).offset.should == 20
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should not pollute plain mongoid criterias" do
|
134
|
-
%w(total_entries total_pages current_page).each do |method|
|
135
|
-
criteria.should_not respond_to(method)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end if mongoid_loaded
|
data/spec/finders/sequel_spec.rb
DELETED
@@ -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
|
data/spec/fixtures/admin.rb
DELETED
data/spec/fixtures/developer.rb
DELETED
data/spec/fixtures/project.rb
DELETED
@@ -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
|
data/spec/fixtures/projects.yml
DELETED
data/spec/fixtures/replies.yml
DELETED
@@ -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) %>
|
data/spec/fixtures/reply.rb
DELETED
data/spec/fixtures/schema.rb
DELETED
@@ -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
|
data/spec/fixtures/topic.rb
DELETED
data/spec/fixtures/topics.yml
DELETED
@@ -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) %>
|