Permalink
Browse files

warn for #num_pages method deprecation

  • Loading branch information...
1 parent c66ffd1 commit 9bf009e1eee658e1ac603847ff2f25b3615ed7f2 @eitoball committed Sep 15, 2012
Showing with 23 additions and 1 deletion.
  1. +5 −1 lib/kaminari/models/page_scope_methods.rb
  2. +18 −0 spec/models/active_record/scopes_spec.rb
@@ -20,8 +20,12 @@ def padding(num)
def total_pages
(total_count.to_f / limit_value).ceil
end
+
#FIXME for compatibility. remove num_pages at some time in the future
- alias num_pages total_pages
+ def num_pages
+ ActiveSupport::Deprecation.warn('num_pages is deprecated and will be removed from next major or minor release')
+ total_pages
+ end
# Current page number
def current_page
@@ -100,6 +100,24 @@
end
end
+ describe '#num_pages' do
+ before do
+ ActiveSupport::Deprecation.behavior = :stderr
+ @original_stderr, $stderr = $stderr, StringIO.new
+ end
+
+ after do
+ $stderr = @original_stderr
+ end
+
+ it 'should still work and warn deprecation' do
+ lambda {
+ model_class.page.num_pages.should == 4
+ }.should_not raise_exception
+ $stderr.string.should match(/^DEPRECATION WARNING: num_pages is deprecated/)
+ end
+ end
+
describe '#current_page' do
context 'page 1' do

0 comments on commit 9bf009e

Please sign in to comment.