OSDN Git Service

t#32046:
[pettanr/pettanr.git] / spec / models / ground_color_spec.rb
index 44a778c..7f0567e 100644 (file)
@@ -4,6 +4,7 @@ require 'spec_helper'
 
 describe GroundColor do
   before do
+    SpeechBalloonTemplate.delete_all
     @admin = FactoryGirl.create :admin
     @user = FactoryGirl.create( :user_yas)
     @author = FactoryGirl.create :author, :user_id => @user.id
@@ -29,11 +30,13 @@ describe GroundColor do
       it '下限データが通る' do
         @gc.code = 0
         @gc.z = 1
+        @gc.t = 0
         @gc.should be_valid
       end
       it '上限データが通る' do
         @gc.code = 99999
         @gc.z = 99999
+        @gc.t = 99999
         @gc.should be_valid
       end
     end
@@ -85,6 +88,35 @@ describe GroundColor do
         @gc.should_not be_valid
       end
     end
+    context 'tを検証するとき' do
+      it 'nullなら失敗する' do
+        @gc.t = nil
+        @gc.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @gc.t = 'a'
+        @gc.should_not be_valid
+      end
+      it '負なら失敗する' do
+        @gc.t = -1
+        @gc.should_not be_valid
+      end
+    end
+  end
+  
+  describe '文字コード検証に於いて' do
+    before do
+      @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
+    end
+    
+    context 'captionを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @gc.caption = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @gc.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
   end
   
   describe 'デフォルト値補充に於いて' do
@@ -95,9 +127,10 @@ describe GroundColor do
   end
   
   describe '上書き補充に於いて' do
-    it 'defined' do
+    it 'panel_idが設定されている' do
       @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
-      @gc.overwrite
+      @gc.overwrite  @panel.id
+      @gc.panel_id.should eq @panel.id
     end
   end
   
@@ -257,19 +290,6 @@ describe GroundColor do
         pl.should eq [@gc]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
-        @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
-        @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
-        @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
-        GroundColor.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundColor.list 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '自分のコマで使った色地一覧取得に於いて' do
@@ -329,19 +349,6 @@ describe GroundColor do
         c.should eq [@gc]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
-        @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
-        @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
-        @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
-        Author.stub(:default_ground_color_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundColor.mylist @author, 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '他作家の色地一覧取得に於いて' do
@@ -391,36 +398,79 @@ describe GroundColor do
         pl.should eq [@other_gc]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
-        @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
-        @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
-        @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
-        Author.stub(:default_ground_color_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundColor.himlist @other_author, 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe '色地一覧ページ制御に於いて' do
+    before do
+      GroundColor.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundColor.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '色地一覧の取得条件を利用している' do
+      GroundColor.stub(:list_where).with(any_args).and_return('')
+      GroundColor.should_receive(:list_where).with(any_args).exactly(1)
+      r = GroundColor.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundColor.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
   end
   
-  describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = GroundColor.list_opt
-      r.has_key?(:include).should be_true
+  describe '自分の色地一覧ページ制御に於いて' do
+    before do
+      GroundColor.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundColor.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '自分の色地一覧の取得条件を利用している' do
+      GroundColor.stub(:mylist_where).with(any_args).and_return('')
+      GroundColor.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = GroundColor.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundColor.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '他作家の色地一覧ページ制御に於いて' do
+    before do
+      GroundColor.stub(:count).with(any_args).and_return(100)
     end
+    it 'ページ制御を返す' do
+      r = GroundColor.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家の色地一覧の取得条件を利用している' do
+      GroundColor.stub(:himlist_where).with(any_args).and_return('')
+      GroundColor.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = GroundColor.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundColor.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
     it '1つの項目を含んでいる' do
-      r = GroundColor.list_opt[:include]
+      r = GroundColor.list_opt
       r.should have(1).items
     end
     it 'コマを含んでいる' do
-      r = GroundColor.list_opt[:include]
+      r = GroundColor.list_opt
       r.has_key?(:panel).should be_true
     end
       it 'コマは作家を含んでいる' do
-        r = GroundColor.list_opt[:include]
+        r = GroundColor.list_opt
         r[:panel].has_key?(:author).should be_true
       end
   end
@@ -430,9 +480,9 @@ describe GroundColor do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       @sbt = FactoryGirl.create :speech_balloon_template
-      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
       @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
     end
     it 'コマを含んでいる' do