Turn classic_pagination plugin into a library
This commit is contained in:
parent
10fb373e5e
commit
ca8e1bf188
22 changed files with 2 additions and 696 deletions
|
@ -21,8 +21,8 @@
|
|||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#++
|
||||
|
||||
require 'pagination'
|
||||
require 'pagination_helper'
|
||||
require 'classic_pagination/pagination'
|
||||
require 'classic_pagination/pagination_helper'
|
||||
|
||||
ActionController::Base.class_eval do
|
||||
include ActionController::Pagination
|
152
vendor/plugins/classic_pagination/CHANGELOG
vendored
152
vendor/plugins/classic_pagination/CHANGELOG
vendored
|
@ -1,152 +0,0 @@
|
|||
* Exported the changelog of Pagination code for historical reference.
|
||||
|
||||
* Imported some patches from Rails Trac (others closed as "wontfix"):
|
||||
#8176, #7325, #7028, #4113. Documentation is much cleaner now and there
|
||||
are some new unobtrusive features!
|
||||
|
||||
* Extracted Pagination from Rails trunk (r6795)
|
||||
|
||||
#
|
||||
# ChangeLog for /trunk/actionpack/lib/action_controller/pagination.rb
|
||||
#
|
||||
# Generated by Trac 0.10.3
|
||||
# 05/20/07 23:48:02
|
||||
#
|
||||
|
||||
09/03/06 23:28:54 david [4953]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Docs and deprecation
|
||||
|
||||
08/07/06 12:40:14 bitsweat [4715]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Deprecate direct usage of @params. Update ActionView::Base for
|
||||
instance var deprecation.
|
||||
|
||||
06/21/06 02:16:11 rick [4476]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Fix indent in pagination documentation. Closes #4990. [Kevin Clark]
|
||||
|
||||
04/25/06 17:42:48 marcel [4268]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Remove all remaining references to @params in the documentation.
|
||||
|
||||
03/16/06 06:38:08 rick [3899]
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (modified)
|
||||
trivial documentation patch for #pagination_links [Francois
|
||||
Beausoleil] closes #4258
|
||||
|
||||
02/20/06 03:15:22 david [3620]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
* trunk/actionpack/test/activerecord/pagination_test.rb (modified)
|
||||
* trunk/activerecord/CHANGELOG (modified)
|
||||
* trunk/activerecord/lib/active_record/base.rb (modified)
|
||||
* trunk/activerecord/test/base_test.rb (modified)
|
||||
Added :count option to pagination that'll make it possible for the
|
||||
ActiveRecord::Base.count call to using something else than * for the
|
||||
count. Especially important for count queries using DISTINCT #3839
|
||||
[skaes]. Added :select option to Base.count that'll allow you to
|
||||
select something else than * to be counted on. Especially important
|
||||
for count queries using DISTINCT (closes #3839) [skaes].
|
||||
|
||||
02/09/06 09:17:40 nzkoz [3553]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
* trunk/actionpack/test/active_record_unit.rb (added)
|
||||
* trunk/actionpack/test/activerecord (added)
|
||||
* trunk/actionpack/test/activerecord/active_record_assertions_test.rb (added)
|
||||
* trunk/actionpack/test/activerecord/pagination_test.rb (added)
|
||||
* trunk/actionpack/test/controller/active_record_assertions_test.rb (deleted)
|
||||
* trunk/actionpack/test/fixtures/companies.yml (added)
|
||||
* trunk/actionpack/test/fixtures/company.rb (added)
|
||||
* trunk/actionpack/test/fixtures/db_definitions (added)
|
||||
* trunk/actionpack/test/fixtures/db_definitions/sqlite.sql (added)
|
||||
* trunk/actionpack/test/fixtures/developer.rb (added)
|
||||
* trunk/actionpack/test/fixtures/developers_projects.yml (added)
|
||||
* trunk/actionpack/test/fixtures/developers.yml (added)
|
||||
* trunk/actionpack/test/fixtures/project.rb (added)
|
||||
* trunk/actionpack/test/fixtures/projects.yml (added)
|
||||
* trunk/actionpack/test/fixtures/replies.yml (added)
|
||||
* trunk/actionpack/test/fixtures/reply.rb (added)
|
||||
* trunk/actionpack/test/fixtures/topic.rb (added)
|
||||
* trunk/actionpack/test/fixtures/topics.yml (added)
|
||||
* Fix pagination problems when using include
|
||||
* Introduce Unit Tests for pagination
|
||||
* Allow count to work with :include by using count distinct.
|
||||
|
||||
[Kevin Clark & Jeremy Hopple]
|
||||
|
||||
11/05/05 02:10:29 bitsweat [2878]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Update paginator docs. Closes #2744.
|
||||
|
||||
10/16/05 15:42:03 minam [2649]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Update/clean up AP documentation (rdoc)
|
||||
|
||||
08/31/05 00:13:10 ulysses [2078]
|
||||
* trunk/actionpack/CHANGELOG (modified)
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Add option to specify the singular name used by pagination. Closes
|
||||
#1960
|
||||
|
||||
08/23/05 14:24:15 minam [2041]
|
||||
* trunk/actionpack/CHANGELOG (modified)
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
Add support for :include with pagination (subject to existing
|
||||
constraints for :include with :limit and :offset) #1478
|
||||
[michael@schubert.cx]
|
||||
|
||||
07/15/05 20:27:38 david [1839]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (modified)
|
||||
More pagination speed #1334 [Stefan Kaes]
|
||||
|
||||
07/14/05 08:02:01 david [1832]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (modified)
|
||||
* trunk/actionpack/test/controller/addresses_render_test.rb (modified)
|
||||
Made pagination faster #1334 [Stefan Kaes]
|
||||
|
||||
04/13/05 05:40:22 david [1159]
|
||||
* trunk/actionpack/CHANGELOG (modified)
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
* trunk/activerecord/lib/active_record/base.rb (modified)
|
||||
Fixed pagination to work with joins #1034 [scott@sigkill.org]
|
||||
|
||||
04/02/05 09:11:17 david [1067]
|
||||
* trunk/actionpack/CHANGELOG (modified)
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
* trunk/actionpack/lib/action_controller/scaffolding.rb (modified)
|
||||
* trunk/actionpack/lib/action_controller/templates/scaffolds/list.rhtml (modified)
|
||||
* trunk/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb (modified)
|
||||
* trunk/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml (modified)
|
||||
Added pagination for scaffolding (10 items per page) #964
|
||||
[mortonda@dgrmm.net]
|
||||
|
||||
03/31/05 14:46:11 david [1048]
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (modified)
|
||||
Improved the message display on the exception handler pages #963
|
||||
[Johan Sorensen]
|
||||
|
||||
03/27/05 00:04:07 david [1017]
|
||||
* trunk/actionpack/CHANGELOG (modified)
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (modified)
|
||||
Fixed that pagination_helper would ignore :params #947 [Sebastian
|
||||
Kanthak]
|
||||
|
||||
03/22/05 13:09:44 david [976]
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (modified)
|
||||
Fixed documentation and prepared for 0.11.0 release
|
||||
|
||||
03/21/05 14:35:36 david [967]
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (modified)
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (modified)
|
||||
Tweaked the documentation
|
||||
|
||||
03/20/05 23:12:05 david [949]
|
||||
* trunk/actionpack/CHANGELOG (modified)
|
||||
* trunk/actionpack/lib/action_controller.rb (modified)
|
||||
* trunk/actionpack/lib/action_controller/pagination.rb (added)
|
||||
* trunk/actionpack/lib/action_view/helpers/pagination_helper.rb (added)
|
||||
* trunk/activesupport/lib/active_support/core_ext/kernel.rb (added)
|
||||
Added pagination support through both a controller and helper add-on
|
||||
#817 [Sam Stephenson]
|
18
vendor/plugins/classic_pagination/README
vendored
18
vendor/plugins/classic_pagination/README
vendored
|
@ -1,18 +0,0 @@
|
|||
Pagination
|
||||
==========
|
||||
|
||||
To install:
|
||||
|
||||
script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination
|
||||
|
||||
This code was extracted from Rails trunk after the release 1.2.3.
|
||||
WARNING: this code is dead. It is unmaintained, untested and full of cruft.
|
||||
|
||||
There is a much better pagination plugin called will_paginate.
|
||||
Install it like this and glance through the README:
|
||||
|
||||
script/plugin install svn://errtheblog.com/svn/plugins/will_paginate
|
||||
|
||||
It doesn't have the same API, but is in fact much nicer. You can
|
||||
have both plugins installed until you change your controller/view code that
|
||||
handles pagination. Then, simply uninstall classic_pagination.
|
22
vendor/plugins/classic_pagination/Rakefile
vendored
22
vendor/plugins/classic_pagination/Rakefile
vendored
|
@ -1,22 +0,0 @@
|
|||
require 'rake'
|
||||
require 'rake/testtask'
|
||||
require 'rake/rdoctask'
|
||||
|
||||
desc 'Default: run unit tests.'
|
||||
task :default => :test
|
||||
|
||||
desc 'Test the classic_pagination plugin.'
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.libs << 'lib'
|
||||
t.pattern = 'test/**/*_test.rb'
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
desc 'Generate documentation for the classic_pagination plugin.'
|
||||
Rake::RDocTask.new(:rdoc) do |rdoc|
|
||||
rdoc.rdoc_dir = 'rdoc'
|
||||
rdoc.title = 'Pagination'
|
||||
rdoc.options << '--line-numbers' << '--inline-source'
|
||||
rdoc.rdoc_files.include('README')
|
||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
end
|
1
vendor/plugins/classic_pagination/install.rb
vendored
1
vendor/plugins/classic_pagination/install.rb
vendored
|
@ -1 +0,0 @@
|
|||
puts "\n\n" + File.read(File.dirname(__FILE__) + '/README')
|
|
@ -1,24 +0,0 @@
|
|||
thirty_seven_signals:
|
||||
id: 1
|
||||
name: 37Signals
|
||||
rating: 4
|
||||
|
||||
TextDrive:
|
||||
id: 2
|
||||
name: TextDrive
|
||||
rating: 4
|
||||
|
||||
PlanetArgon:
|
||||
id: 3
|
||||
name: Planet Argon
|
||||
rating: 4
|
||||
|
||||
Google:
|
||||
id: 4
|
||||
name: Google
|
||||
rating: 4
|
||||
|
||||
Ionist:
|
||||
id: 5
|
||||
name: Ioni.st
|
||||
rating: 4
|
|
@ -1,9 +0,0 @@
|
|||
class Company < ActiveRecord::Base
|
||||
attr_protected :rating
|
||||
set_sequence_name :companies_nonstd_seq
|
||||
|
||||
validates_presence_of :name
|
||||
def validate
|
||||
errors.add('rating', 'rating should not be 2') if rating == 2
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
class Developer < ActiveRecord::Base
|
||||
has_and_belongs_to_many :projects
|
||||
end
|
||||
|
||||
class DeVeLoPeR < ActiveRecord::Base
|
||||
set_table_name "developers"
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
david:
|
||||
id: 1
|
||||
name: David
|
||||
salary: 80000
|
||||
|
||||
jamis:
|
||||
id: 2
|
||||
name: Jamis
|
||||
salary: 150000
|
||||
|
||||
<% for digit in 3..10 %>
|
||||
dev_<%= digit %>:
|
||||
id: <%= digit %>
|
||||
name: fixture_<%= digit %>
|
||||
salary: 100000
|
||||
<% end %>
|
||||
|
||||
poor_jamis:
|
||||
id: 11
|
||||
name: Jamis
|
||||
salary: 9000
|
|
@ -1,13 +0,0 @@
|
|||
david_action_controller:
|
||||
developer_id: 1
|
||||
project_id: 2
|
||||
joined_on: 2004-10-10
|
||||
|
||||
david_active_record:
|
||||
developer_id: 1
|
||||
project_id: 1
|
||||
joined_on: 2004-10-10
|
||||
|
||||
jamis_active_record:
|
||||
developer_id: 2
|
||||
project_id: 1
|
|
@ -1,3 +0,0 @@
|
|||
class Project < ActiveRecord::Base
|
||||
has_and_belongs_to_many :developers, :uniq => true
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
action_controller:
|
||||
id: 2
|
||||
name: Active Controller
|
||||
|
||||
active_record:
|
||||
id: 1
|
||||
name: Active Record
|
|
@ -1,13 +0,0 @@
|
|||
witty_retort:
|
||||
id: 1
|
||||
topic_id: 1
|
||||
content: Birdman is better!
|
||||
created_at: <%= 6.hours.ago.to_s(:db) %>
|
||||
updated_at: nil
|
||||
|
||||
another:
|
||||
id: 2
|
||||
topic_id: 2
|
||||
content: Nuh uh!
|
||||
created_at: <%= 1.hour.ago.to_s(:db) %>
|
||||
updated_at: nil
|
|
@ -1,5 +0,0 @@
|
|||
class Reply < ActiveRecord::Base
|
||||
belongs_to :topic, :include => [:replies]
|
||||
|
||||
validates_presence_of :content
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
CREATE TABLE 'companies' (
|
||||
'id' INTEGER PRIMARY KEY NOT NULL,
|
||||
'name' TEXT DEFAULT NULL,
|
||||
'rating' INTEGER DEFAULT 1
|
||||
);
|
||||
|
||||
CREATE TABLE 'replies' (
|
||||
'id' INTEGER PRIMARY KEY NOT NULL,
|
||||
'content' text,
|
||||
'created_at' datetime,
|
||||
'updated_at' datetime,
|
||||
'topic_id' integer
|
||||
);
|
||||
|
||||
CREATE TABLE 'topics' (
|
||||
'id' INTEGER PRIMARY KEY NOT NULL,
|
||||
'title' varchar(255),
|
||||
'subtitle' varchar(255),
|
||||
'content' text,
|
||||
'created_at' datetime,
|
||||
'updated_at' datetime
|
||||
);
|
||||
|
||||
CREATE TABLE 'developers' (
|
||||
'id' INTEGER PRIMARY KEY NOT NULL,
|
||||
'name' TEXT DEFAULT NULL,
|
||||
'salary' INTEGER DEFAULT 70000,
|
||||
'created_at' DATETIME DEFAULT NULL,
|
||||
'updated_at' DATETIME DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE 'projects' (
|
||||
'id' INTEGER PRIMARY KEY NOT NULL,
|
||||
'name' TEXT DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE 'developers_projects' (
|
||||
'developer_id' INTEGER NOT NULL,
|
||||
'project_id' INTEGER NOT NULL,
|
||||
'joined_on' DATE DEFAULT NULL,
|
||||
'access_level' INTEGER DEFAULT 1
|
||||
);
|
|
@ -1,3 +0,0 @@
|
|||
class Topic < ActiveRecord::Base
|
||||
has_many :replies, :include => [:user], :dependent => :destroy
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
futurama:
|
||||
id: 1
|
||||
title: Isnt futurama awesome?
|
||||
subtitle: It really is, isnt it.
|
||||
content: I like futurama
|
||||
created_at: <%= 1.day.ago.to_s(:db) %>
|
||||
updated_at:
|
||||
|
||||
harvey_birdman:
|
||||
id: 2
|
||||
title: Harvey Birdman is the king of all men
|
||||
subtitle: yup
|
||||
content: It really is
|
||||
created_at: <%= 2.hours.ago.to_s(:db) %>
|
||||
updated_at:
|
||||
|
||||
rails:
|
||||
id: 3
|
||||
title: Rails is nice
|
||||
subtitle: It makes me happy
|
||||
content: except when I have to hack internals to fix pagination. even then really.
|
||||
created_at: <%= 20.minutes.ago.to_s(:db) %>
|
117
vendor/plugins/classic_pagination/test/helper.rb
vendored
117
vendor/plugins/classic_pagination/test/helper.rb
vendored
|
@ -1,117 +0,0 @@
|
|||
require 'test/unit'
|
||||
|
||||
unless defined?(ActiveRecord)
|
||||
plugin_root = File.join(File.dirname(__FILE__), '..')
|
||||
|
||||
# first look for a symlink to a copy of the framework
|
||||
if framework_root = ["#{plugin_root}/rails", "#{plugin_root}/../../rails"].find { |p| File.directory? p }
|
||||
puts "found framework root: #{framework_root}"
|
||||
# this allows for a plugin to be tested outside an app
|
||||
$:.unshift "#{framework_root}/activesupport/lib", "#{framework_root}/activerecord/lib", "#{framework_root}/actionpack/lib"
|
||||
else
|
||||
# is the plugin installed in an application?
|
||||
app_root = plugin_root + '/../../..'
|
||||
|
||||
if File.directory? app_root + '/config'
|
||||
puts 'using config/boot.rb'
|
||||
ENV['RAILS_ENV'] = 'test'
|
||||
require File.expand_path(app_root + '/config/boot')
|
||||
else
|
||||
# simply use installed gems if available
|
||||
puts 'using rubygems'
|
||||
require 'rubygems'
|
||||
gem 'actionpack'; gem 'activerecord'
|
||||
end
|
||||
end
|
||||
|
||||
%w(action_pack active_record action_controller active_record/fixtures action_controller/test_process).each {|f| require f}
|
||||
|
||||
Dependencies.load_paths.unshift "#{plugin_root}/lib"
|
||||
end
|
||||
|
||||
# Define the connector
|
||||
class ActiveRecordTestConnector
|
||||
cattr_accessor :able_to_connect
|
||||
cattr_accessor :connected
|
||||
|
||||
# Set our defaults
|
||||
self.connected = false
|
||||
self.able_to_connect = true
|
||||
|
||||
class << self
|
||||
def setup
|
||||
unless self.connected || !self.able_to_connect
|
||||
setup_connection
|
||||
load_schema
|
||||
require_fixture_models
|
||||
self.connected = true
|
||||
end
|
||||
rescue Exception => e # errors from ActiveRecord setup
|
||||
$stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
|
||||
#$stderr.puts " #{e.backtrace.join("\n ")}\n"
|
||||
self.able_to_connect = false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def setup_connection
|
||||
if Object.const_defined?(:ActiveRecord)
|
||||
defaults = { :database => ':memory:' }
|
||||
begin
|
||||
options = defaults.merge :adapter => 'sqlite3', :timeout => 500
|
||||
ActiveRecord::Base.establish_connection(options)
|
||||
ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
|
||||
ActiveRecord::Base.connection
|
||||
rescue Exception # errors from establishing a connection
|
||||
$stderr.puts 'SQLite 3 unavailable; trying SQLite 2.'
|
||||
options = defaults.merge :adapter => 'sqlite'
|
||||
ActiveRecord::Base.establish_connection(options)
|
||||
ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options }
|
||||
ActiveRecord::Base.connection
|
||||
end
|
||||
|
||||
Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE)
|
||||
else
|
||||
raise "Can't setup connection since ActiveRecord isn't loaded."
|
||||
end
|
||||
end
|
||||
|
||||
# Load actionpack sqlite tables
|
||||
def load_schema
|
||||
File.read(File.dirname(__FILE__) + "/fixtures/schema.sql").split(';').each do |sql|
|
||||
ActiveRecord::Base.connection.execute(sql) unless sql.blank?
|
||||
end
|
||||
end
|
||||
|
||||
def require_fixture_models
|
||||
Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each {|f| require f}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Test case for inheritance
|
||||
class ActiveRecordTestCase < Test::Unit::TestCase
|
||||
# Set our fixture path
|
||||
if ActiveRecordTestConnector.able_to_connect
|
||||
self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
|
||||
self.use_transactional_fixtures = false
|
||||
end
|
||||
|
||||
def self.fixtures(*args)
|
||||
super if ActiveRecordTestConnector.connected
|
||||
end
|
||||
|
||||
def run(*args)
|
||||
super if ActiveRecordTestConnector.connected
|
||||
end
|
||||
|
||||
# Default so Test::Unit::TestCase doesn't complain
|
||||
def test_truth
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecordTestConnector.setup
|
||||
ActionController::Routing::Routes.reload rescue nil
|
||||
ActionController::Routing::Routes.draw do |map|
|
||||
map.connect ':controller/:action/:id'
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/helper'
|
||||
require File.dirname(__FILE__) + '/../init'
|
||||
|
||||
class PaginationHelperTest < Test::Unit::TestCase
|
||||
include ActionController::Pagination
|
||||
include ActionView::Helpers::PaginationHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def setup
|
||||
@controller = Class.new do
|
||||
attr_accessor :url, :request
|
||||
def url_for(options, *parameters_for_method_reference)
|
||||
url
|
||||
end
|
||||
end
|
||||
@controller = @controller.new
|
||||
@controller.url = "http://www.example.com"
|
||||
end
|
||||
|
||||
def test_pagination_links
|
||||
total, per_page, page = 30, 10, 1
|
||||
output = pagination_links Paginator.new(@controller, total, per_page, page)
|
||||
assert_equal "1 <a href=\"http://www.example.com\">2</a> <a href=\"http://www.example.com\">3</a> ", output
|
||||
end
|
||||
|
||||
def test_pagination_links_with_prefix
|
||||
total, per_page, page = 30, 10, 1
|
||||
output = pagination_links Paginator.new(@controller, total, per_page, page), :prefix => 'Newer '
|
||||
assert_equal "Newer 1 <a href=\"http://www.example.com\">2</a> <a href=\"http://www.example.com\">3</a> ", output
|
||||
end
|
||||
|
||||
def test_pagination_links_with_suffix
|
||||
total, per_page, page = 30, 10, 1
|
||||
output = pagination_links Paginator.new(@controller, total, per_page, page), :suffix => 'Older'
|
||||
assert_equal "1 <a href=\"http://www.example.com\">2</a> <a href=\"http://www.example.com\">3</a> Older", output
|
||||
end
|
||||
end
|
|
@ -1,177 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/helper'
|
||||
require File.dirname(__FILE__) + '/../init'
|
||||
|
||||
class PaginationTest < ActiveRecordTestCase
|
||||
fixtures :topics, :replies, :developers, :projects, :developers_projects
|
||||
|
||||
class PaginationController < ActionController::Base
|
||||
if respond_to? :view_paths=
|
||||
self.view_paths = [ "#{File.dirname(__FILE__)}/../fixtures/" ]
|
||||
else
|
||||
self.template_root = [ "#{File.dirname(__FILE__)}/../fixtures/" ]
|
||||
end
|
||||
|
||||
def simple_paginate
|
||||
@topic_pages, @topics = paginate(:topics)
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_per_page
|
||||
@topic_pages, @topics = paginate(:topics, :per_page => 1)
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_order
|
||||
@topic_pages, @topics = paginate(:topics, :order => 'created_at asc')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_order_by
|
||||
@topic_pages, @topics = paginate(:topics, :order_by => 'created_at asc')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_include_and_order
|
||||
@topic_pages, @topics = paginate(:topics, :include => :replies, :order => 'replies.created_at asc, topics.created_at asc')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_conditions
|
||||
@topic_pages, @topics = paginate(:topics, :conditions => ["created_at > ?", 30.minutes.ago])
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_class_name
|
||||
@developer_pages, @developers = paginate(:developers, :class_name => "DeVeLoPeR")
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_singular_name
|
||||
@developer_pages, @developers = paginate()
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_joins
|
||||
@developer_pages, @developers = paginate(:developers,
|
||||
:joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
||||
:conditions => 'project_id=1')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_join
|
||||
@developer_pages, @developers = paginate(:developers,
|
||||
:join => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
||||
:conditions => 'project_id=1')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_join_and_count
|
||||
@developer_pages, @developers = paginate(:developers,
|
||||
:join => 'd LEFT JOIN developers_projects ON d.id = developers_projects.developer_id',
|
||||
:conditions => 'project_id=1',
|
||||
:count => "d.id")
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def paginate_with_join_and_group
|
||||
@developer_pages, @developers = paginate(:developers,
|
||||
:join => 'INNER JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
||||
:group => 'developers.id')
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def rescue_errors(e) raise e end
|
||||
|
||||
def rescue_action(e) raise end
|
||||
|
||||
end
|
||||
|
||||
def setup
|
||||
@controller = PaginationController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
super
|
||||
end
|
||||
|
||||
# Single Action Pagination Tests
|
||||
|
||||
def test_simple_paginate
|
||||
get :simple_paginate
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
assert_equal 3, assigns(:topics).size
|
||||
end
|
||||
|
||||
def test_paginate_with_per_page
|
||||
get :paginate_with_per_page
|
||||
assert_equal 1, assigns(:topics).size
|
||||
assert_equal 3, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_order
|
||||
get :paginate_with_order
|
||||
expected = [topics(:futurama),
|
||||
topics(:harvey_birdman),
|
||||
topics(:rails)]
|
||||
assert_equal expected, assigns(:topics)
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_order_by
|
||||
get :paginate_with_order
|
||||
expected = assigns(:topics)
|
||||
get :paginate_with_order_by
|
||||
assert_equal expected, assigns(:topics)
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_conditions
|
||||
get :paginate_with_conditions
|
||||
expected = [topics(:rails)]
|
||||
assert_equal expected, assigns(:topics)
|
||||
assert_equal 1, assigns(:topic_pages).page_count
|
||||
end
|
||||
|
||||
def test_paginate_with_class_name
|
||||
get :paginate_with_class_name
|
||||
|
||||
assert assigns(:developers).size > 0
|
||||
assert_equal DeVeLoPeR, assigns(:developers).first.class
|
||||
end
|
||||
|
||||
def test_paginate_with_joins
|
||||
get :paginate_with_joins
|
||||
assert_equal 2, assigns(:developers).size
|
||||
developer_names = assigns(:developers).map { |d| d.name }
|
||||
assert developer_names.include?('David')
|
||||
assert developer_names.include?('Jamis')
|
||||
end
|
||||
|
||||
def test_paginate_with_join_and_conditions
|
||||
get :paginate_with_joins
|
||||
expected = assigns(:developers)
|
||||
get :paginate_with_join
|
||||
assert_equal expected, assigns(:developers)
|
||||
end
|
||||
|
||||
def test_paginate_with_join_and_count
|
||||
get :paginate_with_joins
|
||||
expected = assigns(:developers)
|
||||
get :paginate_with_join_and_count
|
||||
assert_equal expected, assigns(:developers)
|
||||
end
|
||||
|
||||
def test_paginate_with_include_and_order
|
||||
get :paginate_with_include_and_order
|
||||
expected = Topic.find(:all, :include => 'replies', :order => 'replies.created_at asc, topics.created_at asc', :limit => 10)
|
||||
assert_equal expected, assigns(:topics)
|
||||
end
|
||||
|
||||
def test_paginate_with_join_and_group
|
||||
get :paginate_with_join_and_group
|
||||
assert_equal 2, assigns(:developers).size
|
||||
assert_equal 2, assigns(:developer_pages).item_count
|
||||
developer_names = assigns(:developers).map { |d| d.name }
|
||||
assert developer_names.include?('David')
|
||||
assert developer_names.include?('Jamis')
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue