OSDN Git Service

t#30021:add repeat on gp
[pettanr/pettanr.git] / spec / models / ground_picture_spec.rb
index e2e449f..5c8c283 100644 (file)
@@ -27,10 +27,16 @@ describe GroundPicture do
     
     context 'オーソドックスなデータのとき' do
       it '下限データが通る' do
+        @gp.repeat = 0
+        @gp.x = -99999
+        @gp.y = -99999
         @gp.z = 1
         @gp.should be_valid
       end
       it '上限データが通る' do
+        @gp.repeat = 3
+        @gp.x = 99999
+        @gp.y = 99999
         @gp.z = 99999
         @gp.should be_valid
       end
@@ -58,6 +64,44 @@ describe GroundPicture do
         @gp.should_not be_valid
       end
     end
+    context 'repeatを検証するとき' do
+      it 'nullなら失敗する' do
+        @gp.repeat = nil
+        @gp.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @gp.repeat = 'a'
+        @gp.should_not be_valid
+      end
+      it '-1なら失敗する' do
+        @gp.repeat = -1
+        @gp.should_not be_valid
+      end
+      it '4なら失敗する' do
+        @gp.repeat = 4
+        @gp.should_not be_valid
+      end
+    end
+    context 'xを検証するとき' do
+      it 'nullなら失敗する' do
+        @gp.x = nil
+        @gp.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @gp.x = 'a'
+        @gp.should_not be_valid
+      end
+    end
+    context 'yを検証するとき' do
+      it 'nullなら失敗する' do
+        @gp.y = nil
+        @gp.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @gp.y = 'a'
+        @gp.should_not be_valid
+      end
+    end
     context 'zを検証するとき' do
       it 'nullなら失敗する' do
         @gp.z = nil
@@ -79,9 +123,20 @@ describe GroundPicture do
   end
   
   describe 'デフォルト値補充に於いて' do
-    it 'defined' do
-      @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+    before do
+      @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+    end
+    it 'xに0を補充している' do
+      @gp.supply_default
+      @gp.x.should eq 0
+    end
+    it 'yに0を補充している' do
+      @gp.supply_default
+      @gp.y.should eq 0
+    end
+    it '繰り返しに0を補充している' do
       @gp.supply_default
+      @gp.repeat.should eq 0
     end
   end
   
@@ -121,13 +176,13 @@ describe GroundPicture do
         GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
       end
     end
-    context 'つつがなく終わるとき' do\r
-      it '一覧取得オプションを利用している' do\r
-        GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})\r
-        GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
+        GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
         r = GroundPicture.list
-      end\r
-    end\r
+      end
+    end
     it 'リストを返す' do
       pl = GroundPicture.list
       pl.should eq [@gp]
@@ -217,10 +272,10 @@ describe GroundPicture do
   end
   describe 'json一覧出力オプションに於いて' do
     before do
-      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
-      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
-      @sbt = FactoryGirl.create :speech_balloon_template\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      @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
       @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
@@ -265,13 +320,13 @@ describe GroundPicture do
     before do
       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
     end
-    context 'つつがなく終わるとき' do\r
-      it '一覧取得オプションを利用している' do\r
-        GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})\r
-        GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
+        GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
         r = GroundPicture.mylist @author
-      end\r
-    end\r
+      end
+    end
     it 'リストを返す' do
       pl = GroundPicture.mylist @author
       pl.should eq [@gp]
@@ -324,7 +379,7 @@ describe GroundPicture do
         @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
         @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
         @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
-        Author.stub(:default_ground_picture_page_size).and_return(2)\r
+        Author.stub(:default_ground_picture_page_size).and_return(2)
       end
       it '通常は全件(5件)を返す' do
         r = GroundPicture.mylist @author, 5, 0