1 # -*- encoding: utf-8 -*-
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
17 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
22 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
25 context 'オーソドックスなデータのとき' do
28 @p.ext = 'png' #リストにない拡張子は通らないし
48 context 'original_picture_idを検証するとき' do
50 @p.original_picture_id = nil
51 @p.should_not be_valid
54 @p.original_picture_id = 'a'
55 @p.should_not be_valid
57 it '存在する原画でなければ失敗する' do
58 @p.original_picture_id = 0
59 @p.should_not be_valid
62 context 'revisionを検証するとき' do
65 @p.should_not be_valid
69 @p.should_not be_valid
72 context 'extを検証するとき' do
75 @p.should_not be_valid
79 @p.should_not be_valid
81 it 'png,gif,jpeg以外なら失敗する' do
83 @p.should_not be_valid
86 context 'widthを検証するとき' do
89 @p.should_not be_valid
93 @p.should_not be_valid
97 @p.should_not be_valid
101 @p.should_not be_valid
104 context 'heightを検証するとき' do
107 @p.should_not be_valid
111 @p.should_not be_valid
115 @p.should_not be_valid
119 @p.should_not be_valid
122 context 'filesizeを検証するとき' do
125 @p.should_not be_valid
129 @p.should_not be_valid
133 @p.should_not be_valid
136 @p.filesize = 2000000+1
137 @p.should_not be_valid
140 context 'md5を検証するとき' do
143 @p.should_not be_valid
147 @p.should_not be_valid
151 @p.should_not be_valid
154 context 'artist_idを検証するとき' do
157 @p.should_not be_valid
161 @p.should_not be_valid
163 it '存在する絵師でなければ失敗する' do
165 @p.should_not be_valid
168 context 'license_idを検証するとき' do
171 @p.should_not be_valid
175 @p.should_not be_valid
177 it '存在するライセンスでなければ失敗する' do
179 @p.should_not be_valid
182 context 'artist_nameを検証するとき' do
185 @p.should_not be_valid
188 context 'classnameを検証するとき' do
191 @p.should_not be_valid
194 @p.classname = 'a'*51
195 @p.should_not be_valid
198 context 'creditを検証するとき' do
200 context 'settingsを検証するとき' do
204 describe '文字コード検証に於いて' do
206 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
209 context 'artist_nameを検証するとき' do
210 it 'Shift JISなら失敗する' do
211 @p.artist_name = "\x83G\x83r\x83]\x83D"
214 }.should raise_error(Pettanr::BadRequest)
218 context 'classnameを検証するとき' do
219 it 'Shift JISなら失敗する' do
220 @p.classname = "\x83G\x83r\x83]\x83D"
223 }.should raise_error(Pettanr::BadRequest)
227 context 'creditを検証するとき' do
228 it 'Shift JISなら失敗する' do
229 @p.credit = "\x83G\x83r\x83]\x83D"
232 }.should raise_error(Pettanr::BadRequest)
236 context 'settingsを検証するとき' do
237 it 'Shift JISなら失敗する' do
238 @p.settings = "\x83G\x83r\x83]\x83D"
241 }.should raise_error(Pettanr::BadRequest)
247 describe 'デフォルト値補充に於いて' do
249 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
254 describe '上書き補充に於いて' do
256 attr = {:ext => 'jpeg', :width => 264, :height => 265, :filesize => 266,
257 :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id,
258 :artist_name => 'tester', :classname => 'Tester', :credit => {:title => 'cap'}.to_json.to_s, :settings => {:set => 1}.to_json.to_s}
259 @rp = FactoryGirl.build :resource_picture, attr
260 @p = FactoryGirl.build :picture, :original_picture_id => nil, :license_id => nil, :artist_id => nil, :revision => nil
262 it 'width, height, ext, filesize, md5, original_picture_idが設定されている' do
264 @p.width.should eq 264
265 @p.height.should eq 265
266 @p.ext.should eq 'jpeg'
267 @p.filesize.should eq 266
268 @p.md5.should eq @rp.md5
269 @p.original_picture_id.should eq @op.id
271 it 'license_id, artist_id, artist_name, classname, credit, settingsが設定されている' do
273 @p.license_id.should eq @license.id
274 @p.artist_id.should eq @artist.id
275 @p.artist_name.should eq 'tester'
276 @p.classname.should eq 'Tester'
277 @p.credit.should match /title/
278 @p.settings.should match /set/
280 it 'new_revisionに問い合わせている' do
281 Picture.any_instance.stub(:new_revision).with(any_args).and_return(3)
282 Picture.any_instance.should_receive(:new_revision).with(any_args).exactly(1)
285 it 'revisionは、new_revisionに設定されている' do
286 Picture.any_instance.stub(:new_revision).with(any_args).and_return(3)
288 @p.revision.should eq 3
292 describe '所持判定に於いて' do
294 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
296 context '事前チェックする' do
297 it '自身にロールリストからの絵師取得を依頼している' do
298 Picture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)
299 r = @p.own?([@artist])
302 context 'ロール内絵師が取得できるとき' do
305 it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do
306 Picture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)
307 r = @p.own?([@artist])
310 it 'ロール内絵師のidが自身の絵師idと一致しないならno' do
311 Picture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)
312 @p.own?(@other_artist).should be_false
315 context 'ロール内絵師が取得できないとき' do
317 Picture.stub(:get_artist_from_roles).with(any_args).and_return(nil)
320 r = @p.own?([@artist])
326 describe '閲覧許可に於いて' do
328 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
331 r = @p.visible?(@artist)
336 describe '詳細閲覧許可に於いて' do
338 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
340 context '自身に原画がリンクしていないとき' do
342 Picture.any_instance.stub(:original_picture).with(any_args).and_return(nil)
345 r = @p.showable?(@author)
350 Picture.any_instance.stub(:own?).with(any_args).and_return(true)
351 @p.showable?(@artist).should == true
353 context '他人の実素材のとき' do
355 Picture.any_instance.stub(:own?).with(any_args).and_return(false)
357 it '自身にhead判定と有効性判定を問い合わせ、両者がTrueならTrueを返す。' do
358 Picture.any_instance.stub(:head?).with(any_args).and_return(true)
359 Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
360 r = @p.showable?(@author)
363 it 'head判定がFalseならFalseを返す。' do
364 Picture.any_instance.stub(:head?).with(any_args).and_return(false)
365 Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
366 r = @p.showable?(@author)
369 it '有効性判定がFalseならFalseを返す。' do
370 Picture.any_instance.stub(:enable?).with(any_args).and_return(false)
371 Picture.any_instance.stub(:head?).with(any_args).and_return(true)
372 r = @p.showable?(@author)
378 describe 'ファイル名に於いて' do
380 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
382 it 'id+拡張子のフォーマットで返す' do
384 r.should eq "#{@p.id}.png"
388 describe 'gifファイル名に於いて' do
390 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'gif'
392 it 'id.gifのフォーマットで返す' do
394 r.should eq "#{@p.id}.gif"
398 describe 'MimeTypeに於いて' do
400 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
402 it 'image/拡張子のフォーマットで返す' do
404 r.should eq "image/png"
408 describe 'ファイルのurlに於いて' do
410 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
411 Picture.any_instance.stub(:filename).and_return('3.gif')
413 it 'ファイル名取得を依頼している' do
414 Picture.any_instance.should_receive(:filename).exactly(1)
417 it '/pictures/3.gifのフォーマットで返す' do
419 r.should eq "/pictures/3.gif"
423 describe '最新Revision取得に於いて' do
424 context '初めての原画を公開したとき' do
426 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
428 it 'Revisionは1となる' do
429 @p.new_revision.should eq 1
432 context 'HEADが1のとき' do
434 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
435 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
437 it 'Revisionは2となる' do
438 @p.new_revision.should eq 2
441 context 'HEADが5のとき' do
443 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
444 FactoryGirl.create :picture, :revision => 5, :original_picture_id => @op.id, :license_id => @license.id
445 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
447 it 'Revisionは6となる' do
448 @p.new_revision.should eq 6
453 describe '有効性判定に於いて' do
455 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
456 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
457 Picture.any_instance.stub(:head).and_return(@p)
459 context '自身のheadとリンクした素材があるとき' do
461 Picture.any_instance.stub(:resource_picture).and_return(@rp)
468 context '自身のheadとリンクした素材がないとき' do
470 Picture.any_instance.stub(:resource_picture).and_return(nil)
479 describe 'head取得に於いて' do
482 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
483 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
484 :original_picture_id => @op.id, :md5 => 'a' * 32
486 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
487 :original_picture_id => @op.id, :md5 => 'b' * 32
489 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
490 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
491 :original_picture_id => @op2.id, :md5 => 'C' * 32
493 context 'つつがなく終わるとき' do
496 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
503 context '無効な素材(素材とリンクしてない)とき' do
511 describe 'head判定に於いて' do
514 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
515 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
516 :original_picture_id => @op.id, :md5 => 'a' * 32
518 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
519 :original_picture_id => @op.id, :md5 => 'b' * 32
520 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
536 describe 'フォーマット変換対象判定に於いて' do
538 @p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
541 it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do
542 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
544 @p.to_gif?.should be_true
547 context '変換しないケース' do
548 it '画像フォーマットがpngでない' do
549 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
551 @p.to_gif?.should be_false
554 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)
556 @p.to_gif?.should be_false
561 describe 'サブディレクトリリストに於いて' do
563 @p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
566 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
568 r.is_a?(Array).should be_true
570 it '本画像(ベースディレクトリ)を含んでいる' do
571 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
573 r.include?('').should be_true
575 context '反転が許可されているとき' do
576 it '垂直・水平・垂直水平反転ディレクトリも返す' do
577 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
579 r.include?('v').should be_true
580 r.include?('h').should be_true
581 r.include?('vh').should be_true
584 context '反転が許可されていないとき' do
585 it '本画像(ベースディレクトリ)だけを返す' do
586 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
593 describe 'md5重複リストに於いて' do
595 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
596 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
597 :original_picture_id => @op.id, :md5 => 'a' * 32
598 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
599 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
600 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
601 :original_picture_id => @op2.id, :md5 => 'b' * 32
602 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
604 context '除外する原画idで指定されていないとき' do
606 res = Picture.list_by_md5(@p.md5)
607 res.is_a?(Array).should be_true
610 res = Picture.list_by_md5(@p.md5)
611 res.include?(@p2).should be_false
614 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
615 :original_picture_id => @op2.id, :md5 => 'C' * 32
616 @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
617 :original_picture_id => @op3.id, :md5 => @p3.md5, :updated_at => Time.now + 100
618 res = Picture.find_by_md5(@p3.md5)
619 res.should eq [@p4, @p3]
622 context '除外する原画idで指定されたとき' do
624 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
625 res.is_a?(Array).should be_true
628 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
629 res.include?(@p2).should be_false
632 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
633 res.empty?.should be_true
635 it '同一原画は旧版でも含まない' do
636 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
637 :original_picture_id => @op.id, :md5 => 'a' * 32
638 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
639 res.empty?.should be_true
642 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
643 :original_picture_id => @op2.id, :md5 => 'a' * 32
644 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
647 it '他所の原画でもmd5が違えば含まない' do
648 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
649 :original_picture_id => @op2.id, :md5 => 'c' * 32
650 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
651 res.empty?.should be_true
654 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
655 :original_picture_id => @op2.id, :md5 => 'a' * 32
656 @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
657 :original_picture_id => @op3.id, :md5 => 'a' * 32, :updated_at => Time.now + 100
658 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
659 res.should eq [@p4, @p3]
664 describe 'md5重複判定に於いて' do
666 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
667 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
668 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
669 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
671 context '同一原画以外に同じ値があるとき' do
673 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license.id
676 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
680 context '同一原画以外に同じ値がないとき' do
682 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
686 context '同一原画に同じ値があるとき' do
688 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 1
691 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
697 describe '単体取得に於いて' do
699 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
701 context 'つつがなく終わるとき' do
702 it '閲覧許可を問い合わせている' do
703 Picture.any_instance.stub(:visible?).with(any_args).and_return(true)
704 Picture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
705 r = Picture.show @p.id, @author
709 r = Picture.show @p.id, @author
712 context '他人の実素材を開こうとしたとき' do
713 it '403Forbidden例外を返す' do
714 Picture.any_instance.stub(:visible?).and_return(false)
716 r = Picture.show @p.id, @other_author
717 }.should raise_error(ActiveRecord::Forbidden)
720 context '存在しない実素材を開こうとしたとき' do
721 it '404RecordNotFound例外を返す' do
723 r = Picture.show 0, @author
724 }.should raise_error(ActiveRecord::RecordNotFound)
731 @imager = ImagerTest.load "abc\ndef\nghi"
732 #原画ファイル削除だけは必ず成功するものとしておく
733 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
737 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
738 #それで外部のメソッド呼び出しだけに着目してテストする。
739 Picture.any_instance.stub(:save).with(any_args).and_return(true)
740 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
741 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
742 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
745 Picture.any_instance.should_receive(:save).with(any_args).exactly(1)
746 r = @p.store(@imager)
748 it '画像ファイルの作成機能で画像を保存している' do
749 Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
751 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(2)
752 r = @p.store(@imager)
754 it '自身にgifフォーマット変換対象かを問い合わせている' do
755 Picture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
756 r = @p.store(@imager)
759 context 'つつがなく終わるとき' do
761 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
762 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
763 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
764 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
767 r = @p.store(@imager)
772 r = @p.store(@imager)
773 }.should change Picture, :count
776 context 'gif変換なしで、つつがなく終わるとき' do
778 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
779 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
780 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(false)
781 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
784 r = @p.store(@imager)
787 it 'gif保存は呼ばれていない' do
788 #二回目の画像作成が呼び出されないで1回こっきりならgif保存は呼ばれていないんだろう。
789 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
790 r = @p.store(@imager)
793 #以下から例外ケース。処理先頭から失敗させていく
794 context '自身の保存に失敗したとき' do
796 Picture.any_instance.stub(:save).with(any_args).and_return(false)
797 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
800 r = @p.store(@imager)
804 r = @p.store(@imager)
805 @p.should be_a_new Picture
808 context '画像の保存に失敗したとき' do
810 Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)
811 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
814 r = @p.store(@imager)
817 it 'gif変換判定は呼ばれていない' do
818 Picture.any_instance.should_not_receive(:to_gif?).with(any_args).exactly(0)
819 r = @p.store(@imager)
822 context 'gif変換に失敗したとき' do
824 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
825 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
826 ImagerTest.stub(:load).with(any_args).and_return(false)
827 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
830 r = @p.store(@imager)
833 it 'gif画像の保存は呼ばれていない' do
835 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
836 r = @p.store(@imager)
839 context 'gif画像の保存に失敗したとき' do
841 @gifimager = @imager.to_gif
842 ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(@gifimager)
843 Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
844 Picture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
845 Picture.any_instance.stub(:store_picture).with(@imager, '1.png').and_return(true)
846 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
847 Picture.any_instance.stub(:store_picture).with(@gifimager, '1.gif').and_return(false)
848 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
851 r = @p.store(@imager)
857 describe '画像ファイルの作成に於いて' do
858 #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。
860 @imager = ImagerTest.load "abc\ndef\nghi"
861 #原画ファイル削除だけは必ず成功するものとしておく
862 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
864 Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])
865 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
869 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
870 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
872 it '画像ファイルの保存が4回呼ばれる' do
873 PictureIO.picture_io.should_receive(:put).with(any_args).exactly(4)
874 r = @p.store_picture(@imager, '1.png')
876 it '画像ファイルのベースへの保存が1回呼ばれる' do
877 PictureIO.picture_io.should_receive(:put).with("abc\ndef\nghi", '1.png', '').exactly(1)
878 r = @p.store_picture(@imager, '1.png')
880 it '画像ファイルの垂直反転への保存が1回呼ばれる' do
881 PictureIO.picture_io.should_receive(:put).with("cba\nfed\nihg", '1.png', 'v').exactly(1)
882 r = @p.store_picture(@imager, '1.png')
884 it '画像ファイルの水平反転への保存が1回呼ばれる' do
885 PictureIO.picture_io.should_receive(:put).with("ghi\ndef\nabc", '1.png', 'h').exactly(1)
886 r = @p.store_picture(@imager, '1.png')
888 it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do
889 PictureIO.picture_io.should_receive(:put).with("ihg\nfed\ncba", '1.png', 'vh').exactly(1)
890 r = @p.store_picture(@imager, '1.png')
893 context 'つつがなく終わるとき' do
895 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
896 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
899 r = @p.store_picture(@imager, '1.png')
905 PictureIO.picture_io.stub(:put).with(any_args).and_return(false)
908 r = @p.store_picture(@imager, '1.png')
917 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
921 @imager = ImagerTest.load "abc\ndef\nghi"
922 Picture.any_instance.stub(:store).with(any_args).and_return(true)
923 PettanImager.stub(:load).with(any_args).and_return(@imager)
925 it '画像ライブラリにロードを依頼している' do
926 PettanImager.should_receive(:load).with(any_args).exactly(1)
930 Picture.any_instance.should_receive(:store).with(any_args).exactly(1)
934 context 'つつがなく終わるとき' do
936 Picture.any_instance.stub(:store).with(any_args).and_return(true)
944 context '画像ライブラリのロードに失敗したとき' do
946 PettanImager.stub(:load).and_return(false)
953 context '作成に失敗したとき' do
955 Picture.any_instance.stub(:store).with(any_args).and_return(false)
964 describe 'フラグ展開に於いて' do
966 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id,
967 :settings => "{\"open\": 1, \"commercial\": 2, \"official\": 3, \"attribution\": 4, \"derive\": 5, \"thumbnail\": 6, \"gif_convert\": 7, \"reverse\": 8, \"resize\": 9, \"sync_vh\": 10, \"overlap\": 11}"
969 context 'json展開チェック' do
970 it '展開してなければ展開して@flagsに保管する' do
971 @p.flags.should_not be_nil
975 @p.flags.is_a?(Hash).should be_true
976 @p.flags.empty?.should be_true
979 context 'openについて' do
980 it '@flag_openに保管する' do
981 @p.flag_open.should_not be_nil
983 it '本当にフラグHashからじゃなく、変数から取得してる?' do
986 @p.flag_open.should_not be_nil
989 @p.flag_open.should eq 1
992 context 'commercialについて' do
993 it '@flag_commercialに保管する' do
994 @p.flag_commercial.should_not be_nil
996 it '本当にフラグHashからじゃなく、変数から取得してる?' do
999 @p.flag_commercial.should_not be_nil
1002 @p.flag_commercial.should eq 2
1005 context 'officialについて' do
1006 it '@flag_officialに保管する' do
1007 @p.flag_official.should_not be_nil
1009 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1012 @p.flag_official.should_not be_nil
1015 @p.flag_official.should eq 3
1018 context 'attributionについて' do
1019 it '@flag_attributionに保管する' do
1020 @p.flag_attribution.should_not be_nil
1022 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1025 @p.flag_attribution.should_not be_nil
1028 @p.flag_attribution.should eq 4
1031 context 'deriveについて' do
1032 it '@flag_deriveに保管する' do
1033 @p.flag_derive.should_not be_nil
1035 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1038 @p.flag_derive.should_not be_nil
1041 @p.flag_derive.should eq 5
1044 context 'thumbnailについて' do
1045 it '@flag_thumbnailに保管する' do
1046 @p.flag_thumbnail.should_not be_nil
1048 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1051 @p.flag_thumbnail.should_not be_nil
1054 @p.flag_thumbnail.should eq 6
1057 context 'gif_convertについて' do
1058 it '@flag_gif_convertに保管する' do
1059 @p.flag_gif_convert.should_not be_nil
1061 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1064 @p.flag_gif_convert.should_not be_nil
1067 @p.flag_gif_convert.should eq 7
1070 context 'reverseについて' do
1071 it '@flag_reverseに保管する' do
1072 @p.flag_reverse.should_not be_nil
1074 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1077 @p.flag_reverse.should_not be_nil
1080 @p.flag_reverse.should eq 8
1083 context 'resizeについて' do
1084 it '@flag_resizeに保管する' do
1085 @p.flag_resize.should_not be_nil
1087 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1090 @p.flag_resize.should_not be_nil
1093 @p.flag_resize.should eq 9
1096 context 'sync_vhについて' do
1097 it '@flag_sync_vhに保管する' do
1098 @p.flag_sync_vh.should_not be_nil
1100 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1103 @p.flag_sync_vh.should_not be_nil
1106 @p.flag_sync_vh.should eq 10
1109 context 'overlapについて' do
1110 it '@flag_overlapに保管する' do
1111 @p.flag_overlap.should_not be_nil
1113 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1116 @p.flag_overlap.should_not be_nil
1119 @p.flag_overlap.should eq 11
1124 describe 'クレジットデータに於いて' do
1126 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1127 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :credit => '{"system_picture_id": 2}'
1129 it 'system_picture_idが入っている' do
1130 res = @p.credit_data
1131 res["system_picture_id"].should eq 2
1135 describe 'エクスポートに於いて' do
1137 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1138 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
1139 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
1140 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 1, :updated_at => Time.now + 1000
1142 @old_op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1143 @old_p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @old_op.id, :license_id => @license.id, :revision => 0, :updated_at => Time.now - 1000
1144 @old_rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @old_op.id, :license_id => @license.id, :picture_id => @old_p.id
1146 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
1147 @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
1148 @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
1150 @outer_artist = FactoryGirl.create :artist_yas, :author_id => nil
1151 @outer_op = FactoryGirl.create :original_picture, :artist_id => @outer_artist.id
1152 @outer_p = FactoryGirl.create :picture, :artist_id => @outer_artist.id, :original_picture_id => @outer_op.id, :license_id => @license.id, :revision => 0
1153 @outer_rp = FactoryGirl.create :resource_picture, :artist_id => @outer_artist.id, :original_picture_id => @outer_op.id, :license_id => @license.id, :picture_id => @outer_p.id
1155 context 'つつがなく終わるとき' do
1156 it '開始日時が省略された場合はすべての内実素材を返す' do
1158 r.should eq [@p2, @other_p, @p, @old_p]
1160 it '開始日時以降に更新された内実素材を返す' do
1161 r = Picture.export @p.updated_at - 100
1162 r.should eq [@p2, @other_p, @p]
1167 describe 'リストのjson化に於いて' do
1169 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1170 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
1171 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
1172 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
1173 @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
1174 @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
1175 Picture.any_instance.stub(:restore).with(any_args).and_return('picture binary data')
1177 context 'つつがなく終わるとき' do
1179 r = Picture.list_as_json_text Picture.all
1182 }.should_not raise_error(JSON::ParserError)
1185 r = Picture.list_as_json_text Picture.all
1189 it '各実素材に画像データを添えて返す' do
1190 r = Picture.list_as_json_text Picture.all
1192 j.first['picture_data'].should_not be_nil
1193 j.last['picture_data'].should_not be_nil