X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=spec%2Fmodels%2Fspeech_spec.rb;fp=spec%2Fmodels%2Fspeech_spec.rb;h=406b4aed6d4df643fdb09bcf804a3ff218c91941;hp=1f34f00c6bb67e547816d3b92ac38fcf62adb04f;hb=5860cb44b475e1dd24c2b0f87b74b516c97c33bf;hpb=2b2bb5b365e839906e7e411af3c9fc08ea6c4898 diff --git a/spec/models/speech_spec.rb b/spec/models/speech_spec.rb index 1f34f00c..406b4aed 100644 --- a/spec/models/speech_spec.rb +++ b/spec/models/speech_spec.rb @@ -7,156 +7,54 @@ describe Speech do @license = Factory :license @user = Factory( :user_yas) @author = @user.author - @artist = Factory :artist_yas, :author_id => @author.id - @other_user = Factory( :user_yas) - @other_author = @other_user.author - @other_artist = Factory :artist_yas, :author_id => @other_author.id + @panel = Factory :panel + @speech_balloon_template = Factory :speech_balloon_template + @speech_balloon = Factory :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id end describe '検証に於いて' do - before do - @st = Factory :speech_template - @comic = Factory :comic, :author_id => @author.id - @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id - @balloon = Factory :balloon, :panel_id => @panel.id, :t => 0 - @speech = Factory.build :speech, :balloon => @balloon.id, :t => 0 - end - it 'オーソドックスなデータなら通る' do + @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id @speech.should be_valid - end + end - context 'balloon_idを検証するとき' do + context 'speech_balloon_idを検証するとき' do before do + @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id end it 'テストデータの確認' do - @speech.comic_id = @comic.id + @speech.speech_balloon_id = @speech_balloon.id @speech.should be_valid end it 'nullなら失敗する' do - @speech.comic_id = nil - @speech.should_not be_valid - end - it '数値でなければ失敗する' do - @speech.comic_id = 'a' - @speech.should_not be_valid - end - it '存在するコミックでなければ失敗する' do - @speech.comic_id = 0 + @speech.speech_balloon_id = nil @speech.should_not be_valid end - it 'コミックidとtが重複していると失敗する' do - @speech.save - @speech2 = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - @speech2.should_not be_valid - end - end - context 'resource_picture_idを検証するとき' do - before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @speech.resource_picture_id = 1 - @speech.should be_valid - end - it 'nullなら通る' do - @speech.resource_picture_id = nil - @speech.should be_valid - end it '数値でなければ失敗する' do - @speech.resource_picture_id = 'a' + @speech.speech_balloon_id = 'a' @speech.should_not be_valid end - it '存在する素材でなければ失敗する' do - @speech.resource_picture_id = 0 + it '存在するフキダシコミックでなければ失敗する' do + @speech.speech_balloon_id = 0 @speech.should_not be_valid end end - context 'widthを検証するとき' do - before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @speech.width = 1 - @speech.should be_valid - end - it 'nullなら失敗する' do - @speech.width = nil - @speech.should_not be_valid - end - it '数値でなければ失敗する' do - @speech.width = 'a' - @speech.should_not be_valid - end - it '0なら失敗する' do - @speech.width = '0' - @speech.should_not be_valid - end - it '負でも失敗する' do - @speech.width = -1 - @speech.should_not be_valid - end + context 'contentを検証するとき' do end - context 'heightを検証するとき' do - before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @speech.height = '1' - @speech.should be_valid - end - it 'nullなら失敗する' do - @speech.height = nil - @speech.should_not be_valid - end - it '数値でなければ失敗する' do - @speech.height = 'a' - @speech.should_not be_valid - end - it '0なら失敗する' do - @speech.height = '0' - @speech.should_not be_valid - end - it '負でも失敗する' do - @speech.height = -1 - @speech.should_not be_valid - end - end - context 'borderを検証するとき' do + context 'xを検証するとき' do before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id end it 'テストデータの確認' do - @speech.border = '1' + @speech.x = '1' @speech.should be_valid end it 'nullなら失敗する' do - @speech.border = nil + @speech.x = nil @speech.should_not be_valid end it '数値でなければ失敗する' do - @speech.border = 'a' - @speech.should_not be_valid - end - it '負なら失敗する' do - @speech.border = '-1' - @speech.should_not be_valid - end - it '0なら通る' do - @speech.border = 0 - @speech.should be_valid - end - end - context 'xを検証するとき' do - before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @speech.x = '1' - @speech.should be_valid - end - it '数値でなければ失敗する' do @speech.x = 'a' @speech.should_not be_valid end @@ -171,12 +69,16 @@ describe Speech do end context 'yを検証するとき' do before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id end it 'テストデータの確認' do @speech.y = '1' @speech.should be_valid end + it 'nullなら失敗する' do + @speech.y = nil + @speech.should_not be_valid + end it '数値でなければ失敗する' do @speech.y = 'a' @speech.should_not be_valid @@ -190,73 +92,64 @@ describe Speech do @speech.should be_valid end end - context 'zを検証するとき' do + context 'widthを検証するとき' do before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id end it 'テストデータの確認' do - @speech.z = '1' + @speech.width = 1 @speech.should be_valid end + it 'nullなら失敗する' do + @speech.width = nil + @speech.should_not be_valid + end it '数値でなければ失敗する' do - @speech.z = 'a' + @speech.width = 'a' @speech.should_not be_valid end it '0なら失敗する' do - @speech.z = '0' + @speech.width = '0' @speech.should_not be_valid end - it '負なら失敗する' do - @speech.z = -1 + it '負でも失敗する' do + @speech.width = -1 @speech.should_not be_valid end end - context 'tを検証するとき' do + context 'heightを検証するとき' do before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id end it 'テストデータの確認' do - @speech.t = '1' + @speech.height = '1' @speech.should be_valid end + it 'nullなら失敗する' do + @speech.height = nil + @speech.should_not be_valid + end it '数値でなければ失敗する' do - @speech.t = 'a' + @speech.height = 'a' @speech.should_not be_valid end - it '0なら通る' do - @speech.t = '0' - @speech.should be_valid + it '0なら失敗する' do + @speech.height = '0' + @speech.should_not be_valid end it '負でも失敗する' do - @speech.t = -1 + @speech.height = -1 @speech.should_not be_valid end end - context 'author_idを検証するとき' do + context 'settingsを検証するとき' do before do - @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + @speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id end it 'テストデータの確認' do - @speech.author_id = @author.id + @speech.settings = '' @speech.should be_valid end - it 'nullなら失敗する' do - @speech.author_id = nil - @speech.should_not be_valid - end - it '数値でなければ失敗する' do - @speech.author_id = 'a' - @speech.should_not be_valid - end - it '存在する絵師でなければ失敗する' do - @speech.author_id = 0 - @speech.should_not be_valid - end - end - context '全体を検証するとき' do - before do - @speech = Factory :panel, :author_id => @author.id, :comic_id => @comic.id - end end end