1 # -*- encoding: utf-8 -*-
5 describe OriginalPicture do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
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
21 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
24 context 'オーソドックスなデータのとき' do
26 @op.ext = 'png' #リストにない拡張子は通らないし
37 @op.filesize = 2000000
43 context 'extを検証するとき' do
46 @op.should_not be_valid
50 @op.should_not be_valid
52 it 'png,gif,jpeg以外なら失敗する' do
54 @op.should_not be_valid
57 context 'widthを検証するとき' do
60 @op.should_not be_valid
64 @op.should_not be_valid
68 @op.should_not be_valid
72 @op.should_not be_valid
75 context 'heightを検証するとき' do
78 @op.should_not be_valid
82 @op.should_not be_valid
86 @op.should_not be_valid
90 @op.should_not be_valid
93 context 'filesizeを検証するとき' do
96 @op.should_not be_valid
100 @op.should_not be_valid
104 @op.should_not be_valid
107 @op.filesize = 2000000+1
108 @op.should_not be_valid
111 context 'artist_idを検証するとき' do
114 @op.should_not be_valid
118 @op.should_not be_valid
120 it '存在する絵師でなければ失敗する' do
122 @op.should_not be_valid
125 context 'md5を検証するとき' do
128 @op.should_not be_valid
132 @op.should_not be_valid
136 @op.should_not be_valid
141 describe 'デフォルト値補充に於いて' do
143 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
148 describe '上書き補充に於いて' do
150 @op = FactoryGirl.build :original_picture, :artist_id => nil
151 @op.overwrite @artist
152 @op.artist_id.should eq @artist.id
156 describe '作者判定に於いて' do
158 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
160 context 'パラメータが作家のとき' do
162 @op.own?(@author).should == true
165 @op.own?(@other_author).should == false
168 context 'パラメータが絵師のとき' do
170 @op.own?(@artist).should == true
173 @op.own?(@other_artist).should == false
178 @op.own?(nil).should == false
183 describe '閲覧許可に於いて' do
185 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
187 it '検査対象が管理者のとき、許可を返す' do
188 OriginalPicture.any_instance.stub(:own?).and_return(false)
189 r = @op.visible?(@admin)
192 it '所持判定を問い合わせ、自分の原画なら許可する' do
193 OriginalPicture.any_instance.stub(:own?).and_return(true)
194 r = @op.visible?(@artist)
198 OriginalPicture.any_instance.stub(:own?).and_return(false)
199 r = @op.visible?(@artist)
204 describe 'ファイル名に於いて' do
206 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
208 it 'id+拡張子のフォーマットで返す' do
210 r.should eq "#{@op.id}.png"
214 describe 'MimeTypeに於いて' do
216 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
218 it 'image/拡張子のフォーマットで返す' do
220 r.should eq "image/png"
224 describe 'ファイルのurlに於いて' do
226 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
227 OriginalPicture.any_instance.stub(:filename).and_return('3.gif')
229 it 'ファイル名取得を依頼している' do
230 OriginalPicture.any_instance.should_receive(:filename).exactly(1)
233 it '/original_pictures/3.gifのフォーマットで返す' do
235 r.should eq "/original_pictures/3.gif"
239 describe 'サムネイル画像タグオプションに於いて' do
241 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
242 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
243 PettanImager.stub(:thumbnail_size).with(any_args).and_return([40, 30])
245 it 'サムネイル画像の幅高さ取得を依頼している' do
246 PettanImager.should_receive(:thumbnail_size).with(any_args).exactly(1)
250 r = @op.tmb_opt_img_tag
251 r.is_a?(Hash).should be_true
254 r = @op.tmb_opt_img_tag
255 r.has_key?(:src).should be_true
256 r[:src].should eq '/original_pictures/3.gif'
258 it 'widthキーを含んでいる' do
259 r = @op.tmb_opt_img_tag
260 r.has_key?(:width).should be_true
261 r[:width].should eq 40
263 it 'heightキーを含んでいる' do
264 r = @op.tmb_opt_img_tag
265 r.has_key?(:height).should be_true
266 r[:height].should eq 30
270 describe '画像タグオプションに於いて' do
272 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
273 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
277 r.is_a?(Hash).should be_true
281 r.has_key?(:src).should be_true
282 r[:src].should eq '/original_pictures/3.gif'
284 it 'widthキーを含んでいる' do
286 r.has_key?(:width).should be_true
287 r[:width].should eq @op.width
289 it 'heightキーを含んでいる' do
291 r.has_key?(:height).should be_true
292 r[:height].should eq @op.height
296 describe '未公開に於いて' do
298 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
300 context '実素材がゼロのとき' do
306 context '実素材がゼロではないとき' do
308 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
315 describe '停止中に於いて' do
317 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
319 context '未公開ではないが、素材がないとき' do
321 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
332 context '未公開ではなく、素材もあるとき' do
334 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
335 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
342 describe 'ライセンス待ちに於いて' do
344 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
346 context '未公開ではなく、素材もあるが、原画の更新日時が実素材のheadのそれより後のとき' do
348 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now - 1000
349 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
360 context '未公開ではないが、素材がないとき' do
362 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
367 context '未公開ではなく、素材もあり、実素材のheadの更新日時が原画のそれより後のとき' do
369 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now + 1000
370 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
377 describe '公開中に於いて' do
379 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
381 context '未公開ではなく、素材もあり、実素材のheadの更新日時が原画のそれより後のとき' do
383 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now + 1000
384 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
395 context '未公開ではないが、素材がないとき' do
397 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
402 context '未公開ではなく、素材もあるが、原画の更新日時が実素材のheadのそれより後のとき' do
404 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now - 1000
405 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
412 describe '一覧取得に於いて' do
414 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
416 context 'page補正について' do
417 it '文字列から数値に変換される' do
418 OriginalPicture.page('8').should eq 8
421 OriginalPicture.page().should eq 1
424 OriginalPicture.page('0').should eq 1
427 context 'page_size補正について' do
428 it '文字列から数値に変換される' do
429 OriginalPicture.page_size('7').should eq 7
431 it 'nilの場合はOriginalPicture.default_page_sizeになる' do
432 OriginalPicture.page_size().should eq OriginalPicture.default_page_size
434 it '0以下の場合はOriginalPicture.default_page_sizeになる' do
435 OriginalPicture.page_size('0').should eq OriginalPicture.default_page_size
437 it 'OriginalPicture.max_page_sizeを超えた場合はOriginalPicture.max_page_sizeになる' do
438 OriginalPicture.page_size('1000').should eq OriginalPicture.max_page_size
442 describe '一覧取得オプションに於いて' do
443 it 'includeキーを含んでいる' do
444 r = OriginalPicture.list_opt
445 r.has_key?(:include).should be_true
448 r = OriginalPicture.list_opt[:include]
449 r.should have(2).items
452 r = OriginalPicture.list_opt[:include]
453 r.has_key?(:resource_picture).should be_true
456 r = OriginalPicture.list_opt[:include]
457 r.has_key?(:pictures).should be_true
460 describe 'json一覧出力オプションに於いて' do
462 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
463 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
464 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
465 @sbt = FactoryGirl.create :speech_balloon_template
466 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
467 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
468 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
471 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
474 i.has_key?('resource_picture').should be_true
477 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
480 i.has_key?('pictures').should be_true
484 describe '自分の原画一覧取得に於いて' do
486 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
488 context 'つつがなく終わるとき' do
489 it '一覧取得オプションを利用している' do
490 OriginalPicture.stub(:list_opt).with(any_args).and_return({})
491 OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)
492 r = OriginalPicture.mylist @artist
496 r = OriginalPicture.mylist @artist
500 nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
501 r = OriginalPicture.mylist @artist
502 r.should eq [nc, @op]
505 nc = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
506 r = OriginalPicture.mylist @artist
509 context 'DBに5件あって1ページの件数を2件に変えたとして' do
511 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
512 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
513 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
514 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
517 r = OriginalPicture.mylist @artist, 1, 2
518 r.should have(2).items
520 it 'page=1なら末尾2件を返す' do
522 r = OriginalPicture.mylist @artist, 1, 2
523 r.should eq [@op5, @op4]
525 it 'page=2なら中間2件を返す' do
526 r = OriginalPicture.mylist @artist, 2, 2
527 r.should eq [@op3, @op2]
529 it 'page=3なら先頭1件を返す' do
530 r = OriginalPicture.mylist @artist, 3, 2
534 context 'DBに5件あって1ページの件数を0件に変えたとして' do
536 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
537 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
538 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
539 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
540 OriginalPicture.stub(:default_page_size).and_return(2)
543 r = OriginalPicture.mylist @artist, 5, 0
544 r.should have(5).items
549 describe '更新履歴一覧取得に於いて' do
551 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
552 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
553 :original_picture_id => @op.id
554 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
560 it '他の原画の実素材は含んでいない' do
561 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
562 :original_picture_id => @op2.id
566 it 'revisionで並んでいる' do
567 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
568 :original_picture_id => @op.id
570 r.should eq [@p2, @p]
574 describe '単体取得に於いて' do
576 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
578 context 'つつがなく終わるとき' do
579 it '単体取得オプションを利用している' do
580 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
581 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
582 r = OriginalPicture.show @op.id, @artist
584 it '閲覧許可を問い合わせている' do
585 OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
586 OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
587 r = OriginalPicture.show @op.id, @artist
591 pic = OriginalPicture.show @op.id, @artist
594 context '他人の原画を開こうとしたとき' do
595 it '403Forbidden例外を返す' do
596 OriginalPicture.any_instance.stub(:visible?).and_return(false)
598 pic = OriginalPicture.show @op.id, @other_artist
599 }.should raise_error(ActiveRecord::Forbidden)
602 context '存在しない原画を開こうとしたとき' do
603 it '404RecordNotFound例外を返す' do
605 pic = OriginalPicture.show 0, @artist
606 }.should raise_error(ActiveRecord::RecordNotFound)
610 describe '編集取得に於いて' do
612 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
614 context 'つつがなく終わるとき' do
615 it '単体取得オプションを利用している' do
616 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
617 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
618 r = OriginalPicture.edit @op.id, @artist
620 it '所持判定を問い合わせている' do
621 OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)
622 OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
623 r = OriginalPicture.edit @op.id, @artist
627 pic = OriginalPicture.edit @op.id, @artist
630 context '他人の原画を開こうとしたとき' do
631 it '403Forbidden例外を返す' do
632 OriginalPicture.any_instance.stub(:own?).and_return(false)
634 r = OriginalPicture.edit @op.id, @other_artist
635 }.should raise_error(ActiveRecord::Forbidden)
638 context '存在しない原画を開こうとしたとき' do
639 it '404RecordNotFound例外を返す' do
641 r = OriginalPicture.edit 0, @artist
642 }.should raise_error(ActiveRecord::RecordNotFound)
646 describe '単体取得オプションに於いて' do
647 it 'includeキーを含んでいる' do
648 r = OriginalPicture.show_opt
649 r.has_key?(:include).should be_true
652 r = OriginalPicture.show_opt[:include]
653 r.should have(2).items
656 r = OriginalPicture.show_opt[:include]
657 r.has_key?(:resource_picture).should be_true
660 r = OriginalPicture.show_opt[:include]
661 r.has_key?(:pictures).should be_true
664 describe 'json単体出力オプションに於いて' do
666 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
667 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
668 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
669 @sbt = FactoryGirl.create :speech_balloon_template
670 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
671 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
672 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
675 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
678 i.has_key?('resource_picture').should be_true
681 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
684 i.has_key?('pictures').should be_true
687 describe '作成・更新に於いて' do
689 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
690 @imager = ImagerTest.load "abc\ndef\nghi"
694 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
695 #それで外部のメソッド呼び出しだけに着目してテストする。
696 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
697 PictureIO.original_picture_io.stub(:put).with(any_args).and_return(true)
699 it '自身に属性をセットしている' do
700 OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
704 OriginalPicture.any_instance.should_receive(:save).exactly(1)
707 it 'PictureIoに画像データの保存を依頼している' do
708 PictureIO.original_picture_io.should_receive(:put).with(any_args).exactly(1)
712 context 'つつがなく終わるとき' do
715 it '自身に属性をセットしている' do
717 @op.width.should eq 3
718 @op.height.should eq 3
719 @op.filesize.should eq 9
721 it '原画モデルが作成されている' do
724 }.should change OriginalPicture, :count
728 OriginalPicture.find(@op).should_not be_nil
731 @op.store(@imager).should eq true
734 #以下から例外ケース。処理先頭から失敗させていく
735 context 'imagerが初期化に失敗したとき' do
739 @op.store(false).should be_false
741 it '自身の保存は呼ばれていない' do
742 OriginalPicture.any_instance.should_not_receive(:save)
745 it '全体エラーメッセージがセットされている' do
748 }.should change(@op.errors[:base], :count)
751 context '自身の保存に失敗したとき' do
753 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)
756 @op.store(@imager).should be_false
760 @op.should be_a_new OriginalPicture
762 it '原画の保存は呼ばれていない' do
763 PictureIO::LocalPicture.any_instance.should_not_receive(:put)
766 context '原画の保存に失敗したとき' do
768 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
769 PictureIO.original_picture_io.stub(:put).with(any_args).and_raise(PictureIO::Error)
772 @op.store(@imager).should be_false
776 @op.should be_a_new OriginalPicture
778 it '全体エラーメッセージがセットされている' do
781 }.should change(@op.errors[:base], :count)
788 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
790 context '事前チェックしておく' do
792 OriginalPicture.any_instance.stub(:destroy).and_return(true)
793 ResourcePicture.any_instance.stub(:unpublish).and_return(true)
794 Picture.any_instance.stub(:unpublish).with(any_args).and_return(true)
795 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
797 it '原画モデルに削除を依頼している' do
798 OriginalPicture.any_instance.should_receive(:destroy).exactly(1)
799 r = @op.destroy_with_resource_picture
801 it '保管庫に原画の画像データ削除を依頼している' do
802 PictureIO.original_picture_io.should_receive(:delete).with(@op.filename).exactly(1)
803 r = @op.destroy_with_resource_picture
805 context '自身にリンクされた素材があるとき' do
806 it '素材モデルに削除を依頼している' do
807 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
808 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
809 ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
810 r = @op.destroy_with_resource_picture
813 context '自身にリンクされた素材がないとき' do
814 it '素材モデルに削除を依頼しない' do
815 ResourcePicture.any_instance.should_not_receive(:unpublish)
816 r = @op.destroy_with_resource_picture
819 context '自身にリンクされた実素材があるとき' do
820 it 'すべての実素材に墨塗を依頼している' do
821 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
822 Picture.any_instance.should_receive(:unpublish).with(any_args).exactly(1)
823 r = @op.destroy_with_resource_picture
826 context '自身にリンクされた実素材がないとき' do
828 Picture.any_instance.should_not_receive(:unpublish)
829 r = @op.destroy_with_resource_picture
833 context 'つつがなく終わるとき' do
835 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
836 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
837 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
841 r = @op.destroy_with_resource_picture
842 }.should change(OriginalPicture, :count).by(-1)
844 r = OriginalPicture.find @op.id
848 r = @op.destroy_with_resource_picture
852 context '自身の削除に失敗したとき' do
854 OriginalPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
857 r = @op.destroy_with_resource_picture
862 r = @op.destroy_with_resource_picture
863 }.should_not change(OriginalPicture, :count)
866 context '画像の削除に失敗したとき' do
868 PictureIO.original_picture_io.stub(:delete).with(@op.filename).and_raise(PictureIO::Error)
871 r = @op.destroy_with_resource_picture
876 r = @op.destroy_with_resource_picture
877 }.should_not change(OriginalPicture, :count)
880 context '素材の削除に失敗とき' do
882 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
883 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
884 ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(false)
887 r = @op.destroy_with_resource_picture
892 r = @op.destroy_with_resource_picture
893 }.should_not change(OriginalPicture, :count)
895 r = @op.destroy_with_resource_picture
896 }.should_not change(ResourcePicture, :count)
899 context '実素材の墨塗に失敗とき' do
901 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
902 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
903 Picture.any_instance.stub(:unpublish).with(any_args).and_return(false)
906 r = @op.destroy_with_resource_picture
911 r = @op.destroy_with_resource_picture
912 }.should_not change(OriginalPicture, :count)
914 r = @op.destroy_with_resource_picture
915 }.should_not change(ResourcePicture, :count)
921 describe 'エクスポートに於いて' do
923 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
924 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
925 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
927 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
929 context 'つつがなく終わるとき' do
930 it 'ライセンスグループに依頼してリストを取得している' do
931 LicenseGroup.stub(:list).with(any_args).and_return([@lg])
932 LicenseGroup.should_receive(:list).with(any_args).exactly(1)
933 r = OriginalPicture.export(@artist)
935 it '原画に依頼してリストを取得している' do
936 OriginalPicture.stub(:list).with(any_args).and_return([@op])
937 OriginalPicture.should_receive(:list).with(any_args).exactly(1)
938 r = OriginalPicture.export(@artist)
941 r = OriginalPicture.export(@artist)
942 r.is_a?(Hash).should be_true
944 it 'Hashはライセンスグループを含んでいる' do
945 r = OriginalPicture.export(@artist)
946 r.include?(:license_groups).should be_true
948 it 'Hashは原画を含んでいる' do
949 r = OriginalPicture.export(@artist)
950 r.include?(:original_pictures).should be_true
952 #素材がライセンスされていないケースもある
953 it 'Hashの原画は素材を含んでいる' do
954 r = OriginalPicture.export(@artist)
955 r[:original_pictures].first.resource_picture.should_not be_nil
957 it 'Hashの原画は実素材を含んでいる' do
958 r = OriginalPicture.export(@artist)
959 r[:original_pictures].first.pictures.should be_nil
962 context '実データ単体のとき' do
963 it 'ライセンスは配列構造になっている' do
964 r = OriginalPicture.export(@artist)
965 r[:license_groups].is_a?(Array).should be_true
968 r = OriginalPicture.export(@artist)
969 r[:license_groups].size.should eq 1
970 r[:license_groups].first.should eq @lg
972 it '原画は配列構造になっている' do
973 r = OriginalPicture.export(@artist)
974 r[:original_pictures].is_a?(Array).should be_true
977 r = OriginalPicture.export(@artist)
978 r[:original_pictures].size.should eq 1
979 r[:original_pictures].first.should eq @op
981 it '原画に素材が関連付いている' do
982 r = OriginalPicture.export(@artist)
983 i = r[:original_pictures].first
984 i.resource_picture.should eq @rp
986 it '原画に実素材が関連付いている' do
987 r = OriginalPicture.export(@artist)
988 i = r[:original_pictures].first
989 i.picture.should eq @p
992 context '実データ複数のとき' do
994 @lg2 = FactoryGirl.create :license_group, :name => 'export test', :url => 'http://export.test/'
995 @license2 = FactoryGirl.create :license, :license_group_id => @lg2.id, :system_picture_id => @sp.id, :name => 'export test license', :url => 'http://export.test/license'
996 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
997 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license2.id, :revision => 0
998 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license2.id, :picture_id => @p2.id
1000 it 'ライセンスは配列構造になっている' do
1001 r = OriginalPicture.export(@artist)
1002 r[:license_groups].is_a?(Array).should be_true
1004 it 'ライセンスが全件出ている' do
1005 r = OriginalPicture.export(@artist)
1006 r[:license_groups].size.should eq 2
1007 r[:license_groups].first.should eq @lg
1008 r[:license_groups].last.should eq @lg2
1010 it '原画は配列構造になっている' do
1011 r = OriginalPicture.export(@artist)
1012 r[:original_pictures].is_a?(Array).should be_true
1015 r = OriginalPicture.export(@artist)
1016 r[:original_pictures].size.should eq 2
1017 r[:original_pictures].first.should eq @op
1018 r[:original_pictures].last.should eq @op2
1020 it '原画に素材が関連付いている' do
1021 r = OriginalPicture.export(@artist)
1022 i = r[:original_pictures].first
1023 i.resource_picture.should eq @rp
1024 i2 = r[:original_pictures].last
1025 i2.resource_picture.should eq @rp2
1027 it '原画に実素材が関連付いている' do
1028 r = OriginalPicture.export(@artist)
1029 i = r[:original_pictures].first
1030 i.picture.should eq @p
1031 i2 = r[:original_pictures].last
1032 i2.picture.should eq @p2
1037 describe 'エクスポートオプションに於いて' do
1040 describe 'インポートに於いて' do
1042 @imports = {:licenses => {}, :artist_id => @artist.id}
1044 context '事前チェックしておく' do