OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / spec / models / comic_spec.rb
index 64acd7e..098ff8f 100644 (file)
@@ -74,6 +74,15 @@ describe Comic do
         }.should raise_error(Pettanr::BadRequest)
       end
     end
+    
+    context 'descriptionを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @comic.description = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @comic.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
   end
   
   describe 'デフォルト値補充に於いて' do
@@ -569,6 +578,72 @@ describe Comic do
     end
   end
   
+  describe '他作家のコミック一覧取得に於いて' do
+    before do
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
+    end
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        Comic.stub(:list_opt).with(any_args).and_return({})
+        Comic.should_receive(:list_opt).with(any_args).exactly(1)
+        r = Comic.himlist @other_author
+      end
+    end
+    it '指定した作家のリストを返す' do
+      r = Comic.himlist @other_author
+      r.should eq [@other_comic]
+    end
+    it '時系列で並んでいる' do
+      nc = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100
+      r = Comic.himlist @other_author
+      r.should eq [nc, @other_comic]
+    end
+    it '公開コミックに限る ' do
+      hidden = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 0
+      r = Comic.himlist @other_author
+      r.should eq [@other_comic]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @other_comic2 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100
+        @other_comic3 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 200
+        @other_comic4 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 300
+        @other_comic5 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 400
+      end
+      it '通常は2件を返す' do
+        c = Comic.himlist @other_author, 1, 2
+        c.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        c = Comic.himlist(@other_author, 1, 2)
+        c.should eq [@other_comic5, @other_comic4]
+      end
+      it 'page=2なら中間2件を返す' do
+        c = Comic.himlist(@other_author, 2, 2)
+        c.should eq [@other_comic3, @other_comic2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        c = Comic.himlist(@other_author, 3, 2)
+        c.should eq [@other_comic]
+      end
+    end
+    context 'DBに5件あって1ページの件数を0件に変えたとして' do
+      before do
+        @other_comic2 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100
+        @other_comic3 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 200
+        @other_comic4 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 300
+        @other_comic5 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 400
+        Author.stub(:default_comic_page_size).and_return(2)
+      end
+      it '通常は全件(5件)を返す' do
+        r = Comic.himlist @other_author, 5, 0
+        r.should have(5).items 
+      end
+    end
+  end
+  
   describe '単体取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id