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
254 it '自身にロールリストからの絵師取得を依頼している' do
255 Picture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)
256 r = @p.own?([@artist])
259 context 'ロール内絵師が取得できるとき' do
262 it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do
263 Picture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)
264 r = @p.own?([@artist])
267 it 'ロール内絵師のidが自身の絵師idと一致しないならno' do
268 Picture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)
269 @p.own?(@other_artist).should be_false
272 context 'ロール内絵師が取得できないとき' do
274 Picture.stub(:get_artist_from_roles).with(any_args).and_return(nil)
277 r = @p.own?([@artist])
283 describe '閲覧許可に於いて' do
285 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
288 r = @p.visible?(@artist)
293 describe '詳細閲覧許可に於いて' do
295 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
297 context '自身に原画がリンクしていないとき' do
299 Picture.any_instance.stub(:original_picture).with(any_args).and_return(nil)
302 r = @p.showable?(@author)
307 Picture.any_instance.stub(:own?).with(any_args).and_return(true)
308 @p.showable?(@artist).should == true
310 context '他人の実素材のとき' do
312 Picture.any_instance.stub(:own?).with(any_args).and_return(false)
314 it '自身にhead判定と有効性判定を問い合わせ、両者がTrueならTrueを返す。' do
315 Picture.any_instance.stub(:head?).with(any_args).and_return(true)
316 Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
317 r = @p.showable?(@author)
320 it 'head判定がFalseならFalseを返す。' do
321 Picture.any_instance.stub(:head?).with(any_args).and_return(false)
322 Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
323 r = @p.showable?(@author)
326 it '有効性判定がFalseならFalseを返す。' do
327 Picture.any_instance.stub(:enable?).with(any_args).and_return(false)
328 Picture.any_instance.stub(:head?).with(any_args).and_return(true)
329 r = @p.showable?(@author)
335 describe 'ファイル名に於いて' do
337 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
339 it 'id+拡張子のフォーマットで返す' do
341 r.should eq "#{@p.id}.png"
345 describe 'gifファイル名に於いて' do
347 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'gif'
349 it 'id.gifのフォーマットで返す' do
351 r.should eq "#{@p.id}.gif"
355 describe 'MimeTypeに於いて' do
357 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
359 it 'image/拡張子のフォーマットで返す' do
361 r.should eq "image/png"
365 describe 'ファイルのurlに於いて' do
367 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
368 Picture.any_instance.stub(:filename).and_return('3.gif')
370 it 'ファイル名取得を依頼している' do
371 Picture.any_instance.should_receive(:filename).exactly(1)
374 it '/pictures/3.gifのフォーマットで返す' do
376 r.should eq "/pictures/3.gif"
380 describe '最新Revision取得に於いて' do
381 context '初めての原画を公開したとき' do
383 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
385 it 'Revisionは1となる' do
386 @p.new_revision.should eq 1
389 context 'HEADが1のとき' do
391 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
392 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
394 it 'Revisionは2となる' do
395 @p.new_revision.should eq 2
398 context 'HEADが5のとき' do
400 FactoryGirl.create :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
401 FactoryGirl.create :picture, :revision => 5, :original_picture_id => @op.id, :license_id => @license.id
402 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
404 it 'Revisionは6となる' do
405 @p.new_revision.should eq 6
410 describe '有効性判定に於いて' do
412 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
413 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
414 Picture.any_instance.stub(:head).and_return(@p)
416 context '自身のheadとリンクした素材があるとき' do
418 Picture.any_instance.stub(:resource_picture).and_return(@rp)
425 context '自身のheadとリンクした素材がないとき' do
427 Picture.any_instance.stub(:resource_picture).and_return(nil)
436 describe 'head取得に於いて' do
439 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
440 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
441 :original_picture_id => @op.id, :md5 => 'a' * 32
443 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
444 :original_picture_id => @op.id, :md5 => 'b' * 32
446 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
447 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
448 :original_picture_id => @op2.id, :md5 => 'C' * 32
450 context 'つつがなく終わるとき' do
453 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
460 context '無効な素材(素材とリンクしてない)とき' do
468 describe 'head判定に於いて' do
471 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
472 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
473 :original_picture_id => @op.id, :md5 => 'a' * 32
475 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
476 :original_picture_id => @op.id, :md5 => 'b' * 32
477 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
493 describe 'フォーマット変換対象判定に於いて' do
495 @p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
498 it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do
499 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
501 @p.to_gif?.should be_true
504 context '変換しないケース' do
505 it '画像フォーマットがpngでない' do
506 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
508 @p.to_gif?.should be_false
511 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)
513 @p.to_gif?.should be_false
518 describe 'サブディレクトリリストに於いて' do
520 @p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
523 Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
525 r.is_a?(Array).should be_true
527 it '本画像(ベースディレクトリ)を含んでいる' do
528 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
530 r.include?('').should be_true
532 context '反転が許可されているとき' do
533 it '垂直・水平・垂直水平反転ディレクトリも返す' do
534 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
536 r.include?('v').should be_true
537 r.include?('h').should be_true
538 r.include?('vh').should be_true
541 context '反転が許可されていないとき' do
542 it '本画像(ベースディレクトリ)だけを返す' do
543 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
550 describe 'md5重複リストに於いて' do
552 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
553 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
554 :original_picture_id => @op.id, :md5 => 'a' * 32
555 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
556 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
557 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
558 :original_picture_id => @op2.id, :md5 => 'b' * 32
559 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
561 context '除外する原画idで指定されていないとき' do
563 res = Picture.list_by_md5(@p.md5)
564 res.is_a?(Array).should be_true
567 res = Picture.list_by_md5(@p.md5)
568 res.include?(@p2).should be_false
571 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
572 :original_picture_id => @op2.id, :md5 => 'C' * 32
573 @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
574 :original_picture_id => @op3.id, :md5 => @p3.md5, :updated_at => Time.now + 100
575 res = Picture.find_by_md5(@p3.md5)
576 res.should eq [@p4, @p3]
579 context '除外する原画idで指定されたとき' do
581 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
582 res.is_a?(Array).should be_true
585 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
586 res.include?(@p2).should be_false
589 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
590 res.empty?.should be_true
592 it '同一原画は旧版でも含まない' do
593 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
594 :original_picture_id => @op.id, :md5 => 'a' * 32
595 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
596 res.empty?.should be_true
599 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
600 :original_picture_id => @op2.id, :md5 => 'a' * 32
601 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
604 it '他所の原画でもmd5が違えば含まない' do
605 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
606 :original_picture_id => @op2.id, :md5 => 'c' * 32
607 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
608 res.empty?.should be_true
611 @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
612 :original_picture_id => @op2.id, :md5 => 'a' * 32
613 @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
614 :original_picture_id => @op3.id, :md5 => 'a' * 32, :updated_at => Time.now + 100
615 res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
616 res.should eq [@p4, @p3]
621 describe 'md5重複判定に於いて' do
623 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
624 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
625 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
626 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
628 context '同一原画以外に同じ値があるとき' do
630 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license.id
633 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
637 context '同一原画以外に同じ値がないとき' do
639 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
643 context '同一原画に同じ値があるとき' do
645 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 1
648 res = Picture.exist_by_md5(@p.md5, @p.original_picture_id)
654 describe '単体取得に於いて' do
656 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
658 context 'つつがなく終わるとき' do
659 it '閲覧許可を問い合わせている' do
660 Picture.any_instance.stub(:visible?).with(any_args).and_return(true)
661 Picture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
662 r = Picture.show @p.id, @author
666 r = Picture.show @p.id, @author
669 context '他人の実素材を開こうとしたとき' do
670 it '403Forbidden例外を返す' do
671 Picture.any_instance.stub(:visible?).and_return(false)
673 r = Picture.show @p.id, @other_author
674 }.should raise_error(ActiveRecord::Forbidden)
677 context '存在しない実素材を開こうとしたとき' do
678 it '404RecordNotFound例外を返す' do
680 r = Picture.show 0, @author
681 }.should raise_error(ActiveRecord::RecordNotFound)
688 @imager = ImagerTest.load "abc\ndef\nghi"
689 #原画ファイル削除だけは必ず成功するものとしておく
690 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
694 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
695 #それで外部のメソッド呼び出しだけに着目してテストする。
696 Picture.any_instance.stub(:save).with(any_args).and_return(true)
697 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
698 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
699 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
702 Picture.any_instance.should_receive(:save).with(any_args).exactly(1)
703 r = @p.store(@imager)
705 it '画像ファイルの作成機能で画像を保存している' do
706 Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
708 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(2)
709 r = @p.store(@imager)
711 it '自身にgifフォーマット変換対象かを問い合わせている' do
712 Picture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
713 r = @p.store(@imager)
716 context 'つつがなく終わるとき' do
718 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
719 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
720 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
721 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
724 r = @p.store(@imager)
729 r = @p.store(@imager)
730 }.should change Picture, :count
733 context 'gif変換なしで、つつがなく終わるとき' do
735 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
736 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
737 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(false)
738 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
741 r = @p.store(@imager)
744 it 'gif保存は呼ばれていない' do
745 #二回目の画像作成が呼び出されないで1回こっきりならgif保存は呼ばれていないんだろう。
746 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
747 r = @p.store(@imager)
750 #以下から例外ケース。処理先頭から失敗させていく
751 context '自身の保存に失敗したとき' do
753 Picture.any_instance.stub(:save).with(any_args).and_return(false)
754 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
757 r = @p.store(@imager)
761 r = @p.store(@imager)
762 @p.should be_a_new Picture
765 context '画像の保存に失敗したとき' do
767 Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)
768 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
771 r = @p.store(@imager)
774 it 'gif変換判定は呼ばれていない' do
775 Picture.any_instance.should_not_receive(:to_gif?).with(any_args).exactly(0)
776 r = @p.store(@imager)
779 context 'gif変換に失敗したとき' do
781 Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
782 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
783 ImagerTest.stub(:load).with(any_args).and_return(false)
784 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
787 r = @p.store(@imager)
790 it 'gif画像の保存は呼ばれていない' do
792 Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
793 r = @p.store(@imager)
796 context 'gif画像の保存に失敗したとき' do
798 @gifimager = @imager.to_gif
799 ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(@gifimager)
800 Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
801 Picture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
802 Picture.any_instance.stub(:store_picture).with(@imager, '1.png').and_return(true)
803 Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
804 Picture.any_instance.stub(:store_picture).with(@gifimager, '1.gif').and_return(false)
805 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
808 r = @p.store(@imager)
814 describe '画像ファイルの作成に於いて' do
815 #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。
817 @imager = ImagerTest.load "abc\ndef\nghi"
818 #原画ファイル削除だけは必ず成功するものとしておく
819 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
821 Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])
822 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
826 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
827 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
829 it '画像ファイルの保存が4回呼ばれる' do
830 PictureIO.picture_io.should_receive(:put).with(any_args).exactly(4)
831 r = @p.store_picture(@imager, '1.png')
833 it '画像ファイルのベースへの保存が1回呼ばれる' do
834 PictureIO.picture_io.should_receive(:put).with("abc\ndef\nghi", '1.png', '').exactly(1)
835 r = @p.store_picture(@imager, '1.png')
837 it '画像ファイルの垂直反転への保存が1回呼ばれる' do
838 PictureIO.picture_io.should_receive(:put).with("cba\nfed\nihg", '1.png', 'v').exactly(1)
839 r = @p.store_picture(@imager, '1.png')
841 it '画像ファイルの水平反転への保存が1回呼ばれる' do
842 PictureIO.picture_io.should_receive(:put).with("ghi\ndef\nabc", '1.png', 'h').exactly(1)
843 r = @p.store_picture(@imager, '1.png')
845 it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do
846 PictureIO.picture_io.should_receive(:put).with("ihg\nfed\ncba", '1.png', 'vh').exactly(1)
847 r = @p.store_picture(@imager, '1.png')
850 context 'つつがなく終わるとき' do
852 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
853 PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
856 r = @p.store_picture(@imager, '1.png')
862 PictureIO.picture_io.stub(:put).with(any_args).and_return(false)
865 r = @p.store_picture(@imager, '1.png')
874 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
878 @imager = ImagerTest.load "abc\ndef\nghi"
879 Picture.any_instance.stub(:store).with(any_args).and_return(true)
880 PettanImager.stub(:load).with(any_args).and_return(@imager)
882 it '画像ライブラリにロードを依頼している' do
883 PettanImager.should_receive(:load).with(any_args).exactly(1)
887 Picture.any_instance.should_receive(:store).with(any_args).exactly(1)
891 context 'つつがなく終わるとき' do
893 Picture.any_instance.stub(:store).with(any_args).and_return(true)
901 context '画像ライブラリのロードに失敗したとき' do
903 PettanImager.stub(:load).and_return(false)
910 context '作成に失敗したとき' do
912 Picture.any_instance.stub(:store).with(any_args).and_return(false)
921 describe 'フラグ展開に於いて' do
923 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id,
924 :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}"
926 context 'json展開チェック' do
927 it '展開してなければ展開して@flagsに保管する' do
928 @p.flags.should_not be_nil
932 @p.flags.is_a?(Hash).should be_true
933 @p.flags.empty?.should be_true
936 context 'openについて' do
937 it '@flag_openに保管する' do
938 @p.flag_open.should_not be_nil
940 it '本当にフラグHashからじゃなく、変数から取得してる?' do
943 @p.flag_open.should_not be_nil
946 @p.flag_open.should eq 1
949 context 'commercialについて' do
950 it '@flag_commercialに保管する' do
951 @p.flag_commercial.should_not be_nil
953 it '本当にフラグHashからじゃなく、変数から取得してる?' do
956 @p.flag_commercial.should_not be_nil
959 @p.flag_commercial.should eq 2
962 context 'officialについて' do
963 it '@flag_officialに保管する' do
964 @p.flag_official.should_not be_nil
966 it '本当にフラグHashからじゃなく、変数から取得してる?' do
969 @p.flag_official.should_not be_nil
972 @p.flag_official.should eq 3
975 context 'attributionについて' do
976 it '@flag_attributionに保管する' do
977 @p.flag_attribution.should_not be_nil
979 it '本当にフラグHashからじゃなく、変数から取得してる?' do
982 @p.flag_attribution.should_not be_nil
985 @p.flag_attribution.should eq 4
988 context 'deriveについて' do
989 it '@flag_deriveに保管する' do
990 @p.flag_derive.should_not be_nil
992 it '本当にフラグHashからじゃなく、変数から取得してる?' do
995 @p.flag_derive.should_not be_nil
998 @p.flag_derive.should eq 5
1001 context 'thumbnailについて' do
1002 it '@flag_thumbnailに保管する' do
1003 @p.flag_thumbnail.should_not be_nil
1005 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1008 @p.flag_thumbnail.should_not be_nil
1011 @p.flag_thumbnail.should eq 6
1014 context 'gif_convertについて' do
1015 it '@flag_gif_convertに保管する' do
1016 @p.flag_gif_convert.should_not be_nil
1018 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1021 @p.flag_gif_convert.should_not be_nil
1024 @p.flag_gif_convert.should eq 7
1027 context 'reverseについて' do
1028 it '@flag_reverseに保管する' do
1029 @p.flag_reverse.should_not be_nil
1031 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1034 @p.flag_reverse.should_not be_nil
1037 @p.flag_reverse.should eq 8
1040 context 'resizeについて' do
1041 it '@flag_resizeに保管する' do
1042 @p.flag_resize.should_not be_nil
1044 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1047 @p.flag_resize.should_not be_nil
1050 @p.flag_resize.should eq 9
1053 context 'sync_vhについて' do
1054 it '@flag_sync_vhに保管する' do
1055 @p.flag_sync_vh.should_not be_nil
1057 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1060 @p.flag_sync_vh.should_not be_nil
1063 @p.flag_sync_vh.should eq 10
1066 context 'overlapについて' do
1067 it '@flag_overlapに保管する' do
1068 @p.flag_overlap.should_not be_nil
1070 it '本当にフラグHashからじゃなく、変数から取得してる?' do
1073 @p.flag_overlap.should_not be_nil
1076 @p.flag_overlap.should eq 11
1081 describe 'クレジットデータに於いて' do
1083 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1084 @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :credit => '{"system_picture_id": 2}'
1086 it 'system_picture_idが入っている' do
1087 res = @p.credit_data
1088 res["system_picture_id"].should eq 2
1092 describe 'エクスポートに於いて' do
1094 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1095 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
1096 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
1097 @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 1, :updated_at => Time.now + 1000
1099 @old_op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1100 @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
1101 @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
1103 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
1104 @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
1105 @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
1107 @outer_artist = FactoryGirl.create :artist_yas, :author_id => nil
1108 @outer_op = FactoryGirl.create :original_picture, :artist_id => @outer_artist.id
1109 @outer_p = FactoryGirl.create :picture, :artist_id => @outer_artist.id, :original_picture_id => @outer_op.id, :license_id => @license.id, :revision => 0
1110 @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
1112 context 'つつがなく終わるとき' do
1113 it '開始日時が省略された場合はすべての内実素材を返す' do
1115 r.should eq [@p2, @other_p, @p, @old_p]
1117 it '開始日時以降に更新された内実素材を返す' do
1118 r = Picture.export @p.updated_at - 100
1119 r.should eq [@p2, @other_p, @p]
1124 describe 'リストのjson化に於いて' do
1126 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1127 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
1128 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
1129 @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
1130 @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
1131 @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
1132 Picture.any_instance.stub(:restore).with(any_args).and_return('picture binary data')
1134 context 'つつがなく終わるとき' do
1136 r = Picture.list_as_json_text Picture.all
1139 }.should_not raise_error(JSON::ParserError)
1142 r = Picture.list_as_json_text Picture.all
1146 it '各実素材に画像データを添えて返す' do
1147 r = Picture.list_as_json_text Picture.all
1149 j.first['picture_data'].should_not be_nil
1150 j.last['picture_data'].should_not be_nil