OSDN Git Service

t#29312:any update
[pettanr/pettanr.git] / spec / models / panel_picture_spec.rb
index 09a3a47..f3a70a3 100644 (file)
@@ -23,9 +23,12 @@ describe PanelPicture do
     before do
       @pp = FactoryGirl.build :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
         :width => @p.width, :height => @p.height
+      Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
+      Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
+      Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
     end
     it 'オーソドックスなデータなら通る' do
-      @pp.save!
+      @pp.save
       @pp.should be_valid
     end
     
@@ -100,9 +103,6 @@ describe PanelPicture do
     end
     context 'widthを検証するとき' do
       before do
-        Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
-        Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
-        Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
       end
       it 'テストデータの確認' do
         @pp.width = 1
@@ -122,7 +122,6 @@ describe PanelPicture do
       end
       context  '反転許可のとき' do
         before do
-          Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
         end
         it '負でも通る' do
           @pp.width = -1
@@ -140,7 +139,6 @@ describe PanelPicture do
       end
       context  'サイズ変更許可のとき' do
         before do
-          Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
         end
         it '実素材のサイズと違っても通る' do
           @pp.width = @p.width-1
@@ -158,7 +156,6 @@ describe PanelPicture do
       end
       context  '縦横比変更許可のとき' do
         before do
-          Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
         end
         it '実素材の縦横比と違っても通る' do
           @pp.width = @p.width / 2
@@ -177,9 +174,6 @@ describe PanelPicture do
     end
     context 'heightを検証するとき' do
       before do
-        Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
-        Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
-        Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
       end
       it 'テストデータの確認' do
         @pp.height = '1'
@@ -203,7 +197,6 @@ describe PanelPicture do
       end
       context  '反転許可のとき' do
         before do
-          Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
         end
         it '負でも通る' do
           @pp.height = -1
@@ -221,7 +214,6 @@ describe PanelPicture do
       end
       context  'サイズ変更許可のとき' do
         before do
-          Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
         end
         it '実素材のサイズと違っても通る' do
           @pp.height = @p.height-1
@@ -239,7 +231,6 @@ describe PanelPicture do
       end
       context  '縦横比変更許可のとき' do
         before do
-          Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
         end
         it '実素材の縦横比と違っても通る' do
           @pp.height = @p.height / 2
@@ -296,6 +287,24 @@ describe PanelPicture do
         @pp.should_not be_valid
       end
     end
+    context 'picture_idを検証するとき' do
+      it 'テストデータの確認' do
+        @pp.picture_id = @p.id
+        @pp.should be_valid
+      end
+      it 'nullなら失敗する' do
+        @pp.picture_id = nil
+        @pp.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @pp.picture_id = 'a'
+        @pp.should_not be_valid
+      end
+      it '存在する実素材でなければ失敗する' do
+        @pp.picture_id = 0
+        @pp.should_not be_valid
+      end
+    end
   end
   describe '一覧取得に於いて' do
     before do