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
167 @op.own?(@author).should == true
170 @op.own?(@other_author).should == false
173 context 'パラメータが絵師のとき' do
175 @op.own?(@artist).should == true
178 @op.own?(@other_artist).should == false
183 @op.own?(nil).should == false
188 describe '閲覧許可に於いて' do
190 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
192 it '検査対象が管理者のとき、許可を返す' do
193 OriginalPicture.any_instance.stub(:own?).and_return(false)
194 r = @op.visible?(@admin)
197 it '所持判定を問い合わせ、自分の原画なら許可する' do
198 OriginalPicture.any_instance.stub(:own?).and_return(true)
199 r = @op.visible?(@artist)
203 OriginalPicture.any_instance.stub(:own?).and_return(false)
204 r = @op.visible?(@artist)
209 describe 'ファイル名に於いて' do
211 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
213 it 'id+拡張子のフォーマットで返す' do
215 r.should eq "#{@op.id}.png"
219 describe 'MimeTypeに於いて' do
221 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
223 it 'image/拡張子のフォーマットで返す' do
225 r.should eq "image/png"
229 describe 'ファイルのurlに於いて' do
231 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
232 OriginalPicture.any_instance.stub(:filename).and_return('3.gif')
234 it 'ファイル名取得を依頼している' do
235 OriginalPicture.any_instance.should_receive(:filename).exactly(1)
238 it '/original_pictures/3.gifのフォーマットで返す' do
240 r.should eq "/original_pictures/3.gif"
244 describe 'サムネイル画像タグオプションに於いて' do
246 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
247 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
248 PettanImager.stub(:thumbnail_size).with(any_args).and_return([40, 30])
250 it 'サムネイル画像の幅高さ取得を依頼している' do
251 PettanImager.should_receive(:thumbnail_size).with(any_args).exactly(1)
255 r = @op.tmb_opt_img_tag
256 r.is_a?(Hash).should be_true
259 r = @op.tmb_opt_img_tag
260 r.has_key?(:src).should be_true
261 r[:src].should eq '/original_pictures/3.gif'
263 it 'widthキーを含んでいる' do
264 r = @op.tmb_opt_img_tag
265 r.has_key?(:width).should be_true
266 r[:width].should eq 40
268 it 'heightキーを含んでいる' do
269 r = @op.tmb_opt_img_tag
270 r.has_key?(:height).should be_true
271 r[:height].should eq 30
275 describe '画像タグオプションに於いて' do
277 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
278 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
282 r.is_a?(Hash).should be_true
286 r.has_key?(:src).should be_true
287 r[:src].should eq '/original_pictures/3.gif'
289 it 'widthキーを含んでいる' do
291 r.has_key?(:width).should be_true
292 r[:width].should eq @op.width
294 it 'heightキーを含んでいる' do
296 r.has_key?(:height).should be_true
297 r[:height].should eq @op.height
301 describe '未公開に於いて' do
303 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
305 context '公開日時と停止日時がともに空のとき' do
311 context '公開日時と停止日時がともに空ではないとき' do
313 @op.stopped_at =Time.now
318 @op.published_at =Time.now
325 describe '停止中に於いて' do
327 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
329 context '停止日時が空でないとき' do
331 @op.stopped_at =Time.now
336 context '停止日時が空のとき' do
345 describe 'ライセンス待ちに於いて' do
347 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
349 context '公開日時と停止日時のうち、空でない方を取得して、投稿日時がそれより後のとき' do
351 @op.uploaded_at = Time.now
352 @op.stopped_at = Time.now - 400
357 @op.uploaded_at = Time.now
358 @op.published_at =Time.now - 400
363 context '公開日時と停止日時のうち、空でない方を取得して、投稿日時がそれより後ではないとき' do
365 @op.published_at = nil
371 @op.uploaded_at = Time.now
372 @op.published_at =Time.now + 400
377 @op.uploaded_at = Time.now
378 @op.stopped_at =Time.now + 400
385 describe '公開中に於いて' do
387 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
389 context '公開日時が空ではないとき' do
391 @op.published_at =Time.now
396 context '公開日時が空のとき' do
398 @op.published_at = nil
405 describe '一覧取得に於いて' do
407 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
409 context 'page補正について' do
410 it '文字列から数値に変換される' do
411 OriginalPicture.page('8').should eq 8
414 OriginalPicture.page().should eq 1
417 OriginalPicture.page('0').should eq 1
420 context 'page_size補正について' do
421 it '文字列から数値に変換される' do
422 OriginalPicture.page_size('7').should eq 7
424 it 'nilの場合はOriginalPicture.default_page_sizeになる' do
425 OriginalPicture.page_size().should eq OriginalPicture.default_page_size
427 it '0以下の場合はOriginalPicture.default_page_sizeになる' do
428 OriginalPicture.page_size('0').should eq OriginalPicture.default_page_size
430 it 'OriginalPicture.max_page_sizeを超えた場合はOriginalPicture.max_page_sizeになる' do
431 OriginalPicture.page_size('1000').should eq OriginalPicture.max_page_size
435 describe '一覧取得オプションに於いて' do
436 it 'includeキーを含んでいる' do
437 r = OriginalPicture.list_opt
438 r.has_key?(:include).should be_true
441 r = OriginalPicture.list_opt[:include]
442 r.should have(2).items
445 r = OriginalPicture.list_opt[:include]
446 r.has_key?(:resource_picture).should be_true
449 r = OriginalPicture.list_opt[:include]
450 r.has_key?(:pictures).should be_true
453 describe 'json一覧出力オプションに於いて' do
455 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
456 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
457 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
458 @sbt = FactoryGirl.create :speech_balloon_template
459 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
460 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
461 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
464 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
467 i.has_key?('resource_picture').should be_true
470 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
473 i.has_key?('pictures').should be_true
477 describe '自分の原画一覧取得に於いて' do
479 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
481 context 'つつがなく終わるとき' do
482 it '一覧取得オプションを利用している' do
483 OriginalPicture.stub(:list_opt).with(any_args).and_return({})
484 OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)
485 r = OriginalPicture.mylist @artist
489 r = OriginalPicture.mylist @artist
493 nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
494 r = OriginalPicture.mylist @artist
495 r.should eq [nc, @op]
498 nc = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
499 r = OriginalPicture.mylist @artist
502 context 'DBに5件あって1ページの件数を2件に変えたとして' do
504 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
505 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
506 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
507 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
510 r = OriginalPicture.mylist @artist, 1, 2
511 r.should have(2).items
513 it 'page=1なら末尾2件を返す' do
515 r = OriginalPicture.mylist @artist, 1, 2
516 r.should eq [@op5, @op4]
518 it 'page=2なら中間2件を返す' do
519 r = OriginalPicture.mylist @artist, 2, 2
520 r.should eq [@op3, @op2]
522 it 'page=3なら先頭1件を返す' do
523 r = OriginalPicture.mylist @artist, 3, 2
527 context 'DBに5件あって1ページの件数を0件に変えたとして' do
529 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
530 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
531 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
532 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
533 OriginalPicture.stub(:default_page_size).and_return(2)
536 r = OriginalPicture.mylist @artist, 5, 0
537 r.should have(5).items
542 describe '更新履歴一覧取得に於いて' do
544 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
545 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
546 :original_picture_id => @op.id
547 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
553 it '他の原画の実素材は含んでいない' do
554 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
555 :original_picture_id => @op2.id
559 it 'revisionで並んでいる' do
560 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
561 :original_picture_id => @op.id
563 r.should eq [@p2, @p]
567 describe '単体取得に於いて' do
569 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
571 context 'つつがなく終わるとき' do
572 it '単体取得オプションを利用している' do
573 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
574 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
575 r = OriginalPicture.show @op.id, @artist
577 it '閲覧許可を問い合わせている' do
578 OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
579 OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
580 r = OriginalPicture.show @op.id, @artist
584 pic = OriginalPicture.show @op.id, @artist
587 context '他人の原画を開こうとしたとき' do
588 it '403Forbidden例外を返す' do
589 OriginalPicture.any_instance.stub(:visible?).and_return(false)
591 pic = OriginalPicture.show @op.id, @other_artist
592 }.should raise_error(ActiveRecord::Forbidden)
595 context '存在しない原画を開こうとしたとき' do
596 it '404RecordNotFound例外を返す' do
598 pic = OriginalPicture.show 0, @artist
599 }.should raise_error(ActiveRecord::RecordNotFound)
603 describe '編集取得に於いて' do
605 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
607 context 'つつがなく終わるとき' do
608 it '単体取得オプションを利用している' do
609 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
610 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
611 r = OriginalPicture.edit @op.id, @artist
613 it '所持判定を問い合わせている' do
614 OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)
615 OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
616 r = OriginalPicture.edit @op.id, @artist
620 pic = OriginalPicture.edit @op.id, @artist
623 context '他人の原画を開こうとしたとき' do
624 it '403Forbidden例外を返す' do
625 OriginalPicture.any_instance.stub(:own?).and_return(false)
627 r = OriginalPicture.edit @op.id, @other_artist
628 }.should raise_error(ActiveRecord::Forbidden)
631 context '存在しない原画を開こうとしたとき' do
632 it '404RecordNotFound例外を返す' do
634 r = OriginalPicture.edit 0, @artist
635 }.should raise_error(ActiveRecord::RecordNotFound)
639 describe '単体取得オプションに於いて' do
640 it 'includeキーを含んでいる' do
641 r = OriginalPicture.show_opt
642 r.has_key?(:include).should be_true
645 r = OriginalPicture.show_opt[:include]
646 r.should have(2).items
649 r = OriginalPicture.show_opt[:include]
650 r.has_key?(:resource_picture).should be_true
653 r = OriginalPicture.show_opt[:include]
654 r.has_key?(:pictures).should be_true
657 describe 'json単体出力オプションに於いて' do
659 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
660 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
661 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
662 @sbt = FactoryGirl.create :speech_balloon_template
663 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
664 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
665 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
668 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
671 i.has_key?('resource_picture').should be_true
674 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
677 i.has_key?('pictures').should be_true
680 describe '作成・更新に於いて' do
682 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
683 @imager = ImagerTest.load "abc\ndef\nghi"
687 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
688 #それで外部のメソッド呼び出しだけに着目してテストする。
689 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
690 PictureIO.original_picture_io.stub(:put).with(any_args).and_return(true)
692 it '自身に属性をセットしている' do
693 OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
697 OriginalPicture.any_instance.should_receive(:save).exactly(1)
700 it 'PictureIoに画像データの保存を依頼している' do
701 PictureIO.original_picture_io.should_receive(:put).with(any_args).exactly(1)
705 context 'つつがなく終わるとき' do
708 it '自身に属性をセットしている' do
710 @op.width.should eq 3
711 @op.height.should eq 3
712 @op.filesize.should eq 9
714 it '原画モデルが作成されている' do
717 }.should change OriginalPicture, :count
721 OriginalPicture.find(@op).should_not be_nil
724 @op.store(@imager).should eq true
727 #以下から例外ケース。処理先頭から失敗させていく
728 context 'imagerが初期化に失敗したとき' do
732 @op.store(false).should be_false
734 it '自身の保存は呼ばれていない' do
735 OriginalPicture.any_instance.should_not_receive(:save)
738 it '全体エラーメッセージがセットされている' do
741 }.should change(@op.errors[:base], :count)
744 context '自身の保存に失敗したとき' do
746 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)
749 @op.store(@imager).should be_false
753 @op.should be_a_new OriginalPicture
755 it '原画の保存は呼ばれていない' do
756 PictureIO::LocalPicture.any_instance.should_not_receive(:put)
759 context '原画の保存に失敗したとき' do
761 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
762 PictureIO.original_picture_io.stub(:put).with(any_args).and_raise(PictureIO::Error)
765 @op.store(@imager).should be_false
769 @op.should be_a_new OriginalPicture
771 it '全体エラーメッセージがセットされている' do
774 }.should change(@op.errors[:base], :count)
781 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
783 context '事前チェックしておく' do
785 OriginalPicture.any_instance.stub(:destroy).and_return(true)
786 ResourcePicture.any_instance.stub(:unpublish).and_return(true)
787 Picture.any_instance.stub(:unpublish).with(any_args).and_return(true)
788 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
790 it '原画モデルに削除を依頼している' do
791 OriginalPicture.any_instance.should_receive(:destroy).exactly(1)
792 r = @op.destroy_with_resource_picture
794 it '保管庫に原画の画像データ削除を依頼している' do
795 PictureIO.original_picture_io.should_receive(:delete).with(@op.filename).exactly(1)
796 r = @op.destroy_with_resource_picture
798 context '自身にリンクされた素材があるとき' do
799 it '素材モデルに削除を依頼している' do
800 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
801 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
802 ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
803 r = @op.destroy_with_resource_picture
806 context '自身にリンクされた素材がないとき' do
807 it '素材モデルに削除を依頼しない' do
808 ResourcePicture.any_instance.should_not_receive(:unpublish)
809 r = @op.destroy_with_resource_picture
812 context '自身にリンクされた実素材があるとき' do
813 it 'すべての実素材に墨塗を依頼している' do
814 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
815 Picture.any_instance.should_receive(:unpublish).with(any_args).exactly(1)
816 r = @op.destroy_with_resource_picture
819 context '自身にリンクされた実素材がないとき' do
821 Picture.any_instance.should_not_receive(:unpublish)
822 r = @op.destroy_with_resource_picture
826 context 'つつがなく終わるとき' do
828 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
829 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
830 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
834 r = @op.destroy_with_resource_picture
835 }.should change(OriginalPicture, :count).by(-1)
837 r = OriginalPicture.find @op.id
841 r = @op.destroy_with_resource_picture
845 context '自身の削除に失敗したとき' do
847 OriginalPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
850 r = @op.destroy_with_resource_picture
855 r = @op.destroy_with_resource_picture
856 }.should_not change(OriginalPicture, :count)
859 context '画像の削除に失敗したとき' do
861 PictureIO.original_picture_io.stub(:exist?).with(@op.filename).and_return(true)
862 PictureIO.original_picture_io.stub(:delete).with(@op.filename).and_raise(PictureIO::Error)
865 r = @op.destroy_with_resource_picture
870 r = @op.destroy_with_resource_picture
871 }.should_not change(OriginalPicture, :count)
874 context '素材の削除に失敗とき' do
876 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
877 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
878 ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(false)
881 r = @op.destroy_with_resource_picture
886 r = @op.destroy_with_resource_picture
887 }.should_not change(OriginalPicture, :count)
889 r = @op.destroy_with_resource_picture
890 }.should_not change(ResourcePicture, :count)
893 context '実素材の墨塗に失敗とき' do
895 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
896 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
897 Picture.any_instance.stub(:unpublish).with(any_args).and_return(false)
900 r = @op.destroy_with_resource_picture
905 r = @op.destroy_with_resource_picture
906 }.should_not change(OriginalPicture, :count)
908 r = @op.destroy_with_resource_picture
909 }.should_not change(ResourcePicture, :count)
914 describe 'エクスポートに於いて' do
916 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
917 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
918 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
920 @old_op = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now - 1000
922 @stopped_op = FactoryGirl.create :original_picture, :artist_id => @artist.id
924 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
926 @outer_artist = FactoryGirl.create :artist_yas, :author_id => nil
927 @outer_op = FactoryGirl.create :original_picture, :artist_id => @outer_artist.id
929 context 'つつがなく終わるとき' do
930 it '開始日時が省略された場合はすべての内原画を返す' do
931 r = OriginalPicture.export
932 r.should eq [@op, @old_op, @stopped_op, @other_op]
934 it '開始日時以降に更新された内原画を返す' do
935 r = OriginalPicture.export @op.updated_at - 100
936 r.should eq [@op, @stopped_op, @other_op]
939 r = OriginalPicture.export
940 r.first.resource_picture.should_not be_nil
942 #素材がライセンスされていないケースもある
943 it '停止中の原画は素材を含んでいない' do
944 r = OriginalPicture.export
945 r[2].resource_picture.should be_nil
950 describe 'リストのjson化に於いて' do
952 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
953 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
954 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
955 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
956 @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
957 @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
958 ResourcePicture.any_instance.stub(:restore).with(any_args).and_return('picture binary data')
960 context 'つつがなく終わるとき' do
962 r = OriginalPicture.list_as_json_text OriginalPicture.all
965 }.should_not raise_error(JSON::ParserError)
968 r = OriginalPicture.list_as_json_text OriginalPicture.all
973 r = OriginalPicture.list_as_json_text OriginalPicture.all
975 j.first['resource_picture'].should_not be_nil
977 it '各素材に画像データを添えて返す' do
978 r = OriginalPicture.list_as_json_text OriginalPicture.all
980 j.first['resource_picture']['picture_data'].should_not be_nil
981 j.last['resource_picture']['picture_data'].should_not be_nil
986 describe 'インポートに於いて' do
988 @imports = {:licenses => {}, :artist_id => @artist.id}
990 context '事前チェックしておく' do