1 # -*- encoding: utf-8 -*-
5 describe OriginalPicture do
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @user = FactoryGirl.create( :user_yas)
10 @author = FactoryGirl.create :author, :user_id => @user.id
11 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
12 @other_user = FactoryGirl.create( :user_yas)
13 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
14 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
15 @sp = FactoryGirl.create :system_picture
16 @lg = FactoryGirl.create :license_group
17 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
22 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
25 context 'オーソドックスなデータのとき' do
27 @op.ext = 'png' #リストにない拡張子は通らないし
38 @op.filesize = 2000000
44 context 'extを検証するとき' do
47 @op.should_not be_valid
51 @op.should_not be_valid
53 it 'png,gif,jpeg以外なら失敗する' do
55 @op.should_not be_valid
58 context 'widthを検証するとき' do
61 @op.should_not be_valid
65 @op.should_not be_valid
69 @op.should_not be_valid
73 @op.should_not be_valid
76 context 'heightを検証するとき' do
79 @op.should_not be_valid
83 @op.should_not be_valid
87 @op.should_not be_valid
91 @op.should_not be_valid
94 context 'filesizeを検証するとき' do
97 @op.should_not be_valid
101 @op.should_not be_valid
105 @op.should_not be_valid
108 @op.filesize = 2000000+1
109 @op.should_not be_valid
112 context 'artist_idを検証するとき' do
115 @op.should_not be_valid
119 @op.should_not be_valid
121 it '存在する絵師でなければ失敗する' do
123 @op.should_not be_valid
126 context 'md5を検証するとき' do
129 @op.should_not be_valid
133 @op.should_not be_valid
137 @op.should_not be_valid
142 describe 'デフォルト値補充に於いて' do
144 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
149 describe '上書き補充に於いて' do
151 @op = FactoryGirl.build :original_picture, :uploaded_at => nil
152 @op.overwrite @artist
153 @op.uploaded_at.should_not be_nil
156 @op = FactoryGirl.build :original_picture, :artist_id => nil
157 @op.overwrite @artist
158 @op.artist_id.should eq @artist.id
162 describe '所持判定に於いて' do
164 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
166 context '事前チェックする' do
167 it '自身にロールリストからの絵師取得を依頼している' do
168 OriginalPicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)
169 r = @op.own?([@artist])
172 context 'ロール内絵師が取得できるとき' do
175 it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do
176 OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)
177 r = @op.own?([@artist])
180 it 'ロール内絵師のidが自身の絵師idと一致しないならno' do
181 OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)
182 @op.own?(@other_artist).should be_false
185 context 'ロール内絵師が取得できないとき' do
187 OriginalPicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)
190 r = @op.own?([@artist])
196 describe '閲覧許可に於いて' do
198 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
200 context '事前チェックする' do
202 MagicNumber['run_mode'] = 1
204 it '自身の原画に所持判定を問い合わせしている' do
205 OriginalPicture.any_instance.stub(:own?).and_return(true)
206 OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
207 r = @op.visible?([@artist])
210 context 'つつがなく終わるとき' do
212 MagicNumber['run_mode'] = 1
215 OriginalPicture.any_instance.stub(:own?).and_return(true)
216 r = @op.visible?([@artist])
220 OriginalPicture.any_instance.stub(:own?).and_return(false)
221 r = @op.visible?([@artist])
227 describe 'ファイル名に於いて' do
229 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
231 it 'id+拡張子のフォーマットで返す' do
233 r.should eq "#{@op.id}.png"
237 describe 'MimeTypeに於いて' do
239 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
241 it 'image/拡張子のフォーマットで返す' do
243 r.should eq "image/png"
247 describe 'ファイルのurlに於いて' do
249 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
250 OriginalPicture.any_instance.stub(:filename).and_return('3.gif')
252 it 'ファイル名取得を依頼している' do
253 OriginalPicture.any_instance.should_receive(:filename).exactly(1)
256 it '/original_pictures/3.gifのフォーマットで返す' do
258 r.should eq "/original_pictures/3.gif"
262 describe 'サムネイル画像タグオプションに於いて' do
264 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
265 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
266 PettanImager.stub(:thumbnail_size).with(any_args).and_return([40, 30])
268 it 'サムネイル画像の幅高さ取得を依頼している' do
269 PettanImager.should_receive(:thumbnail_size).with(any_args).exactly(1)
273 r = @op.tmb_opt_img_tag
274 r.is_a?(Hash).should be_true
277 r = @op.tmb_opt_img_tag
278 r.has_key?(:src).should be_true
279 r[:src].should eq '/original_pictures/3.gif'
281 it 'widthキーを含んでいる' do
282 r = @op.tmb_opt_img_tag
283 r.has_key?(:width).should be_true
284 r[:width].should eq 40
286 it 'heightキーを含んでいる' do
287 r = @op.tmb_opt_img_tag
288 r.has_key?(:height).should be_true
289 r[:height].should eq 30
293 describe '画像タグオプションに於いて' do
295 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
296 OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
300 r.is_a?(Hash).should be_true
304 r.has_key?(:src).should be_true
305 r[:src].should eq '/original_pictures/3.gif'
307 it 'widthキーを含んでいる' do
309 r.has_key?(:width).should be_true
310 r[:width].should eq @op.width
312 it 'heightキーを含んでいる' do
314 r.has_key?(:height).should be_true
315 r[:height].should eq @op.height
319 describe '未公開に於いて' do
321 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
323 context '公開日時と停止日時がともに空のとき' do
329 context '公開日時と停止日時がともに空ではないとき' do
331 @op.stopped_at =Time.now
336 @op.published_at =Time.now
343 describe '停止中に於いて' do
345 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
347 context '停止日時が空でないとき' do
349 @op.stopped_at =Time.now
354 context '停止日時が空のとき' do
363 describe 'ライセンス待ちに於いて' do
365 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
367 context '公開日時と停止日時のうち、空でない方を取得して、投稿日時がそれより後のとき' do
369 @op.uploaded_at = Time.now
370 @op.stopped_at = Time.now - 400
375 @op.uploaded_at = Time.now
376 @op.published_at =Time.now - 400
381 context '公開日時と停止日時のうち、空でない方を取得して、投稿日時がそれより後ではないとき' do
383 @op.published_at = nil
389 @op.uploaded_at = Time.now
390 @op.published_at =Time.now + 400
395 @op.uploaded_at = Time.now
396 @op.stopped_at =Time.now + 400
403 describe '公開中に於いて' do
405 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
407 context '公開日時が空ではないとき' do
409 @op.published_at =Time.now
414 context '公開日時が空のとき' do
416 @op.published_at = nil
423 describe '一覧取得に於いて' do
425 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
427 context 'page補正について' do
428 it '文字列から数値に変換される' do
429 OriginalPicture.page('8').should eq 8
432 OriginalPicture.page().should eq 1
435 OriginalPicture.page('0').should eq 1
438 context 'page_size補正について' do
439 it '文字列から数値に変換される' do
440 OriginalPicture.page_size('7').should eq 7
442 it 'nilの場合はOriginalPicture.default_page_sizeになる' do
443 OriginalPicture.page_size().should eq OriginalPicture.default_page_size
445 it '0以下の場合はOriginalPicture.default_page_sizeになる' do
446 OriginalPicture.page_size('0').should eq OriginalPicture.default_page_size
448 it 'OriginalPicture.max_page_sizeを超えた場合はOriginalPicture.max_page_sizeになる' do
449 OriginalPicture.page_size('1000').should eq OriginalPicture.max_page_size
454 describe '自分の原画一覧取得に於いて' do
456 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
458 context 'つつがなく終わるとき' do
459 it '一覧取得オプションを利用している' do
460 OriginalPicture.stub(:list_opt).with(any_args).and_return({})
461 OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)
462 r = OriginalPicture.mylist @artist
466 r = OriginalPicture.mylist @artist
470 nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
471 r = OriginalPicture.mylist @artist
472 r.should eq [nc, @op]
475 nc = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
476 r = OriginalPicture.mylist @artist
479 context 'DBに5件あって1ページの件数を2件に変えたとして' do
481 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
482 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
483 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
484 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
487 r = OriginalPicture.mylist @artist, 1, 2
488 r.should have(2).items
490 it 'page=1なら末尾2件を返す' do
492 r = OriginalPicture.mylist @artist, 1, 2
493 r.should eq [@op5, @op4]
495 it 'page=2なら中間2件を返す' do
496 r = OriginalPicture.mylist @artist, 2, 2
497 r.should eq [@op3, @op2]
499 it 'page=3なら先頭1件を返す' do
500 r = OriginalPicture.mylist @artist, 3, 2
506 describe '自分の原画一覧ページ制御に於いて' do
508 OriginalPicture.stub(:count).with(any_args).and_return(100)
511 r = OriginalPicture.mylist_paginate @author
512 r.is_a?(Kaminari::PaginatableArray).should be_true
514 it '自分の原画一覧の取得条件を利用している' do
515 OriginalPicture.stub(:mylist_where).with(any_args).and_return('')
516 OriginalPicture.should_receive(:mylist_where).with(any_args).exactly(1)
517 r = OriginalPicture.mylist_paginate @author
519 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
520 r = OriginalPicture.mylist_paginate @author, 3, 10
521 r.limit_value.should eq 10
522 r.offset_value.should eq 20
526 describe '一覧取得オプションに於いて' do
528 r = OriginalPicture.list_opt
529 r.should have(2).items
532 r = OriginalPicture.list_opt
533 r.has_key?(:resource_picture).should be_true
536 r = OriginalPicture.list_opt
537 r.has_key?(:pictures).should be_true
540 describe 'json一覧出力オプションに於いて' do
542 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
543 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
544 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
545 @sbt = FactoryGirl.create :speech_balloon_template
546 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
547 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
548 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
551 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
554 i.has_key?('resource_picture').should be_true
557 r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
560 i.has_key?('pictures').should be_true
564 describe '更新履歴一覧取得に於いて' do
566 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
567 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
568 :original_picture_id => @op.id
569 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
575 it '他の原画の実素材は含んでいない' do
576 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
577 :original_picture_id => @op2.id
581 it 'revisionで並んでいる' do
582 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
583 :original_picture_id => @op.id
585 r.should eq [@p2, @p]
589 describe '単体取得に於いて' do
591 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
593 context 'つつがなく終わるとき' do
594 it '単体取得オプションを利用している' do
595 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
596 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
597 r = OriginalPicture.show @op.id, @artist
599 it '閲覧許可を問い合わせている' do
600 OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
601 OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
602 r = OriginalPicture.show @op.id, @artist
606 pic = OriginalPicture.show @op.id, @artist
609 context '他人の原画を開こうとしたとき' do
610 it '403Forbidden例外を返す' do
611 OriginalPicture.any_instance.stub(:visible?).and_return(false)
613 pic = OriginalPicture.show @op.id, @other_artist
614 }.should raise_error(ActiveRecord::Forbidden)
617 context '存在しない原画を開こうとしたとき' do
618 it '404RecordNotFound例外を返す' do
620 pic = OriginalPicture.show 0, @artist
621 }.should raise_error(ActiveRecord::RecordNotFound)
625 describe '編集取得に於いて' do
627 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
629 context 'つつがなく終わるとき' do
630 it '単体取得オプションを利用している' do
631 OriginalPicture.stub(:show_opt).with(any_args).and_return({})
632 OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
633 r = OriginalPicture.edit @op.id, @artist
635 it '所持判定を問い合わせている' do
636 OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)
637 OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
638 r = OriginalPicture.edit @op.id, @artist
642 pic = OriginalPicture.edit @op.id, @artist
645 context '他人の原画を開こうとしたとき' do
646 it '403Forbidden例外を返す' do
647 OriginalPicture.any_instance.stub(:own?).and_return(false)
649 r = OriginalPicture.edit @op.id, @other_artist
650 }.should raise_error(ActiveRecord::Forbidden)
653 context '存在しない原画を開こうとしたとき' do
654 it '404RecordNotFound例外を返す' do
656 r = OriginalPicture.edit 0, @artist
657 }.should raise_error(ActiveRecord::RecordNotFound)
661 describe '単体取得オプションに於いて' do
662 it 'includeキーを含んでいる' do
663 r = OriginalPicture.show_opt
664 r.has_key?(:include).should be_true
667 r = OriginalPicture.show_opt[:include]
668 r.should have(2).items
671 r = OriginalPicture.show_opt[:include]
672 r.has_key?(:resource_picture).should be_true
675 r = OriginalPicture.show_opt[:include]
676 r.has_key?(:pictures).should be_true
679 describe 'json単体出力オプションに於いて' do
681 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
682 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
683 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
684 @sbt = FactoryGirl.create :speech_balloon_template
685 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
686 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
687 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
690 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
693 i.has_key?('resource_picture').should be_true
696 r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
699 i.has_key?('pictures').should be_true
702 describe '作成・更新に於いて' do
704 @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
705 @imager = ImagerTest.load "abc\ndef\nghi"
709 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
710 #それで外部のメソッド呼び出しだけに着目してテストする。
711 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
712 PictureIO.original_picture_io.stub(:put).with(any_args).and_return(true)
714 it '自身に属性をセットしている' do
715 OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
719 OriginalPicture.any_instance.should_receive(:save).exactly(1)
722 it 'PictureIoに画像データの保存を依頼している' do
723 PictureIO.original_picture_io.should_receive(:put).with(any_args).exactly(1)
727 context 'つつがなく終わるとき' do
730 it '自身に属性をセットしている' do
732 @op.width.should eq 3
733 @op.height.should eq 3
734 @op.filesize.should eq 9
736 it '原画モデルが作成されている' do
739 }.should change OriginalPicture, :count
743 OriginalPicture.find(@op).should_not be_nil
746 @op.store(@imager).should eq true
749 #以下から例外ケース。処理先頭から失敗させていく
750 context 'imagerが初期化に失敗したとき' do
754 @op.store(false).should be_false
756 it '自身の保存は呼ばれていない' do
757 OriginalPicture.any_instance.should_not_receive(:save)
760 it '全体エラーメッセージがセットされている' do
763 }.should change(@op.errors[:base], :count)
766 context '自身の保存に失敗したとき' do
768 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)
771 @op.store(@imager).should be_false
775 @op.should be_a_new OriginalPicture
777 it '原画の保存は呼ばれていない' do
778 PictureIO::LocalPicture.any_instance.should_not_receive(:put)
781 context '原画の保存に失敗したとき' do
783 OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
784 PictureIO.original_picture_io.stub(:put).with(any_args).and_raise(PictureIO::Error)
787 @op.store(@imager).should be_false
791 @op.should be_a_new OriginalPicture
793 it '全体エラーメッセージがセットされている' do
796 }.should change(@op.errors[:base], :count)
803 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
805 context '事前チェックしておく' do
807 OriginalPicture.any_instance.stub(:destroy).and_return(true)
808 ResourcePicture.any_instance.stub(:unpublish).and_return(true)
809 Picture.any_instance.stub(:unpublish).with(any_args).and_return(true)
810 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
812 it '原画モデルに削除を依頼している' do
813 OriginalPicture.any_instance.should_receive(:destroy).exactly(1)
814 r = @op.destroy_with_resource_picture
816 it '保管庫に原画の画像データ削除を依頼している' do
817 PictureIO.original_picture_io.should_receive(:delete).with(@op.filename).exactly(1)
818 r = @op.destroy_with_resource_picture
820 context '自身にリンクされた素材があるとき' do
821 it '素材モデルに削除を依頼している' do
822 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
823 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
824 ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
825 r = @op.destroy_with_resource_picture
828 context '自身にリンクされた素材がないとき' do
829 it '素材モデルに削除を依頼しない' do
830 ResourcePicture.any_instance.should_not_receive(:unpublish)
831 r = @op.destroy_with_resource_picture
834 context '自身にリンクされた実素材があるとき' do
835 it 'すべての実素材に墨塗を依頼している' do
836 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
837 Picture.any_instance.should_receive(:unpublish).with(any_args).exactly(1)
838 r = @op.destroy_with_resource_picture
841 context '自身にリンクされた実素材がないとき' do
843 Picture.any_instance.should_not_receive(:unpublish)
844 r = @op.destroy_with_resource_picture
848 context 'つつがなく終わるとき' do
850 PictureIO.original_picture_io.stub(:delete).with(any_args).and_return(true)
851 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
852 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
856 r = @op.destroy_with_resource_picture
857 }.should change(OriginalPicture, :count).by(-1)
859 r = OriginalPicture.find @op.id
863 r = @op.destroy_with_resource_picture
867 context '自身の削除に失敗したとき' do
869 OriginalPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
872 r = @op.destroy_with_resource_picture
877 r = @op.destroy_with_resource_picture
878 }.should_not change(OriginalPicture, :count)
881 context '画像の削除に失敗したとき' do
883 PictureIO.original_picture_io.stub(:exist?).with(@op.filename).and_return(true)
884 PictureIO.original_picture_io.stub(:delete).with(@op.filename).and_raise(PictureIO::Error)
887 r = @op.destroy_with_resource_picture
892 r = @op.destroy_with_resource_picture
893 }.should_not change(OriginalPicture, :count)
896 context '素材の削除に失敗とき' do
898 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
899 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
900 ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(false)
903 r = @op.destroy_with_resource_picture
908 r = @op.destroy_with_resource_picture
909 }.should_not change(OriginalPicture, :count)
911 r = @op.destroy_with_resource_picture
912 }.should_not change(ResourcePicture, :count)
915 context '実素材の墨塗に失敗とき' do
917 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :revision => 0
918 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
919 Picture.any_instance.stub(:unpublish).with(any_args).and_return(false)
922 r = @op.destroy_with_resource_picture
927 r = @op.destroy_with_resource_picture
928 }.should_not change(OriginalPicture, :count)
930 r = @op.destroy_with_resource_picture
931 }.should_not change(ResourcePicture, :count)
936 describe 'エクスポートに於いて' do
938 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
939 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
940 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
942 @old_op = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now - 1000
944 @stopped_op = FactoryGirl.create :original_picture, :artist_id => @artist.id
946 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
948 @outer_artist = FactoryGirl.create :artist_yas, :author_id => nil
949 @outer_op = FactoryGirl.create :original_picture, :artist_id => @outer_artist.id
951 context 'つつがなく終わるとき' do
952 it '開始日時が省略された場合はすべての内原画を返す' do
953 r = OriginalPicture.export
954 r.should eq [@op, @old_op, @stopped_op, @other_op]
956 it '開始日時以降に更新された内原画を返す' do
957 r = OriginalPicture.export @op.updated_at - 100
958 r.should eq [@op, @stopped_op, @other_op]
961 r = OriginalPicture.export
962 r.first.resource_picture.should_not be_nil
964 #素材がライセンスされていないケースもある
965 it '停止中の原画は素材を含んでいない' do
966 r = OriginalPicture.export
967 r[2].resource_picture.should be_nil
972 describe 'リストのjson化に於いて' do
974 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
975 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
976 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
977 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
978 @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
979 @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
980 ResourcePicture.any_instance.stub(:restore).with(any_args).and_return('picture binary data')
982 context 'つつがなく終わるとき' do
984 r = OriginalPicture.list_as_json_text OriginalPicture.all
987 }.should_not raise_error(JSON::ParserError)
990 r = OriginalPicture.list_as_json_text OriginalPicture.all
995 r = OriginalPicture.list_as_json_text OriginalPicture.all
997 j.first['resource_picture'].should_not be_nil
999 it '各素材に画像データを添えて返す' do
1000 r = OriginalPicture.list_as_json_text OriginalPicture.all
1002 j.first['resource_picture']['picture_data'].should_not be_nil
1003 j.last['resource_picture']['picture_data'].should_not be_nil
1008 describe 'インポートに於いて' do
1010 @imports = {:licenses => {}, :artist_id => @artist.id}
1012 context '事前チェックしておく' do