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
211 describe '上書き補充に於いて' do
213 attr = {:ext => 'jpeg', :width => 264, :height => 265, :filesize => 266,
214 :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id,
215 :artist_name => 'tester', :classname => 'Tester', :credit => {:title => 'cap'}.to_json.to_s, :settings => {:set => 1}.to_json.to_s}
216 @rp = FactoryGirl.build :resource_picture, attr
217 @p = FactoryGirl.build :picture, :original_picture_id => nil, :license_id => nil, :artist_id => nil, :revision => nil
219 it 'width, height, ext, filesize, md5, original_picture_idが設定されている' do
221 @p.width.should eq 264
222 @p.height.should eq 265
223 @p.ext.should eq 'jpeg'
224 @p.filesize.should eq 266
225 @p.md5.should eq @rp.md5
226 @p.original_picture_id.should eq @op.id
228 it 'license_id, artist_id, artist_name, classname, credit, settingsが設定されている' do
230 @p.license_id.should eq @license.id
231 @p.artist_id.should eq @artist.id
232 @p.artist_name.should eq 'tester'
233 @p.classname.should eq 'Tester'
234 @p.credit.should match /title/
235 @p.settings.should match /set/
237 it 'new_revisionに問い合わせている' do
238 Picture.any_instance.stub(:new_revision).with(any_args).and_return(3)
239 Picture.any_instance.should_receive(:new_revision).with(any_args).exactly(1)
242 it 'revisionは、new_revisionに設定されている' do
243 Picture.any_instance.stub(:new_revision).with(any_args).and_return(3)
245 @p.revision.should eq 3
249 describe '所持判定に於いて' do
251 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
253 context 'パラメータが作家のとき' do
255 @p.own?(@author).should == true
258 @p.own?(@other_author).should == false
261 context 'パラメータが絵師のとき' do
263 @p.own?(@artist).should == true
266 @p.own?(@other_artist).should == false
271 @p.own?(nil).should == false
275 describe '閲覧許可に於いて' do
277 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
280 r = @p.visible?(@artist)
285 describe '詳細閲覧許可に於いて' do
287 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
290 Picture.any_instance.stub(:own?).with(any_args).and_return(true)
291 @p.showable?(@artist).should == true
293 context '他人の実素材のとき' do
295 Picture.any_instance.stub(:own?).with(any_args).and_return(false)
297 it '自身にhead判定と有効性判定を問い合わせ、両者がTrueならTrueを返す。' do
298 Picture.any_instance.stub(:head?).with(any_args).and_return(true)
299 Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
300 r = @p.showable?(@artist)
303 it 'head判定がFalseならFalseを返す。' do
304 Picture.any_instance.stub(:head?).with(any_args).and_return(false)
305 Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
306 r = @p.showable?(@artist)
309 it '有効性判定がFalseならFalseを返す。' do
310 Picture.any_instance.stub(:enable?).with(any_args).and_return(false)
311 Picture.any_instance.stub(:head?).with(any_args).and_return(true)
312 r = @p.showable?(@artist)
318 describe 'ファイル名に於いて' do
320 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
322 it 'id+拡張子のフォーマットで返す' do
324 r.should eq "#{@p.id}.png"
328 describe 'gifファイル名に於いて' do
330 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'gif'
332 it 'id.gifのフォーマットで返す' do
334 r.should eq "#{@p.id}.gif"
338 describe 'MimeTypeに於いて' do
340 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
342 it 'image/拡張子のフォーマットで返す' do
344 r.should eq "image/png"
348 describe 'ファイルのurlに於いて' do
350 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
351 Picture.any_instance.stub(:filename).and_return('3.gif')
353 it 'ファイル名取得を依頼している' do
354 Picture.any_instance.should_receive(:filename).exactly(1)
357 it '/pictures/3.gifのフォーマットで返す' do
359 r.should eq "/pictures/3.gif"
363 describe '最新Revision取得に於いて' do
364 context '初めての原画を公開したとき' do
366 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
368 it 'Revisionは1となる' do
369 @p.new_revision.should eq 1
372 context 'HEADが1のとき' do
374 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
375 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
377 it 'Revisionは2となる' do
378 @p.new_revision.should eq 2
381 context 'HEADが5のとき' do
383 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
384 FactoryGirl.create :picture, :revision => 5, :original_picture_id => @op.id, :license_id => @license.id
385 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
387 it 'Revisionは6となる' do
388 @p.new_revision.should eq 6
393 describe '有効性判定に於いて' do
395 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
396 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
397 Picture.any_instance.stub(:head).and_return(@p)
399 context '自身のheadとリンクした素材があるとき' do
401 Picture.any_instance.stub(:resource_picture).and_return(@rp)
408 context '自身のheadとリンクした素材がないとき' do
410 Picture.any_instance.stub(:resource_picture).and_return(nil)
419 describe 'head取得に於いて' do
422 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
423 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
424 :original_picture_id => @op.id, :md5 => 'a' * 32
426 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
427 :original_picture_id => @op.id, :md5 => 'b' * 32
429 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
430 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
431 :original_picture_id => @op2.id, :md5 => 'C' * 32
433 context 'つつがなく終わるとき' do
436 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
443 context '無効な素材(素材とリンクしてない)とき' do
451 describe 'head判定に於いて' do
454 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
455 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
456 :original_picture_id => @op.id, :md5 => 'a' * 32
458 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
459 :original_picture_id => @op.id, :md5 => 'b' * 32
460 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
476 describe 'フォーマット変換対象判定に於いて' do
478 @p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
481 it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do
482 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
484 @p.to_gif?.should be_true
487 context '変換しないケース' do
488 it '画像フォーマットがpngでない' do
489 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
491 @p.to_gif?.should be_false
494 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)
496 @p.to_gif?.should be_false
501 describe 'サブディレクトリリストに於いて' do
503 @p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
506 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
508 r.is_a?(Array).should be_true
510 it '本画像(ベースディレクトリ)を含んでいる' do
511 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
513 r.include?('').should be_true
515 context '反転が許可されているとき' do
516 it '垂直・水平・垂直水平反転ディレクトリも返す' do
517 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
519 r.include?('v').should be_true
520 r.include?('h').should be_true
521 r.include?('vh').should be_true
524 context '反転が許可されていないとき' do
525 it '本画像(ベースディレクトリ)だけを返す' do
526 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
533 describe 'md5検索に於いて' do
535 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
536 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
537 :original_picture_id => @op.id, :md5 => 'a' * 32
538 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
539 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
540 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
541 :original_picture_id => @op2.id, :md5 => 'b' * 32
542 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
545 res = Picture.find_by_md5(@p.md5)
546 res.is_a?(Array).should be_true
549 res = Picture.find_by_md5(@p.md5)
550 res.include?(@p2).should be_false
553 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
554 :original_picture_id => @op2.id, :md5 => 'C' * 32
555 @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
556 :original_picture_id => @op3.id, :md5 => @p3.md5, :updated_at => Time.now + 100
557 res = Picture.find_by_md5(@p3.md5)
558 res.should eq [@p4, @p3]
562 describe 'md5重複リストに於いて' do
564 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
565 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
566 :original_picture_id => @op.id, :md5 => 'a' * 32
567 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
568 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
569 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
570 :original_picture_id => @op2.id, :md5 => 'b' * 32
571 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
574 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
575 res.is_a?(Array).should be_true
578 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
579 res.include?(@p2).should be_false
582 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
583 res.empty?.should be_true
585 it '同一原画は旧版でも含まない' do
586 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
587 :original_picture_id => @op.id, :md5 => 'a' * 32
588 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
589 res.empty?.should be_true
592 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
593 :original_picture_id => @op2.id, :md5 => 'a' * 32
594 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
597 it '他所の原画でもmd5が違えば含まない' do
598 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
599 :original_picture_id => @op2.id, :md5 => 'c' * 32
600 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
601 res.empty?.should be_true
604 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
605 :original_picture_id => @op2.id, :md5 => 'a' * 32
606 @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
607 :original_picture_id => @op3.id, :md5 => 'a' * 32, :updated_at => Time.now + 100
608 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
609 res.should eq [@p4, @p3]
613 describe 'md5重複判定に於いて' do
615 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
616 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
617 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
618 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
620 context '同一原画以外に同じ値があるとき' do
622 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license.id
625 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
629 context '同一原画以外に同じ値がないとき' do
631 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
635 context '同一原画に同じ値があるとき' do
637 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 1
640 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
646 describe '単体取得に於いて' do
648 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
650 context 'つつがなく終わるとき' do
651 it '閲覧許可を問い合わせている' do
652 Picture.any_instance.stub(:visible?).with(any_args).and_return(true)
653 Picture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
654 r = Picture.show @p.id, @author
658 r = Picture.show @p.id, @author
661 context '他人の実素材を開こうとしたとき' do
662 it '403Forbidden例外を返す' do
663 Picture.any_instance.stub(:visible?).and_return(false)
665 r = Picture.show @p.id, @other_author
666 }.should raise_error(ActiveRecord::Forbidden)
669 context '存在しない実素材を開こうとしたとき' do
670 it '404RecordNotFound例外を返す' do
672 r = Picture.show 0, @author
673 }.should raise_error(ActiveRecord::RecordNotFound)
680 @imager = ImagerTest.load "abc\ndef\nghi"
681 #原画ファイル削除だけは必ず成功するものとしておく
682 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
686 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
687 #それで外部のメソッド呼び出しだけに着目してテストする。
688 Picture.any_instance.stub(:save).with(any_args).and_return(true)
689 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
690 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
691 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
694 Picture.any_instance.should_receive(:save).with(any_args).exactly(1)
695 r = @p.store(@imager)
697 it '画像ファイルの作成機能で画像を保存している' do
698 Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
700 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(2)
701 r = @p.store(@imager)
703 it '自身にgifフォーマット変換対象かを問い合わせている' do
704 Picture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
705 r = @p.store(@imager)
708 context 'つつがなく終わるとき' do
710 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
711 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
712 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
713 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
716 r = @p.store(@imager)
721 r = @p.store(@imager)
722 }.should change Picture, :count
725 context 'gif変換なしで、つつがなく終わるとき' do
727 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
728 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
729 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(false)
730 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
733 r = @p.store(@imager)
736 it 'gif保存は呼ばれていない' do
737 #二回目の画像作成が呼び出されないで1回こっきりならgif保存は呼ばれていないんだろう。
738 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
739 r = @p.store(@imager)
742 #以下から例外ケース。処理先頭から失敗させていく
743 context '自身の保存に失敗したとき' do
745 Picture.any_instance.stub(:save).with(any_args).and_return(false)
746 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
749 r = @p.store(@imager)
753 r = @p.store(@imager)
754 @p.should be_a_new Picture
757 context '画像の保存に失敗したとき' do
759 Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)
760 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
763 r = @p.store(@imager)
766 it 'gif変換判定は呼ばれていない' do
767 Picture.any_instance.should_not_receive(:to_gif?).with(any_args).exactly(0)
768 r = @p.store(@imager)
771 context 'gif変換に失敗したとき' do
773 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
774 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
775 ImagerTest.stub(:load).with(any_args).and_return(false)
776 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
779 r = @p.store(@imager)
782 it 'gif画像の保存は呼ばれていない' do
784 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
785 r = @p.store(@imager)
788 context 'gif画像の保存に失敗したとき' do
790 @gifimager = @imager.to_gif
791 ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(@gifimager)
792 Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
793 Picture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
794 Picture.any_instance.stub(:store_picture).with(@imager, '1.png').and_return(true)
795 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
796 Picture.any_instance.stub(:store_picture).with(@gifimager, '1.gif').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)
806 describe '画像ファイルの作成に於いて' do
807 #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。
809 @imager = ImagerTest.load "abc\ndef\nghi"
810 #原画ファイル削除だけは必ず成功するものとしておく
811 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
813 Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])
814 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
818 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
819 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
821 it '画像ファイルの保存が4回呼ばれる' do
822 PictureIO.picture_io.should_receive(:put).with(any_args).exactly(4)
823 r = @p.store_picture(@imager, '1.png')
825 it '画像ファイルのベースへの保存が1回呼ばれる' do
826 PictureIO.picture_io.should_receive(:put).with("abc\ndef\nghi", '1.png', '').exactly(1)
827 r = @p.store_picture(@imager, '1.png')
829 it '画像ファイルの垂直反転への保存が1回呼ばれる' do
830 PictureIO.picture_io.should_receive(:put).with("cba\nfed\nihg", '1.png', 'v').exactly(1)
831 r = @p.store_picture(@imager, '1.png')
833 it '画像ファイルの水平反転への保存が1回呼ばれる' do
834 PictureIO.picture_io.should_receive(:put).with("ghi\ndef\nabc", '1.png', 'h').exactly(1)
835 r = @p.store_picture(@imager, '1.png')
837 it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do
838 PictureIO.picture_io.should_receive(:put).with("ihg\nfed\ncba", '1.png', 'vh').exactly(1)
839 r = @p.store_picture(@imager, '1.png')
842 context 'つつがなく終わるとき' do
844 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
845 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
848 r = @p.store_picture(@imager, '1.png')
854 PictureIO.picture_io.stub(:put).with(any_args).and_return(false)
857 r = @p.store_picture(@imager, '1.png')
864 describe 'フラグ展開に於いて' do
866 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id,
867 :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}"
869 context 'json展開チェック' do
870 it '展開してなければ展開して@flagsに保管する' do
871 @p.flags.should_not be_nil
875 @p.flags.is_a?(Hash).should be_true
876 @p.flags.empty?.should be_true
879 context 'openについて' do
880 it '@flag_openに保管する' do
881 @p.flag_open.should_not be_nil
883 it '本当にフラグHashからじゃなく、変数から取得してる?' do
886 @p.flag_open.should_not be_nil
889 @p.flag_open.should eq 1
892 context 'commercialについて' do
893 it '@flag_commercialに保管する' do
894 @p.flag_commercial.should_not be_nil
896 it '本当にフラグHashからじゃなく、変数から取得してる?' do
899 @p.flag_commercial.should_not be_nil
902 @p.flag_commercial.should eq 2
905 context 'officialについて' do
906 it '@flag_officialに保管する' do
907 @p.flag_official.should_not be_nil
909 it '本当にフラグHashからじゃなく、変数から取得してる?' do
912 @p.flag_official.should_not be_nil
915 @p.flag_official.should eq 3
918 context 'attributionについて' do
919 it '@flag_attributionに保管する' do
920 @p.flag_attribution.should_not be_nil
922 it '本当にフラグHashからじゃなく、変数から取得してる?' do
925 @p.flag_attribution.should_not be_nil
928 @p.flag_attribution.should eq 4
931 context 'deriveについて' do
932 it '@flag_deriveに保管する' do
933 @p.flag_derive.should_not be_nil
935 it '本当にフラグHashからじゃなく、変数から取得してる?' do
938 @p.flag_derive.should_not be_nil
941 @p.flag_derive.should eq 5
944 context 'thumbnailについて' do
945 it '@flag_thumbnailに保管する' do
946 @p.flag_thumbnail.should_not be_nil
948 it '本当にフラグHashからじゃなく、変数から取得してる?' do
951 @p.flag_thumbnail.should_not be_nil
954 @p.flag_thumbnail.should eq 6
957 context 'gif_convertについて' do
958 it '@flag_gif_convertに保管する' do
959 @p.flag_gif_convert.should_not be_nil
961 it '本当にフラグHashからじゃなく、変数から取得してる?' do
964 @p.flag_gif_convert.should_not be_nil
967 @p.flag_gif_convert.should eq 7
970 context 'reverseについて' do
971 it '@flag_reverseに保管する' do
972 @p.flag_reverse.should_not be_nil
974 it '本当にフラグHashからじゃなく、変数から取得してる?' do
977 @p.flag_reverse.should_not be_nil
980 @p.flag_reverse.should eq 8
983 context 'resizeについて' do
984 it '@flag_resizeに保管する' do
985 @p.flag_resize.should_not be_nil
987 it '本当にフラグHashからじゃなく、変数から取得してる?' do
990 @p.flag_resize.should_not be_nil
993 @p.flag_resize.should eq 9
996 context 'sync_vhについて' do
997 it '@flag_sync_vhに保管する' do
998 @p.flag_sync_vh.should_not be_nil
1000 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1003 @p.flag_sync_vh.should_not be_nil
1006 @p.flag_sync_vh.should eq 10
1009 context 'overlapについて' do
1010 it '@flag_overlapに保管する' do
1011 @p.flag_overlap.should_not be_nil
1013 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1016 @p.flag_overlap.should_not be_nil
1019 @p.flag_overlap.should eq 11
1024 describe 'クレジットデータに於いて' do
1026 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1027 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :credit => '{"system_picture_id": 2}'
1029 it 'system_picture_idが入っている' do
1030 res = @p.credit_data
1031 res["system_picture_id"].should eq 2