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
453 describe '自分の原画一覧取得に於いて' do
455 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
457 context 'つつがなく終わるとき' do
458 it '一覧取得オプションを利用している' do
459 OriginalPicture.stub(:list_opt).with(any_args).and_return({})
460 OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)
461 r = OriginalPicture.mylist @artist
465 r = OriginalPicture.mylist @artist
469 nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
470 r = OriginalPicture.mylist @artist
471 r.should eq [nc, @op]
474 nc = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
475 r = OriginalPicture.mylist @artist
478 context 'DBに5件あって1ページの件数を2件に変えたとして' do
480 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
481 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
482 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
483 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
486 r = OriginalPicture.mylist @artist, 1, 2
487 r.should have(2).items
489 it 'page=1なら末尾2件を返す' do
491 r = OriginalPicture.mylist @artist, 1, 2
492 r.should eq [@op5, @op4]
494 it 'page=2なら中間2件を返す' do
495 r = OriginalPicture.mylist @artist, 2, 2
496 r.should eq [@op3, @op2]
498 it 'page=3なら先頭1件を返す' do
499 r = OriginalPicture.mylist @artist, 3, 2
505 describe '自分の原画一覧ページ制御に於いて' do
507 OriginalPicture.stub(:count).with(any_args).and_return(100)
510 r = OriginalPicture.mylist_paginate @author
511 r.is_a?(Kaminari::PaginatableArray).should be_true
513 it '自分の原画一覧の取得条件を利用している' do
514 OriginalPicture.stub(:mylist_where).with(any_args).and_return('')
515 OriginalPicture.should_receive(:mylist_where).with(any_args).exactly(1)
516 r = OriginalPicture.mylist_paginate @author
518 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
519 r = OriginalPicture.mylist_paginate @author, 3, 10
520 r.limit_value.should eq 10
521 r.offset_value.should eq 20
525 describe '一覧取得オプションに於いて' do
527 r = OriginalPicture.list_opt
528 r.should have(2).items
531 r = OriginalPicture.list_opt
532 r.has_key?(:resource_picture).should be_true
535 r = OriginalPicture.list_opt
536 r.has_key?(:pictures).should be_true
539 describe 'json一覧出力オプションに於いて' do
541 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
542 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
543 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
544 @sbt = FactoryGirl.create :speech_balloon_template
545 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
546 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
547 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
550 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
553 i.has_key?('resource_picture').should be_true
556 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
559 i.has_key?('pictures').should be_true
563 describe '更新履歴一覧取得に於いて' do
565 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
566 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
567 :original_picture_id => @op.id
568 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
574 it '他の原画の実素材は含んでいない' do
575 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
576 :original_picture_id => @op2.id
580 it 'revisionで並んでいる' do
581 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
582 :original_picture_id => @op.id
584 r.should eq [@p2, @p]
588 describe '単体取得に於いて' do
590 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
592 context 'つつがなく終わるとき' do
593 it '単体取得オプションを利用している' do
594 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
595 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
596 r = OriginalPicture.show @op.id, @artist
598 it '閲覧許可を問い合わせている' do
599 OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
600 OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
601 r = OriginalPicture.show @op.id, @artist
605 pic = OriginalPicture.show @op.id, @artist
608 context '他人の原画を開こうとしたとき' do
609 it '403Forbidden例外を返す' do
610 OriginalPicture.any_instance.stub(:visible?).and_return(false)
612 pic = OriginalPicture.show @op.id, @other_artist
613 }.should raise_error(ActiveRecord::Forbidden)
616 context '存在しない原画を開こうとしたとき' do
617 it '404RecordNotFound例外を返す' do
619 pic = OriginalPicture.show 0, @artist
620 }.should raise_error(ActiveRecord::RecordNotFound)
624 describe '編集取得に於いて' do
626 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
628 context 'つつがなく終わるとき' do
629 it '単体取得オプションを利用している' do
630 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
631 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
632 r = OriginalPicture.edit @op.id, @artist
634 it '所持判定を問い合わせている' do
635 OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)
636 OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
637 r = OriginalPicture.edit @op.id, @artist
641 pic = OriginalPicture.edit @op.id, @artist
644 context '他人の原画を開こうとしたとき' do
645 it '403Forbidden例外を返す' do
646 OriginalPicture.any_instance.stub(:own?).and_return(false)
648 r = OriginalPicture.edit @op.id, @other_artist
649 }.should raise_error(ActiveRecord::Forbidden)
652 context '存在しない原画を開こうとしたとき' do
653 it '404RecordNotFound例外を返す' do
655 r = OriginalPicture.edit 0, @artist
656 }.should raise_error(ActiveRecord::RecordNotFound)
660 describe '単体取得オプションに於いて' do
661 it 'includeキーを含んでいる' do
662 r = OriginalPicture.show_opt
663 r.has_key?(:include).should be_true
666 r = OriginalPicture.show_opt[:include]
667 r.should have(2).items
670 r = OriginalPicture.show_opt[:include]
671 r.has_key?(:resource_picture).should be_true
674 r = OriginalPicture.show_opt[:include]
675 r.has_key?(:pictures).should be_true
678 describe 'json単体出力オプションに於いて' do
680 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
681 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
682 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
683 @sbt = FactoryGirl.create :speech_balloon_template
684 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
685 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
686 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
689 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
692 i.has_key?('resource_picture').should be_true
695 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
698 i.has_key?('pictures').should be_true
701 describe '作成・更新に於いて' do
703 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
704 @imager = ImagerTest.load "abc\ndef\nghi"
708 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
709 #それで外部のメソッド呼び出しだけに着目してテストする。
710 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
711 PictureIO.original_picture_io.stub(:put).with(any_args).and_return(true)
713 it '自身に属性をセットしている' do
714 OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
718 OriginalPicture.any_instance.should_receive(:save).exactly(1)
721 it 'PictureIoに画像データの保存を依頼している' do
722 PictureIO.original_picture_io.should_receive(:put).with(any_args).exactly(1)
726 context 'つつがなく終わるとき' do
729 it '自身に属性をセットしている' do
731 @op.width.should eq 3
732 @op.height.should eq 3
733 @op.filesize.should eq 9
735 it '原画モデルが作成されている' do
738 }.should change OriginalPicture, :count
742 OriginalPicture.find(@op).should_not be_nil
745 @op.store(@imager).should eq true
748 #以下から例外ケース。処理先頭から失敗させていく
749 context 'imagerが初期化に失敗したとき' do
753 @op.store(false).should be_false
755 it '自身の保存は呼ばれていない' do
756 OriginalPicture.any_instance.should_not_receive(:save)
759 it '全体エラーメッセージがセットされている' do
762 }.should change(@op.errors[:base], :count)
765 context '自身の保存に失敗したとき' do
767 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)
770 @op.store(@imager).should be_false
774 @op.should be_a_new OriginalPicture
776 it '原画の保存は呼ばれていない' do
777 PictureIO::LocalPicture.any_instance.should_not_receive(:put)
780 context '原画の保存に失敗したとき' do
782 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
783 PictureIO.original_picture_io.stub(:put).with(any_args).and_raise(PictureIO::Error)
786 @op.store(@imager).should be_false
790 @op.should be_a_new OriginalPicture
792 it '全体エラーメッセージがセットされている' do
795 }.should change(@op.errors[:base], :count)
802 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
804 context '事前チェックしておく' do
806 OriginalPicture.any_instance.stub(:destroy).and_return(true)
807 ResourcePicture.any_instance.stub(:unpublish).and_return(true)
808 Picture.any_instance.stub(:unpublish).with(any_args).and_return(true)
809 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
811 it '原画モデルに削除を依頼している' do
812 OriginalPicture.any_instance.should_receive(:destroy).exactly(1)
813 r = @op.destroy_with_resource_picture
815 it '保管庫に原画の画像データ削除を依頼している' do
816 PictureIO.original_picture_io.should_receive(:delete).with(@op.filename).exactly(1)
817 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 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
823 ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
824 r = @op.destroy_with_resource_picture
827 context '自身にリンクされた素材がないとき' do
828 it '素材モデルに削除を依頼しない' do
829 ResourcePicture.any_instance.should_not_receive(:unpublish)
830 r = @op.destroy_with_resource_picture
833 context '自身にリンクされた実素材があるとき' do
834 it 'すべての実素材に墨塗を依頼している' do
835 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
836 Picture.any_instance.should_receive(:unpublish).with(any_args).exactly(1)
837 r = @op.destroy_with_resource_picture
840 context '自身にリンクされた実素材がないとき' do
842 Picture.any_instance.should_not_receive(:unpublish)
843 r = @op.destroy_with_resource_picture
847 context 'つつがなく終わるとき' do
849 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
850 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
851 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
855 r = @op.destroy_with_resource_picture
856 }.should change(OriginalPicture, :count).by(-1)
858 r = OriginalPicture.find @op.id
862 r = @op.destroy_with_resource_picture
866 context '自身の削除に失敗したとき' do
868 OriginalPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
871 r = @op.destroy_with_resource_picture
876 r = @op.destroy_with_resource_picture
877 }.should_not change(OriginalPicture, :count)
880 context '画像の削除に失敗したとき' do
882 PictureIO.original_picture_io.stub(:exist?).with(@op.filename).and_return(true)
883 PictureIO.original_picture_io.stub(:delete).with(@op.filename).and_raise(PictureIO::Error)
886 r = @op.destroy_with_resource_picture
891 r = @op.destroy_with_resource_picture
892 }.should_not change(OriginalPicture, :count)
895 context '素材の削除に失敗とき' do
897 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
898 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
899 ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(false)
902 r = @op.destroy_with_resource_picture
907 r = @op.destroy_with_resource_picture
908 }.should_not change(OriginalPicture, :count)
910 r = @op.destroy_with_resource_picture
911 }.should_not change(ResourcePicture, :count)
914 context '実素材の墨塗に失敗とき' do
916 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
917 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
918 Picture.any_instance.stub(:unpublish).with(any_args).and_return(false)
921 r = @op.destroy_with_resource_picture
926 r = @op.destroy_with_resource_picture
927 }.should_not change(OriginalPicture, :count)
929 r = @op.destroy_with_resource_picture
930 }.should_not change(ResourcePicture, :count)
935 describe 'エクスポートに於いて' do
937 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
938 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
939 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
941 @old_op = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now - 1000
943 @stopped_op = FactoryGirl.create :original_picture, :artist_id => @artist.id
945 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
947 @outer_artist = FactoryGirl.create :artist_yas, :author_id => nil
948 @outer_op = FactoryGirl.create :original_picture, :artist_id => @outer_artist.id
950 context 'つつがなく終わるとき' do
951 it '開始日時が省略された場合はすべての内原画を返す' do
952 r = OriginalPicture.export
953 r.should eq [@op, @old_op, @stopped_op, @other_op]
955 it '開始日時以降に更新された内原画を返す' do
956 r = OriginalPicture.export @op.updated_at - 100
957 r.should eq [@op, @stopped_op, @other_op]
960 r = OriginalPicture.export
961 r.first.resource_picture.should_not be_nil
963 #素材がライセンスされていないケースもある
964 it '停止中の原画は素材を含んでいない' do
965 r = OriginalPicture.export
966 r[2].resource_picture.should be_nil
971 describe 'リストのjson化に於いて' do
973 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
974 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
975 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
976 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
977 @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
978 @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
979 ResourcePicture.any_instance.stub(:restore).with(any_args).and_return('picture binary data')
981 context 'つつがなく終わるとき' do
983 r = OriginalPicture.list_as_json_text OriginalPicture.all
986 }.should_not raise_error(JSON::ParserError)
989 r = OriginalPicture.list_as_json_text OriginalPicture.all
994 r = OriginalPicture.list_as_json_text OriginalPicture.all
996 j.first['resource_picture'].should_not be_nil
998 it '各素材に画像データを添えて返す' do
999 r = OriginalPicture.list_as_json_text OriginalPicture.all
1001 j.first['resource_picture']['picture_data'].should_not be_nil
1002 j.last['resource_picture']['picture_data'].should_not be_nil
1007 describe 'インポートに於いて' do
1009 @imports = {:licenses => {}, :artist_id => @artist.id}
1011 context '事前チェックしておく' do