OSDN Git Service

t#31470:create pager
[pettanr/pettanr.git] / spec / models / author_spec.rb
index 10b3859..1504797 100644 (file)
@@ -271,43 +271,30 @@ describe Author do
         r.should eq [@author]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @other_user2 = FactoryGirl.create :user_yas
-        @author2 = FactoryGirl.create :author, :user_id => @other_user2.id
-        @author2.created_at = Time.now + 100
-        @author2.save
-        @other_user3 = FactoryGirl.create :user_yas
-        @author3 = FactoryGirl.create :author, :user_id => @other_user3.id
-        @author3.created_at = Time.now + 200
-        @author3.save
-        @other_user4 = FactoryGirl.create :user_yas
-        @author4 = FactoryGirl.create :author, :user_id => @other_user4.id
-        @author4.created_at = Time.now + 300
-        @author4.save
-        @other_user5 = FactoryGirl.create :user_yas
-        @author5 = FactoryGirl.create :author, :user_id => @other_user5.id
-        @author5.created_at = Time.now + 400
-        @author5.save
-        Author.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = Author.list 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe '一覧ページ制御に於いて' do
+    before do
+      Author.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Author.list_paginate
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Author.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
   end
+  
   describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = Author.list_opt
-      r.has_key?(:include).should be_true
-    end
     it '1つの項目を含んでいる' do
-      r = Author.list_opt[:include]
+      r = Author.list_opt
       r.should have(1).items
     end
     it '絵師を含んでいる' do
-      r = Author.list_opt[:include]
+      r = Author.list_opt
       r.has_key?(:artist).should be_true
     end
   end