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, :uploaded_at => nil
151 @op.overwrite @artist
152 @op.uploaded_at.should_not be_nil
155 @op = FactoryGirl.build :original_picture, :artist_id => nil
156 @op.overwrite @artist
157 @op.artist_id.should eq @artist.id
161 describe '所持判定に於いて' do
163 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
165 context '事前チェックする' do
166 it '自身にロールリストからの絵師取得を依頼している' do
167 OriginalPicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)
168 r = @op.own?([@artist])
171 context 'ロール内絵師が取得できるとき' do
174 it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do
175 OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)
176 r = @op.own?([@artist])
179 it 'ロール内絵師のidが自身の絵師idと一致しないならno' do
180 OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)
181 @op.own?(@other_artist).should be_false
184 context 'ロール内絵師が取得できないとき' do
186 OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)
189 r = @op.own?([@artist])
195 describe '閲覧許可に於いて' do
197 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
199 context '事前チェックする' do
201 MagicNumber['run_mode'] = 1
203 it '自身の原画に所持判定を問い合わせしている' do
204 OriginalPicture.any_instance.stub(:own?).and_return(true)
205 OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
206 r = @op.visible?([@artist])
209 context 'つつがなく終わるとき' do
211 MagicNumber['run_mode'] = 1
214 OriginalPicture.any_instance.stub(:own?).and_return(true)
215 r = @op.visible?([@artist])
219 OriginalPicture.any_instance.stub(:own?).and_return(false)
220 r = @op.visible?([@artist])
226 describe 'ファイル名に於いて' do
228 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
230 it 'id+拡張子のフォーマットで返す' do
232 r.should eq "#{@op.id}.png"
236 describe 'MimeTypeに於いて' do
238 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
240 it 'image/拡張子のフォーマットで返す' do
242 r.should eq "image/png"
246 describe 'ファイルのurlに於いて' do
248 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
249 OriginalPicture.any_instance.stub(:filename).and_return('3.gif')
251 it 'ファイル名取得を依頼している' do
252 OriginalPicture.any_instance.should_receive(:filename).exactly(1)
255 it '/original_pictures/3.gifのフォーマットで返す' do
257 r.should eq "/original_pictures/3.gif"
261 describe 'サムネイル画像タグオプションに於いて' do
263 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
264 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
265 PettanImager.stub(:thumbnail_size).with(any_args).and_return([40, 30])
267 it 'サムネイル画像の幅高さ取得を依頼している' do
268 PettanImager.should_receive(:thumbnail_size).with(any_args).exactly(1)
272 r = @op.tmb_opt_img_tag
273 r.is_a?(Hash).should be_true
276 r = @op.tmb_opt_img_tag
277 r.has_key?(:src).should be_true
278 r[:src].should eq '/original_pictures/3.gif'
280 it 'widthキーを含んでいる' do
281 r = @op.tmb_opt_img_tag
282 r.has_key?(:width).should be_true
283 r[:width].should eq 40
285 it 'heightキーを含んでいる' do
286 r = @op.tmb_opt_img_tag
287 r.has_key?(:height).should be_true
288 r[:height].should eq 30
292 describe '画像タグオプションに於いて' do
294 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
295 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
299 r.is_a?(Hash).should be_true
303 r.has_key?(:src).should be_true
304 r[:src].should eq '/original_pictures/3.gif'
306 it 'widthキーを含んでいる' do
308 r.has_key?(:width).should be_true
309 r[:width].should eq @op.width
311 it 'heightキーを含んでいる' do
313 r.has_key?(:height).should be_true
314 r[:height].should eq @op.height
318 describe '未公開に於いて' do
320 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
322 context '公開日時と停止日時がともに空のとき' do
328 context '公開日時と停止日時がともに空ではないとき' do
330 @op.stopped_at =Time.now
335 @op.published_at =Time.now
342 describe '停止中に於いて' do
344 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
346 context '停止日時が空でないとき' do
348 @op.stopped_at =Time.now
353 context '停止日時が空のとき' do
362 describe 'ライセンス待ちに於いて' do
364 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
366 context '公開日時と停止日時のうち、空でない方を取得して、投稿日時がそれより後のとき' do
368 @op.uploaded_at = Time.now
369 @op.stopped_at = Time.now - 400
374 @op.uploaded_at = Time.now
375 @op.published_at =Time.now - 400
380 context '公開日時と停止日時のうち、空でない方を取得して、投稿日時がそれより後ではないとき' do
382 @op.published_at = nil
388 @op.uploaded_at = Time.now
389 @op.published_at =Time.now + 400
394 @op.uploaded_at = Time.now
395 @op.stopped_at =Time.now + 400
402 describe '公開中に於いて' do
404 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
406 context '公開日時が空ではないとき' do
408 @op.published_at =Time.now
413 context '公開日時が空のとき' do
415 @op.published_at = nil
422 describe '一覧取得に於いて' do
424 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
426 context 'page補正について' do
427 it '文字列から数値に変換される' do
428 OriginalPicture.page('8').should eq 8
431 OriginalPicture.page().should eq 1
434 OriginalPicture.page('0').should eq 1
437 context 'page_size補正について' do
438 it '文字列から数値に変換される' do
439 OriginalPicture.page_size('7').should eq 7
441 it 'nilの場合はOriginalPicture.default_page_sizeになる' do
442 OriginalPicture.page_size().should eq OriginalPicture.default_page_size
444 it '0以下の場合はOriginalPicture.default_page_sizeになる' do
445 OriginalPicture.page_size('0').should eq OriginalPicture.default_page_size
447 it 'OriginalPicture.max_page_sizeを超えた場合はOriginalPicture.max_page_sizeになる' do
448 OriginalPicture.page_size('1000').should eq OriginalPicture.max_page_size
452 describe '一覧取得オプションに於いて' do
453 it 'includeキーを含んでいる' do
454 r = OriginalPicture.list_opt
455 r.has_key?(:include).should be_true
458 r = OriginalPicture.list_opt[:include]
459 r.should have(2).items
462 r = OriginalPicture.list_opt[:include]
463 r.has_key?(:resource_picture).should be_true
466 r = OriginalPicture.list_opt[:include]
467 r.has_key?(:pictures).should be_true
470 describe 'json一覧出力オプションに於いて' do
472 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
473 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
474 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
475 @sbt = FactoryGirl.create :speech_balloon_template
476 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
477 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
478 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
481 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
484 i.has_key?('resource_picture').should be_true
487 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
490 i.has_key?('pictures').should be_true
494 describe '自分の原画一覧取得に於いて' do
496 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
498 context 'つつがなく終わるとき' do
499 it '一覧取得オプションを利用している' do
500 OriginalPicture.stub(:list_opt).with(any_args).and_return({})
501 OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)
502 r = OriginalPicture.mylist @artist
506 r = OriginalPicture.mylist @artist
510 nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
511 r = OriginalPicture.mylist @artist
512 r.should eq [nc, @op]
515 nc = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
516 r = OriginalPicture.mylist @artist
519 context 'DBに5件あって1ページの件数を2件に変えたとして' do
521 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
522 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
523 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
524 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
527 r = OriginalPicture.mylist @artist, 1, 2
528 r.should have(2).items
530 it 'page=1なら末尾2件を返す' do
532 r = OriginalPicture.mylist @artist, 1, 2
533 r.should eq [@op5, @op4]
535 it 'page=2なら中間2件を返す' do
536 r = OriginalPicture.mylist @artist, 2, 2
537 r.should eq [@op3, @op2]
539 it 'page=3なら先頭1件を返す' do
540 r = OriginalPicture.mylist @artist, 3, 2
544 context 'DBに5件あって1ページの件数を0件に変えたとして' do
546 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
547 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
548 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
549 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
550 OriginalPicture.stub(:default_page_size).and_return(2)
553 r = OriginalPicture.mylist @artist, 5, 0
554 r.should have(5).items
559 describe '更新履歴一覧取得に於いて' do
561 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
562 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
563 :original_picture_id => @op.id
564 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
570 it '他の原画の実素材は含んでいない' do
571 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
572 :original_picture_id => @op2.id
576 it 'revisionで並んでいる' do
577 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
578 :original_picture_id => @op.id
580 r.should eq [@p2, @p]
584 describe '単体取得に於いて' do
586 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
588 context 'つつがなく終わるとき' do
589 it '単体取得オプションを利用している' do
590 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
591 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
592 r = OriginalPicture.show @op.id, @artist
594 it '閲覧許可を問い合わせている' do
595 OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
596 OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
597 r = OriginalPicture.show @op.id, @artist
601 pic = OriginalPicture.show @op.id, @artist
604 context '他人の原画を開こうとしたとき' do
605 it '403Forbidden例外を返す' do
606 OriginalPicture.any_instance.stub(:visible?).and_return(false)
608 pic = OriginalPicture.show @op.id, @other_artist
609 }.should raise_error(ActiveRecord::Forbidden)
612 context '存在しない原画を開こうとしたとき' do
613 it '404RecordNotFound例外を返す' do
615 pic = OriginalPicture.show 0, @artist
616 }.should raise_error(ActiveRecord::RecordNotFound)
620 describe '編集取得に於いて' do
622 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
624 context 'つつがなく終わるとき' do
625 it '単体取得オプションを利用している' do
626 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
627 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
628 r = OriginalPicture.edit @op.id, @artist
630 it '所持判定を問い合わせている' do
631 OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)
632 OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
633 r = OriginalPicture.edit @op.id, @artist
637 pic = OriginalPicture.edit @op.id, @artist
640 context '他人の原画を開こうとしたとき' do
641 it '403Forbidden例外を返す' do
642 OriginalPicture.any_instance.stub(:own?).and_return(false)
644 r = OriginalPicture.edit @op.id, @other_artist
645 }.should raise_error(ActiveRecord::Forbidden)
648 context '存在しない原画を開こうとしたとき' do
649 it '404RecordNotFound例外を返す' do
651 r = OriginalPicture.edit 0, @artist
652 }.should raise_error(ActiveRecord::RecordNotFound)
656 describe '単体取得オプションに於いて' do
657 it 'includeキーを含んでいる' do
658 r = OriginalPicture.show_opt
659 r.has_key?(:include).should be_true
662 r = OriginalPicture.show_opt[:include]
663 r.should have(2).items
666 r = OriginalPicture.show_opt[:include]
667 r.has_key?(:resource_picture).should be_true
670 r = OriginalPicture.show_opt[:include]
671 r.has_key?(:pictures).should be_true
674 describe 'json単体出力オプションに於いて' do
676 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
677 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
678 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
679 @sbt = FactoryGirl.create :speech_balloon_template
680 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
681 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
682 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
685 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
688 i.has_key?('resource_picture').should be_true
691 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
694 i.has_key?('pictures').should be_true
697 describe '作成・更新に於いて' do
699 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
700 @imager = ImagerTest.load "abc\ndef\nghi"
704 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
705 #それで外部のメソッド呼び出しだけに着目してテストする。
706 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
707 PictureIO.original_picture_io.stub(:put).with(any_args).and_return(true)
709 it '自身に属性をセットしている' do
710 OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
714 OriginalPicture.any_instance.should_receive(:save).exactly(1)
717 it 'PictureIoに画像データの保存を依頼している' do
718 PictureIO.original_picture_io.should_receive(:put).with(any_args).exactly(1)
722 context 'つつがなく終わるとき' do
725 it '自身に属性をセットしている' do
727 @op.width.should eq 3
728 @op.height.should eq 3
729 @op.filesize.should eq 9
731 it '原画モデルが作成されている' do
734 }.should change OriginalPicture, :count
738 OriginalPicture.find(@op).should_not be_nil
741 @op.store(@imager).should eq true
744 #以下から例外ケース。処理先頭から失敗させていく
745 context 'imagerが初期化に失敗したとき' do
749 @op.store(false).should be_false
751 it '自身の保存は呼ばれていない' do
752 OriginalPicture.any_instance.should_not_receive(:save)
755 it '全体エラーメッセージがセットされている' do
758 }.should change(@op.errors[:base], :count)
761 context '自身の保存に失敗したとき' do
763 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)
766 @op.store(@imager).should be_false
770 @op.should be_a_new OriginalPicture
772 it '原画の保存は呼ばれていない' do
773 PictureIO::LocalPicture.any_instance.should_not_receive(:put)
776 context '原画の保存に失敗したとき' do
778 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
779 PictureIO.original_picture_io.stub(:put).with(any_args).and_raise(PictureIO::Error)
782 @op.store(@imager).should be_false
786 @op.should be_a_new OriginalPicture
788 it '全体エラーメッセージがセットされている' do
791 }.should change(@op.errors[:base], :count)
798 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
800 context '事前チェックしておく' do
802 OriginalPicture.any_instance.stub(:destroy).and_return(true)
803 ResourcePicture.any_instance.stub(:unpublish).and_return(true)
804 Picture.any_instance.stub(:unpublish).with(any_args).and_return(true)
805 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
807 it '原画モデルに削除を依頼している' do
808 OriginalPicture.any_instance.should_receive(:destroy).exactly(1)
809 r = @op.destroy_with_resource_picture
811 it '保管庫に原画の画像データ削除を依頼している' do
812 PictureIO.original_picture_io.should_receive(:delete).with(@op.filename).exactly(1)
813 r = @op.destroy_with_resource_picture
815 context '自身にリンクされた素材があるとき' do
816 it '素材モデルに削除を依頼している' do
817 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
818 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
819 ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
820 r = @op.destroy_with_resource_picture
823 context '自身にリンクされた素材がないとき' do
824 it '素材モデルに削除を依頼しない' do
825 ResourcePicture.any_instance.should_not_receive(:unpublish)
826 r = @op.destroy_with_resource_picture
829 context '自身にリンクされた実素材があるとき' do
830 it 'すべての実素材に墨塗を依頼している' do
831 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
832 Picture.any_instance.should_receive(:unpublish).with(any_args).exactly(1)
833 r = @op.destroy_with_resource_picture
836 context '自身にリンクされた実素材がないとき' do
838 Picture.any_instance.should_not_receive(:unpublish)
839 r = @op.destroy_with_resource_picture
843 context 'つつがなく終わるとき' do
845 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
846 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
847 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
851 r = @op.destroy_with_resource_picture
852 }.should change(OriginalPicture, :count).by(-1)
854 r = OriginalPicture.find @op.id
858 r = @op.destroy_with_resource_picture
862 context '自身の削除に失敗したとき' do
864 OriginalPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
867 r = @op.destroy_with_resource_picture
872 r = @op.destroy_with_resource_picture
873 }.should_not change(OriginalPicture, :count)
876 context '画像の削除に失敗したとき' do
878 PictureIO.original_picture_io.stub(:exist?).with(@op.filename).and_return(true)
879 PictureIO.original_picture_io.stub(:delete).with(@op.filename).and_raise(PictureIO::Error)
882 r = @op.destroy_with_resource_picture
887 r = @op.destroy_with_resource_picture
888 }.should_not change(OriginalPicture, :count)
891 context '素材の削除に失敗とき' do
893 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
894 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
895 ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(false)
898 r = @op.destroy_with_resource_picture
903 r = @op.destroy_with_resource_picture
904 }.should_not change(OriginalPicture, :count)
906 r = @op.destroy_with_resource_picture
907 }.should_not change(ResourcePicture, :count)
910 context '実素材の墨塗に失敗とき' do
912 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
913 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
914 Picture.any_instance.stub(:unpublish).with(any_args).and_return(false)
917 r = @op.destroy_with_resource_picture
922 r = @op.destroy_with_resource_picture
923 }.should_not change(OriginalPicture, :count)
925 r = @op.destroy_with_resource_picture
926 }.should_not change(ResourcePicture, :count)
931 describe 'エクスポートに於いて' do
933 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
934 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
935 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
937 @old_op = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now - 1000
939 @stopped_op = FactoryGirl.create :original_picture, :artist_id => @artist.id
941 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
943 @outer_artist = FactoryGirl.create :artist_yas, :author_id => nil
944 @outer_op = FactoryGirl.create :original_picture, :artist_id => @outer_artist.id
946 context 'つつがなく終わるとき' do
947 it '開始日時が省略された場合はすべての内原画を返す' do
948 r = OriginalPicture.export
949 r.should eq [@op, @old_op, @stopped_op, @other_op]
951 it '開始日時以降に更新された内原画を返す' do
952 r = OriginalPicture.export @op.updated_at - 100
953 r.should eq [@op, @stopped_op, @other_op]
956 r = OriginalPicture.export
957 r.first.resource_picture.should_not be_nil
959 #素材がライセンスされていないケースもある
960 it '停止中の原画は素材を含んでいない' do
961 r = OriginalPicture.export
962 r[2].resource_picture.should be_nil
967 describe 'リストのjson化に於いて' do
969 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
970 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
971 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
972 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
973 @other_p = FactoryGirl.create :picture, :artist_id => @other_artist.id, :original_picture_id => @other_op.id, :license_id => @license.id, :revision => 0, :updated_at => Time.now + 100
974 @other_rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :original_picture_id => @other_op.id, :license_id => @license.id, :picture_id => @other_p.id
975 ResourcePicture.any_instance.stub(:restore).with(any_args).and_return('picture binary data')
977 context 'つつがなく終わるとき' do
979 r = OriginalPicture.list_as_json_text OriginalPicture.all
982 }.should_not raise_error(JSON::ParserError)
985 r = OriginalPicture.list_as_json_text OriginalPicture.all
990 r = OriginalPicture.list_as_json_text OriginalPicture.all
992 j.first['resource_picture'].should_not be_nil
994 it '各素材に画像データを添えて返す' do
995 r = OriginalPicture.list_as_json_text OriginalPicture.all
997 j.first['resource_picture']['picture_data'].should_not be_nil
998 j.last['resource_picture']['picture_data'].should_not be_nil
1003 describe 'インポートに於いて' do
1005 @imports = {:licenses => {}, :artist_id => @artist.id}
1007 context '事前チェックしておく' do