-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add will_paginate fixes and and refactored integration specs
- Loading branch information
Showing
7 changed files
with
169 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters