1 # -*- encoding: utf-8 -*-
7 FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = @other_user.author
13 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
14 @sp = FactoryGirl.create :system_picture
15 @lg = FactoryGirl.create :license_group
16 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
17 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
24 it 'オーソドックスなデータなら通る' do
25 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
29 context 'original_picture_idを検証するとき' do
31 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
34 @p.original_picture_id = @op.id
38 @p.original_picture_id = nil
39 @p.should_not be_valid
42 @p.original_picture_id = 'a'
43 @p.should_not be_valid
45 it '存在する原画でなければ失敗する' do
46 @p.original_picture_id = 0
47 @p.should_not be_valid
50 context 'revisionを検証するとき' do
52 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
60 @p.should_not be_valid
64 @p.should_not be_valid
67 context 'extを検証するとき' do
69 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
77 @p.should_not be_valid
81 @p.should_not be_valid
83 it 'png,gif,jpeg以外なら失敗する' do
85 @p.should_not be_valid
88 context 'widthを検証するとき' do
90 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
98 @p.should_not be_valid
102 @p.should_not be_valid
106 @p.should_not be_valid
110 @p.should_not be_valid
113 context 'heightを検証するとき' do
115 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
123 @p.should_not be_valid
127 @p.should_not be_valid
131 @p.should_not be_valid
135 @p.should_not be_valid
138 context 'filesizeを検証するとき' do
140 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
148 @p.should_not be_valid
152 @p.should_not be_valid
156 @p.should_not be_valid
159 @p.filesize = 2000000+1
160 @p.should_not be_valid
163 context 'artist_idを検証するとき' do
165 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
168 @p.artist_id = @artist.id
173 @p.should_not be_valid
177 @p.should_not be_valid
179 it '存在する絵師でなければ失敗する' do
181 @p.should_not be_valid
184 context 'license_idを検証するとき' do
186 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
189 @p.license_id = @license.id
194 @p.should_not be_valid
198 @p.should_not be_valid
200 it '存在するライセンスグループでなければ失敗する' do
202 @p.should_not be_valid
205 context 'artist_nameを検証するとき' do
207 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
215 @p.should_not be_valid
218 context 'classnameを検証するとき' do
220 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
223 @p.classname = 'a'*50
228 @p.should_not be_valid
231 @p.classname = 'a'*51
232 @p.should_not be_valid
235 context 'creditを検証するとき' do
237 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
244 context 'settingsを検証するとき' do
246 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
256 describe '最新Revision取得に於いて' do
257 context '初めての原画を公開したとき' do
259 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
261 it 'Revisionは1となる' do
262 @p.new_revision.should eq 1
265 context 'HEADが1のとき' do
267 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
268 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
270 it 'Revisionは2となる' do
271 @p.new_revision.should eq 2
274 context 'HEADが5のとき' do
276 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
277 FactoryGirl.create :picture, :revision => 5, :original_picture_id => @op.id, :license_id => @license.id
278 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
280 it 'Revisionは6となる' do
281 @p.new_revision.should eq 6
285 describe '素材からのコピーデータセットに於いて' do
287 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
288 attr = {:ext => 'jpeg', :width => 264, :height => 265, :filesize => 266,
289 :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id,
290 :artist_name => 'tester', :classname => 'Tester', :credit => {:title => 'cap'}.to_json.to_s, :settings => {:set => 1}.to_json.to_s}
291 @rp = FactoryGirl.build :resource_picture, attr
292 @p = FactoryGirl.build :picture
294 it '素材オブジェクトから属性を取り出して対象実素材にセットしている' do
295 res = @p.copy_data(@rp)
296 @p.ext.should eq 'jpeg'
297 @p.width.should eq 264
298 @p.height.should eq 265
299 @p.filesize.should eq 266
300 @p.artist_id.should eq @artist.id
301 @p.license_id.should eq @license.id
302 @p.original_picture_id.should eq @op.id
303 @p.artist_name.should eq 'tester'
304 @p.classname.should eq 'Tester'
305 @p.credit.should match /title/
306 @p.settings.should match /set/
313 class Mgk ; class Image ; end ; end
315 Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
316 Mgk.any_instance.stub(:format).with(any_args).and_return('png')
317 Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
318 Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
319 Mgk.any_instance.stub(:filesize).with(any_args).and_return(@filesize)
320 Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
321 #原画ファイル削除だけは必ず成功するものとしておく
322 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
326 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
327 #それで外部のメソッド呼び出しだけに着目してテストする。
328 Picture.any_instance.stub(:save).with(any_args).and_return(true)
329 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
330 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
331 class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために
332 @gifmgk = GifMgk.new #パラメータを二種類用意する。
333 Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
334 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
336 it '最新Revisionを取得している' do
337 Picture.any_instance.should_receive(:new_revision).with(any_args).exactly(1)
338 res = @p.store(Mgk.new)
341 Picture.any_instance.should_receive(:save).with(any_args).exactly(1)
342 res = @p.store(Mgk.new)
344 it '画像ファイルの作成機能で画像を保存している' do
345 mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
346 Picture.any_instance.should_receive(:store_picture).with(mgk).exactly(1)
349 it '自身にgifフォーマット変換対象かを問い合わせている' do
350 Picture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
351 res = @p.store(Mgk.new)
353 it '自身にGifフォーマット変換を依頼している' do
354 Picture.should_receive(:png_to_gif).with(any_args).exactly(1)
355 res = @p.store(Mgk.new)
357 it '画像ファイルの作成機能でgif画像を保存している' do
359 Picture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
360 res = @p.store(Mgk.new)
363 context 'つつがなく終わるとき' do
365 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
366 # Picture.any_instance.stub(:save).with(any_args).and_return(true)
367 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
368 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
369 class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために
370 @gifmgk = GifMgk.new #パラメータを二種類用意する。
371 Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
372 @p = FactoryGirl.build :picture, :revision => nil, :original_picture_id => @op.id, :license_id => @license.id
375 res = @p.store(Mgk.new)
378 it 'Revisionに最新Revisionセット' do
379 res = @p.store(Mgk.new)
380 @p.revision.should eq 1
384 res = @p.store(Mgk.new)
385 }.should change Picture, :count
388 context 'gif変換なしで、つつがなく終わるとき' do
390 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
391 Picture.any_instance.stub(:save).with(any_args).and_return(true)
392 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
393 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(false)
394 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
397 res = @p.store(Mgk.new)
400 it 'gif保存は呼ばれていない' do
401 #二回目の画像作成が呼び出されないで1回こっきりならgif保存は呼ばれていないんだろう。
402 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
403 res = @p.store(Mgk.new)
406 #以下から例外ケース。処理先頭から失敗させていく
407 context '自身の保存に失敗したとき' do
409 Picture.any_instance.stub(:save).with(any_args).and_return(false)
410 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
413 res = @p.store(Mgk.new)
418 @p.should be_a_new Picture
421 context '画像の保存に失敗したとき' do
423 Picture.any_instance.stub(:save).with(any_args).and_return(true)
424 Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)
425 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
428 res = @p.store(Mgk.new)
431 it 'gif変換判定は呼ばれていない' do
432 Picture.any_instance.should_not_receive(:to_gif?).with(any_args)
433 res = @p.store(Mgk.new)
436 context 'gif変換に失敗したとき' do
438 Picture.any_instance.stub(:save).with(any_args).and_return(true)
439 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
440 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
441 Picture.stub(:png_to_gif).with(any_args).and_return(false)
442 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
445 res = @p.store(Mgk.new)
448 it 'gif画像の保存は呼ばれていない' do
450 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
451 res = @p.store(Mgk.new)
454 context 'gif画像の保存に失敗したとき' do
457 Picture.any_instance.stub(:save).with(any_args).and_return(true)
458 Picture.any_instance.stub(:store_picture).with(@mgk).and_return(true)
459 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
460 class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために
461 @gifmgk = GifMgk.new #パラメータを二種類用意する。
462 Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
463 Picture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)
464 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
473 describe '反転画像の保存先に於いて' do
475 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
478 it 'ベースディレクトリだけを返す' do
479 Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(-1)
481 r.should have(1).item
483 it 'ベースディレクトリだけを返す' do
484 Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(-1)
490 it 'ベースディレクトリと反転3種を返す' do
491 Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(1)
493 r.should have(4).item
495 it 'ベースディレクトリと反転3種を返す' do
496 Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(1)
498 r.last.should eq 'vh'
503 describe '画像ファイルの作成に於いて' do
504 #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。
507 class Mgk ; class Image ; end ; end
509 Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
510 Mgk.any_instance.stub(:format).with(any_args).and_return('png')
511 Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
512 Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
513 Mgk.any_instance.stub(:filesize).with(any_args).and_return(@filesize)
514 Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
515 #原画ファイル削除だけは必ず成功するものとしておく
516 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
518 Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])
519 Picture.any_instance.stub(:h).with(any_args).and_return('data')
520 Picture.any_instance.stub(:v).with(any_args).and_return('data')
521 Picture.any_instance.stub(:vh).with(any_args).and_return('data')
522 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
526 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
527 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
529 it '画像ファイルの保存が4回呼ばれる' do
530 PictureIO.picture_io.should_receive(:put).with(any_args).exactly(4)
531 res = @p.store_picture(Mgk.new)
533 it '画像ファイルのベースへの保存が1回呼ばれる' do
534 PictureIO.picture_io.should_receive(:put).with('data', @p.filename, '').exactly(1)
535 res = @p.store_picture(Mgk.new)
537 it '画像ファイルの垂直反転への保存が1回呼ばれる' do
538 PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'v').exactly(1)
539 res = @p.store_picture(Mgk.new)
541 it '画像ファイルの水平反転への保存が1回呼ばれる' do
542 PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'h').exactly(1)
543 res = @p.store_picture(Mgk.new)
545 it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do
546 PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'vh').exactly(1)
547 res = @p.store_picture(Mgk.new)
550 Picture.any_instance.should_receive(:v).with(any_args).exactly(1)
551 res = @p.store_picture(Mgk.new)
554 Picture.any_instance.should_receive(:h).with(any_args).exactly(1)
555 res = @p.store_picture(Mgk.new)
557 it '垂直水平反転が1回呼ばれる' do
558 Picture.any_instance.should_receive(:vh).with(any_args).exactly(1)
559 res = @p.store_picture(Mgk.new)
562 context 'つつがなく終わるとき' do
564 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
565 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
568 res = @p.store_picture(Mgk.new)
574 PictureIO.picture_io.stub(:put).with(any_args).and_return(false)
577 res = @p.store_picture(Mgk.new)
584 describe 'フラグ展開に於いて' do
586 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id,
587 :settings => "{\"open\": 1, \"commercial\": 2, \"official\": 3, \"attribution\": 4, \"derive\": 5, \"thumbnail\": 6, \"gif_convert\": 7, \"reverse\": 8, \"resize\": 9, \"sync_vh\": 10, \"overlap\": 11}"
589 context 'json展開チェック' do
590 it '展開してなければ展開して@flagsに保管する' do
591 @p.flags.should_not be_nil
595 @p.flags.is_a?(Hash).should be_true
596 @p.flags.empty?.should be_true
599 context 'openについて' do
600 it '@flag_openに保管する' do
601 @p.flag_open.should_not be_nil
603 it '本当にフラグHashからじゃなく、変数から取得してる?' do
606 @p.flag_open.should_not be_nil
609 @p.flag_open.should eq 1
612 context 'commercialについて' do
613 it '@flag_commercialに保管する' do
614 @p.flag_commercial.should_not be_nil
616 it '本当にフラグHashからじゃなく、変数から取得してる?' do
619 @p.flag_commercial.should_not be_nil
622 @p.flag_commercial.should eq 2
625 context 'officialについて' do
626 it '@flag_officialに保管する' do
627 @p.flag_official.should_not be_nil
629 it '本当にフラグHashからじゃなく、変数から取得してる?' do
632 @p.flag_official.should_not be_nil
635 @p.flag_official.should eq 3
638 context 'attributionについて' do
639 it '@flag_attributionに保管する' do
640 @p.flag_attribution.should_not be_nil
642 it '本当にフラグHashからじゃなく、変数から取得してる?' do
645 @p.flag_attribution.should_not be_nil
648 @p.flag_attribution.should eq 4
651 context 'deriveについて' do
652 it '@flag_deriveに保管する' do
653 @p.flag_derive.should_not be_nil
655 it '本当にフラグHashからじゃなく、変数から取得してる?' do
658 @p.flag_derive.should_not be_nil
661 @p.flag_derive.should eq 5
664 context 'thumbnailについて' do
665 it '@flag_thumbnailに保管する' do
666 @p.flag_thumbnail.should_not be_nil
668 it '本当にフラグHashからじゃなく、変数から取得してる?' do
671 @p.flag_thumbnail.should_not be_nil
674 @p.flag_thumbnail.should eq 6
677 context 'gif_convertについて' do
678 it '@flag_gif_convertに保管する' do
679 @p.flag_gif_convert.should_not be_nil
681 it '本当にフラグHashからじゃなく、変数から取得してる?' do
684 @p.flag_gif_convert.should_not be_nil
687 @p.flag_gif_convert.should eq 7
690 context 'reverseについて' do
691 it '@flag_reverseに保管する' do
692 @p.flag_reverse.should_not be_nil
694 it '本当にフラグHashからじゃなく、変数から取得してる?' do
697 @p.flag_reverse.should_not be_nil
700 @p.flag_reverse.should eq 8
703 context 'resizeについて' do
704 it '@flag_resizeに保管する' do
705 @p.flag_resize.should_not be_nil
707 it '本当にフラグHashからじゃなく、変数から取得してる?' do
710 @p.flag_resize.should_not be_nil
713 @p.flag_resize.should eq 9
716 context 'sync_vhについて' do
717 it '@flag_sync_vhに保管する' do
718 @p.flag_sync_vh.should_not be_nil
720 it '本当にフラグHashからじゃなく、変数から取得してる?' do
723 @p.flag_sync_vh.should_not be_nil
726 @p.flag_sync_vh.should eq 10
729 context 'overlapについて' do
730 it '@flag_overlapに保管する' do
731 @p.flag_overlap.should_not be_nil
733 it '本当にフラグHashからじゃなく、変数から取得してる?' do
736 @p.flag_overlap.should_not be_nil
739 @p.flag_overlap.should eq 11
744 describe 'クレジットデータに於いて' do
746 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
747 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :credit => '{"system_picture_id": 2}'
749 it 'system_picture_idが入っている' do
751 res["system_picture_id"].should eq 2