Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add will_paginate fixes and and refactored integration specs

  • Loading branch information...
commit 3ec4970d0e9eec94e93f18a7c01c030cd752f26b 1 parent 838078b
Darcy Laycock authored
4 Gemfile
View
@@ -13,4 +13,8 @@ end
# 2.10 for the moment changes some exceptions.
gem 'rspec', '~> 2.9.0'
+if (wp_version = ENV['WILL_PAGINATE_VERSION'])
+ gem 'will_paginate', wp_version
+end
+
gemspec
21 Rakefile
View
@@ -10,10 +10,29 @@ desc "Run all specs in spec directory (excluding plugin specs)"
RSpec::Core::RakeTask.new(:spec)
namespace :spec do
+
+ namespace :integration do
+
+ desc "Run the will_paginate integrate specs"
+ RSpec::Core::RakeTask.new(:will_paginate) do |t|
+ t.rspec_opts = "--tag integration"
+ t.pattern = "./spec/integration/will_paginate_spec.rb"
+ end
+
+ desc "Run the will_paginate integrate specs"
+ RSpec::Core::RakeTask.new(:kaminari) do |t|
+ t.rspec_opts = "--tag integration"
+ t.pattern = "./spec/integration/kaminari_spec.rb"
+ end
+
+ end
+
desc "Run all specs with rcov"
RSpec::Core::RakeTask.new(:rcov) do |t|
t.rcov = true
t.pattern = "./spec/**/*_spec.rb"
t.rcov_opts = '--exclude spec/,/gems/,/Library/,/usr/,lib/tasks,.bundle,config,/lib/rspec/,/lib/rspec-'
end
-end
+end
+
+task :default => ["spec:integration:will_paginate", "spec:integration:kaminari"]
2  lib/rocket_pants/controller/respondable.rb
View
@@ -3,7 +3,7 @@ module Respondable
extend ActiveSupport::Concern
def self.pagination_type(object)
- if defined?(WillPaginate::Collection) && object.is_a?(WillPaginate::Collection)
+ if object.respond_to?(:total_entries)
:will_paginate
elsif object.respond_to?(:num_pages) && object.respond_to?(:current_page)
:kaminari
69 spec/integration/kaminari_spec.rb
View
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+describe RocketPants::Base, 'kaminari integration', :integration => true, :target => 'kaminari' do
+ include ControllerHelpers
+
+ before :all do
+ begin
+ stderr, $stderr = $stderr, StringIO.new
+ require 'kaminari'
+ ensure
+ $stderr = stderr
+ end
+ end
+
+ describe 'on models' do
+
+ let(:table_manager) { ReversibleData.manager_for(:users) }
+
+ before :all do
+ table_manager.up!
+ 25.times { |i| User.create :age => (18 + i) }
+ end
+
+ after(:all) do
+ User.delete_all
+ table_manager.down!
+ end
+
+ it 'should let you expose a kaminari-paginated collection' do
+ mock(TestController).test_data { User.page(1).per(5) }
+ get :test_data
+ content[:response].should be_present
+ content[:count].should == 5
+ content[:pagination].should be_present
+ content[:pagination][:count].should == 25
+ end
+
+ it 'should not expose non-paginated as paginated' do
+ mock(TestController).test_data { User.all }
+ get :test_data
+ content[:response].should be_present
+ content[:count].should == 25
+ content[:pagination].should_not be_present
+ end
+
+ end
+
+ describe 'on arrays' do
+
+ it 'should correctly convert a kaminari array' do
+ pager = Kaminari::PaginatableArray.new((1..200).to_a, :limit => 10, :offset => 10)
+ mock(TestController).test_data { pager }
+ get :test_data
+ content.should have_key(:pagination)
+ content[:pagination].should == {
+ :next => 3,
+ :current => 2,
+ :previous => 1,
+ :pages => 20,
+ :count => 200,
+ :per_page => 10
+ }.stringify_keys
+ content.should have_key(:count)
+ content[:count].should == 10
+ end
+
+ end
+
+end
74 spec/integration/will_paginate_spec.rb
View
@@ -0,0 +1,74 @@
+require 'spec_helper'
+
+describe RocketPants::Base, 'will_paginate integration', :integration => true, :target => 'will_paginate' do
+ include ControllerHelpers
+
+ before :all do
+ require 'will_paginate/active_record'
+ require 'will_paginate/collection'
+ end
+
+ describe 'on models' do
+
+ let(:table_manager) { ReversibleData.manager_for(:users) }
+
+ before :all do
+ table_manager.up!
+ 25.times { |i| User.create :age => (18 + i) }
+ end
+
+ after(:all) do
+ User.delete_all
+ table_manager.down!
+ end
+
+ it 'should let you expose a classically paginated collection' do
+ mock(TestController).test_data { User.paginate :per_page => 5, :page => 1 }
+ get :test_data
+ content[:response].should be_present
+ content[:count].should == 5
+ content[:pagination].should be_present
+ content[:pagination][:count].should == 25
+ end
+
+ it 'should not expose non-paginated as paginated' do
+ mock(TestController).test_data { User.all }
+ get :test_data
+ content[:response].should be_present
+ content[:count].should == 25
+ content[:pagination].should_not be_present
+ end
+
+ it 'should let you expose a relational collection' do
+ mock(TestController).test_data { User.page(1).limit(5).all }
+ get :test_data
+ content[:response].should be_present
+ content[:count].should == 5
+ content[:pagination].should be_present
+ content[:pagination][:count].should == 25
+ end
+
+ end
+
+ describe 'on arrays' do
+
+ it 'should correctly convert a will paginate collection' do
+ pager = WillPaginate::Collection.create(2, 10) { |p| p.replace %w(a b c d e f g h i j); p.total_entries = 200 }
+ mock(TestController).test_data { pager }
+ get :test_data
+ content.should have_key(:pagination)
+ content[:pagination].should == {
+ :next => 3,
+ :current => 2,
+ :previous => 1,
+ :pages => 20,
+ :count => 200,
+ :per_page => 10
+ }.stringify_keys
+ content.should have_key(:count)
+ content[:count].should == 10
+ end
+
+ end
+
+end
54 spec/rocket_pants/controller_spec.rb
View
@@ -1,15 +1,7 @@
require 'spec_helper'
require 'logger'
require 'stringio'
-
require 'will_paginate/collection'
-# Replace stderr because kaminari complains about not having a framework.
-begin
- stderr, $stderr = $stderr, StringIO.new
- require 'kaminari'
-ensure
- $stderr = stderr
-end
describe RocketPants::Base do
include ControllerHelpers
@@ -47,18 +39,6 @@
content[:count].should == 5
end
- it 'should let you expose a kaminari-paginated collection' do
- 1.upto(5) do |offset|
- User.create :age => (18 + offset)
- end
- mock(TestController).test_data { User.page(1).per(2) }
- get :test_data
- content[:response].should be_present
- content[:count].should == 2
- content[:pagination].should be_present
- content[:pagination][:count].should == 5
- end
-
end
end
@@ -93,40 +73,6 @@
response.status.should == 422
end
- it 'should correctly convert a kaminari array' do
- pager = Kaminari::PaginatableArray.new((1..200).to_a, :limit => 10, :offset => 10)
- mock(TestController).test_data { pager }
- get :test_data
- content.should have_key(:pagination)
- content[:pagination].should == {
- :next => 3,
- :current => 2,
- :previous => 1,
- :pages => 20,
- :count => 200,
- :per_page => 10
- }.stringify_keys
- content.should have_key(:count)
- content[:count].should == 10
- end
-
- it 'should correctly convert a will paginate collection' do
- pager = WillPaginate::Collection.create(2, 10) { |p| p.replace %w(a b c d e f g h i j); p.total_entries = 200 }
- mock(TestController).test_data { pager }
- get :test_data
- content.should have_key(:pagination)
- content[:pagination].should == {
- :next => 3,
- :current => 2,
- :previous => 1,
- :pages => 20,
- :count => 200,
- :per_page => 10
- }.stringify_keys
- content.should have_key(:count)
- content[:count].should == 10
- end
-
it 'should correctly convert a normal collection' do
mock(TestController).test_data { %w(a b c d) }
get :test_data
1  spec/spec_helper.rb
View
@@ -16,4 +16,5 @@
config.include I18nSpecHelper
config.include ConfigHelper
config.include WebmockResponses
+ config.filter_run_excluding :integration => true
end
Please sign in to comment.
Something went wrong with that request. Please try again.