OSDN Git Service

test update
[pettanr/pettanr.git] / spec / models / balloon_spec.rb
index a9c7e3b..ca5cd86 100644 (file)
@@ -1,5 +1,262 @@
+# -*- encoding: utf-8 -*-\r
 require 'spec_helper'
 
 describe Balloon do
-  pending "add some examples to (or delete) #{__FILE__}"
+  before do
+    Factory :admin
+    @license = Factory :license
+    @user = Factory( :user_yas)
+    @author = @user.author
+    @artist = Factory :artist_yas, :author_id => @author.id\r
+    @other_user = Factory( :user_yas)
+    @other_author = @other_user.author
+    @other_artist = Factory :artist_yas, :author_id => @other_author.id
+    
+  end\r
+  
+  describe '検証に於いて' do
+    before do\r
+      @comic = Factory :comic, :author_id => @author.id
+    end
+    
+    it 'オーソドックスなデータなら通る' do
+      @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+#      @panel.should be_valid
+      @panel.save!
+    end
+    
+    context 'comic_idを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => nil
+      end
+      it 'テストデータの確認' do
+        @panel.comic_id = @comic.id
+        @panel.should be_valid
+      end
+      it 'nullなら失敗する' do
+        @panel.comic_id = nil
+        @panel.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.comic_id = 'a'
+        @panel.should_not be_valid
+      end
+      it '存在するコミックでなければ失敗する' do
+        @panel.comic_id = 0
+        @panel.should_not be_valid
+      end
+    end
+    context 'resource_picture_idを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.resource_picture_id = 1
+        @panel.should be_valid
+      end
+      it 'nullなら通る' do
+        @panel.resource_picture_id = nil
+        @panel.should be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.resource_picture_id = 'a'
+        @panel.should_not be_valid
+      end
+      it '存在する素材でなければ失敗する' do
+        @panel.resource_picture_id = 0
+        @panel.should_not be_valid
+      end
+    end
+    context 'widthを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.width = 1
+        @panel.should be_valid
+      end
+      it 'nullなら失敗する' do
+        @panel.width = nil
+        @panel.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.width = 'a'
+        @panel.should_not be_valid
+      end
+      it '0なら失敗する' do
+        @panel.width = '0'
+        @panel.should_not be_valid
+      end
+      it '負でも失敗する' do
+        @panel.width = -1
+        @panel.should_not be_valid
+      end
+    end
+    context 'heightを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.height = '1'
+        @panel.should be_valid
+      end
+      it 'nullなら失敗する' do
+        @panel.height = nil
+        @panel.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.height = 'a'
+        @panel.should_not be_valid
+      end
+      it '0なら失敗する' do
+        @panel.height = '0'
+        @panel.should_not be_valid
+      end
+      it '負でも失敗する' do
+        @panel.height = -1
+        @panel.should_not be_valid
+      end
+    end
+    context 'borderを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.border = '1'
+        @panel.should be_valid
+      end
+      it 'nullなら失敗する' do
+        @panel.border = nil
+        @panel.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.border = 'a'
+        @panel.should_not be_valid
+      end
+      it '負なら失敗する' do
+        @panel.border = '-1'
+        @panel.should_not be_valid
+      end
+      it '0なら通る' do
+        @panel.border = 0
+        @panel.should be_valid
+      end
+    end
+    context 'xを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.x = '1'
+        @panel.should be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.x = 'a'
+        @panel.should_not be_valid
+      end
+      it '0なら通る' do
+        @panel.x = '0'
+        @panel.should be_valid
+      end
+      it '負でも通る' do
+        @panel.x = -1
+        @panel.should be_valid
+      end
+    end
+    context 'yを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.y = '1'
+        @panel.should be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.y = 'a'
+        @panel.should_not be_valid
+      end
+      it '0なら通る' do
+        @panel.y = '0'
+        @panel.should be_valid
+      end
+      it '負でも通る' do
+        @panel.y = -1
+        @panel.should be_valid
+      end
+    end
+    context 'zを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.z = '1'
+        @panel.should be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.z = 'a'
+        @panel.should_not be_valid
+      end
+      it '0なら失敗する' do
+        @panel.z = '0'
+        @panel.should_not be_valid
+      end
+      it '負なら失敗する' do
+        @panel.z = -1
+        @panel.should_not be_valid
+      end
+    end
+    context 'tを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.t = '1'
+        @panel.should be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.t = 'a'
+        @panel.should_not be_valid
+      end
+      it '0なら通る' do
+        @panel.t = '0'
+        @panel.should be_valid
+      end
+      it '負でも失敗する' do
+        @panel.t = -1
+        @panel.should_not be_valid
+      end
+    end
+    context 'author_idを検証するとき' do
+      before do
+        @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'テストデータの確認' do
+        @panel.author_id = @author.id
+        @panel.should be_valid
+      end
+      it 'nullなら失敗する' do
+        @panel.author_id = nil
+        @panel.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @panel.author_id = 'a'
+        @panel.should_not be_valid
+      end
+      it '存在する絵師でなければ失敗する' do
+        @panel.author_id = 0
+        @panel.should_not be_valid
+      end
+    end
+    context '全体を検証するとき' do
+      before do
+        @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
+      end
+      it 'コミックidとtが重複していると失敗する' do
+        @panel2 = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
+        @panel2.save\r
+        @panel2.should_not be_valid
+      end
+    end
+  end
+  
 end