1 # -*- encoding: utf-8 -*-
\r
3 require 'spec_helper'
\r
5 describe ResourcePicture do
\r
7 @admin = FactoryGirl.create :admin
\r
8 @user = FactoryGirl.create( :user_yas)
\r
9 @author = FactoryGirl.create :author, :user_id => @user.id
\r
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
\r
11 @other_user = FactoryGirl.create( :user_yas)
\r
12 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
\r
13 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
\r
14 @sp = FactoryGirl.create :system_picture
\r
15 @lg = FactoryGirl.create :license_group
\r
16 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
\r
17 @original_picture = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
19 #原画ファイル削除だけは必ず成功するものとしておく
\r
20 PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
\r
21 Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])
\r
22 Picture.any_instance.stub(:h).with(any_args).and_return('data')
\r
23 Picture.any_instance.stub(:v).with(any_args).and_return('data')
\r
24 Picture.any_instance.stub(:vh).with(any_args).and_return('data')
\r
27 describe '検証に於いて' do
\r
29 @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
\r
30 @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
\r
33 context 'オーソドックスなデータのとき' do
\r
35 @rp.ext = 'png' #リストにない拡張子は通らないし
\r
40 @rp.classname = 'a'*1
\r
47 @rp.filesize = 2000000
\r
49 @rp.classname = 'a'*50
\r
54 context 'extを検証するとき' do
\r
57 @rp.should_not be_valid
\r
61 @rp.should_not be_valid
\r
63 it 'png,gif,jpeg以外なら失敗する' do
\r
65 @rp.should_not be_valid
\r
68 context 'widthを検証するとき' do
\r
71 @rp.should_not be_valid
\r
75 @rp.should_not be_valid
\r
79 @rp.should_not be_valid
\r
83 @rp.should_not be_valid
\r
86 context 'heightを検証するとき' do
\r
89 @rp.should_not be_valid
\r
93 @rp.should_not be_valid
\r
97 @rp.should_not be_valid
\r
101 @rp.should_not be_valid
\r
104 context 'filesizeを検証するとき' do
\r
107 @rp.should_not be_valid
\r
109 it '数値でなければ失敗する' do
\r
111 @rp.should_not be_valid
\r
114 @rp.filesize = '-1'
\r
115 @rp.should_not be_valid
\r
117 it '2MB以上なら失敗する' do
\r
118 @rp.filesize = 2000000+1
\r
119 @rp.should_not be_valid
\r
122 context 'artist_idを検証するとき' do
\r
124 @rp.artist_id = nil
\r
125 @rp.should_not be_valid
\r
127 it '数値でなければ失敗する' do
\r
128 @rp.artist_id = 'a'
\r
129 @rp.should_not be_valid
\r
131 it '存在する絵師でなければ失敗する' do
\r
133 @rp.should_not be_valid
\r
136 context 'md5を検証するとき' do
\r
139 @rp.should_not be_valid
\r
143 @rp.should_not be_valid
\r
145 it '32文字以上なら失敗する' do
\r
147 @rp.should_not be_valid
\r
150 context 'license_idを検証するとき' do
\r
152 @rp.license_id = nil
\r
153 @rp.should_not be_valid
\r
155 it '数値でなければ失敗する' do
\r
156 @rp.license_id = 'a'
\r
157 @rp.should_not be_valid
\r
159 it '存在する絵師でなければ失敗する' do
\r
161 @rp.should_not be_valid
\r
164 context 'original_picture_idを検証するとき' do
\r
166 @rp.original_picture_id = nil
\r
167 @rp.should_not be_valid
\r
169 it '数値でなければ失敗する' do
\r
170 @rp.original_picture_id = 'a'
\r
171 @rp.should_not be_valid
\r
173 it '存在する原画でなければ失敗する' do
\r
174 @rp.original_picture_id = 0
\r
175 @rp.should_not be_valid
\r
178 context 'artist_nameを検証するとき' do
\r
180 @rp.artist_name = nil
\r
181 @rp.should_not be_valid
\r
184 context 'classnameを検証するとき' do
\r
187 @rp.should_not be_valid
\r
189 it '51文字以上なら失敗する' do
\r
190 @rp.classname = 'a'*51
\r
191 @rp.should_not be_valid
\r
194 context 'creditを検証するとき' do
\r
196 context 'settingsを検証するとき' do
\r
198 context 'picture_idを検証するとき' do
\r
200 @rp.picture_id = nil
\r
201 @rp.should_not be_valid
\r
203 it '数値でなければ失敗する' do
\r
204 @rp.picture_id = 'a'
\r
205 @rp.should_not be_valid
\r
207 it '存在する実素材でなければ失敗する' do
\r
209 @rp.should_not be_valid
\r
214 describe 'デフォルト値補充に於いて' do
\r
216 @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
\r
217 @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
\r
222 describe '上書き補充に於いて' do
\r
224 @original_picture.attributes = {:ext => 'gif', :width => 267, :height => 268, :filesize => 269,
\r
225 :artist_id => @artist.id }
\r
226 @rp = FactoryGirl.build :resource_picture, :original_picture_id => @original_picture.id
\r
228 it 'width, height, ext, filesize, md5, original_picture_id, artist_idが設定されている' do
\r
229 @rp.overwrite @original_picture
\r
230 @rp.width.should eq 267
\r
231 @rp.height.should eq 268
\r
232 @rp.ext.should eq 'gif'
\r
233 @rp.filesize.should eq 269
\r
234 @rp.md5.should eq @rp.md5
\r
235 @rp.original_picture_id.should eq @original_picture.id
\r
236 @rp.artist_id.should eq @artist.id
\r
240 describe '所持判定に於いて' do
\r
242 @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
\r
243 @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
\r
245 it '素材を更新することはないので、Falseを返す' do
\r
246 @rp.own?(@author).should == false
\r
250 describe '閲覧許可に於いて' do
\r
252 @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
\r
253 @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
\r
255 context '検査対象がnil(ゲスト)のとき' do
\r
256 context 'クローズドモードのとき' do
\r
258 MagicNumber['run_mode'] = 1
\r
261 r = @rp.visible?(nil)
\r
265 context 'オープンモードのとき' do
\r
267 MagicNumber['run_mode'] = 0
\r
270 r = @rp.visible?(nil)
\r
275 context '検査対象が作家のとき' do
\r
277 r = @rp.visible?(@author)
\r
281 context '検査対象がそれ以外のとき' do
\r
283 r = @rp.visible?(@admin)
\r
289 describe 'ファイル名に於いて' do
\r
291 @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
\r
292 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
\r
294 it 'id+拡張子のフォーマットで返す' do
\r
296 r.should eq "#{@rp.id}.png"
\r
300 describe 'MimeTypeに於いて' do
\r
302 @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
\r
303 @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
\r
305 it 'image/拡張子のフォーマットで返す' do
\r
307 r.should eq "image/png"
\r
311 describe 'ファイルのurlに於いて' do
\r
313 @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
\r
314 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
\r
315 ResourcePicture.any_instance.stub(:filename).and_return('3.gif')
\r
317 it 'ファイル名取得を依頼している' do
\r
318 ResourcePicture.any_instance.should_receive(:filename).exactly(1)
\r
321 it '/resource_pictures/3.gifのフォーマットで返す' do
\r
323 r.should eq "/resource_pictures/3.gif"
\r
327 describe '一覧取得に於いて' do
\r
329 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
330 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
331 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
\r
333 context 'page補正について' do
\r
334 it '文字列から数値に変換される' do
\r
335 ResourcePicture.page('8').should eq 8
\r
337 it 'nilの場合は1になる' do
\r
338 ResourcePicture.page().should eq 1
\r
340 it '0以下の場合は1になる' do
\r
341 ResourcePicture.page('0').should eq 1
\r
344 context 'page_size補正について' do
\r
345 it '文字列から数値に変換される' do
\r
346 ResourcePicture.page_size('7').should eq 7
\r
348 it 'nilの場合はResourcePicture.default_page_sizeになる' do
\r
349 ResourcePicture.page_size().should eq ResourcePicture.default_page_size
\r
351 it '0以下の場合はResourcePicture.default_page_sizeになる' do
\r
352 ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size
\r
354 it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do
\r
355 ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size
\r
359 r = ResourcePicture.list
\r
363 nop = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
364 nrp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100
\r
365 r = ResourcePicture.list
\r
366 r.should eq [nrp, @rp]
\r
368 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
370 nop2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
371 @nrp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100
\r
372 nop3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
373 @nrp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200
\r
374 nop4 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
375 @nrp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300
\r
376 nop5 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
377 @nrp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400
\r
378 ResourcePicture.stub(:default_page_size).and_return(2)
\r
381 r = ResourcePicture.list
\r
382 r.should have(2).items
\r
384 it 'page=1なら末尾2件を返す' do
\r
386 r = ResourcePicture.list(1)
\r
387 r.should eq [@nrp5, @nrp4]
\r
389 it 'page=2なら中間2件を返す' do
\r
390 r = ResourcePicture.list(2)
\r
391 r.should eq [@nrp3, @nrp2]
\r
393 it 'page=3なら先頭1件を返す' do
\r
394 r = ResourcePicture.list(3)
\r
398 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
400 nop2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
401 @nrp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100
\r
402 nop3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
403 @nrp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200
\r
404 nop4 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
405 @nrp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300
\r
406 nop5 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
407 @nrp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400
\r
408 ResourcePicture.stub(:default_page_size).and_return(2)
\r
410 it '件数0は全件(5件)を返す' do
\r
411 r = ResourcePicture.list 5, 0
\r
412 r.should have(5).items
\r
416 describe '一覧取得オプションに於いて' do
\r
417 it 'includeキーを含んでいる' do
\r
418 r = ResourcePicture.list_opt
\r
419 r.has_key?(:include).should be_true
\r
421 it '3つの項目を含んでいる' do
\r
422 r = ResourcePicture.list_opt[:include]
\r
423 r.should have(3).items
\r
425 it 'ライセンスを含んでいる' do
\r
426 r = ResourcePicture.list_opt[:include]
\r
427 r.has_key?(:license).should be_true
\r
430 r = ResourcePicture.list_opt[:include]
\r
431 r.has_key?(:artist).should be_true
\r
434 r = ResourcePicture.list_opt[:include]
\r
435 r.has_key?(:picture).should be_true
\r
438 describe 'json一覧出力オプションに於いて' do
\r
440 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
441 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
442 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
443 @sbt = FactoryGirl.create :speech_balloon_template
\r
444 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
\r
445 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
\r
446 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
\r
448 it 'ライセンスを含んでいる' do
\r
449 r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
\r
452 i.has_key?('license').should be_true
\r
455 r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
\r
458 i.has_key?('artist').should be_true
\r
461 r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
\r
464 i.has_key?('picture').should be_true
\r
468 describe '自分の素材一覧取得に於いて' do
\r
470 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
471 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
472 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
474 context 'つつがなく終わるとき' do
\r
475 it '一覧取得オプションを利用している' do
\r
476 ResourcePicture.stub(:list_opt).with(any_args).and_return({})
\r
477 ResourcePicture.should_receive(:list_opt).with(any_args).exactly(1)
\r
478 r = ResourcePicture.mylist @artist
\r
482 c = ResourcePicture.mylist @artist
\r
486 nop = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
487 nrp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100
\r
488 cl = ResourcePicture.mylist @artist
\r
489 cl.should eq [nrp, @rp]
\r
492 nop = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
\r
493 nrp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100
\r
494 cl = ResourcePicture.mylist @artist
\r
497 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
499 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
500 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p.id, :updated_at => Time.now + 100
\r
501 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
502 @rp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op3.id, :picture_id => @p.id, :updated_at => Time.now + 200
\r
503 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
504 @rp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op4.id, :picture_id => @p.id, :updated_at => Time.now + 300
\r
505 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
506 @rp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op5.id, :picture_id => @p.id, :updated_at => Time.now + 400
\r
509 c = ResourcePicture.mylist @artist, 1, 2
\r
510 c.should have(2).items
\r
512 it 'page=1なら末尾2件を返す' do
\r
514 c = ResourcePicture.mylist(@artist, 1, 2)
\r
515 c.should eq [@rp5, @rp4]
\r
517 it 'page=2なら中間2件を返す' do
\r
518 c = ResourcePicture.mylist(@artist, 2, 2)
\r
519 c.should eq [@rp3, @rp2]
\r
521 it 'page=3なら先頭1件を返す' do
\r
522 c = ResourcePicture.mylist(@artist, 3, 2)
\r
526 context 'DBに5件あって1ページの件数を0件に変えたとして' do
\r
528 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
529 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p.id, :updated_at => Time.now + 100
\r
530 @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
531 @rp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op3.id, :picture_id => @p.id, :updated_at => Time.now + 200
\r
532 @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
533 @rp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op4.id, :picture_id => @p.id, :updated_at => Time.now + 300
\r
534 @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
535 @rp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op5.id, :picture_id => @p.id, :updated_at => Time.now + 400
\r
536 Author.stub(:default_resource_picture_page_size).and_return(2)
\r
538 it '通常は全件(5件)を返す' do
\r
539 r = ResourcePicture.mylist @artist, 5, 0
\r
540 r.should have(5).items
\r
545 describe '単体取得に於いて' do
\r
547 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
548 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
549 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
\r
551 context 'つつがなく終わるとき' do
\r
552 it '単体取得オプションを利用している' do
\r
553 ResourcePicture.stub(:show_opt).with(any_args).and_return({})
\r
554 ResourcePicture.should_receive(:show_opt).with(any_args).exactly(1)
\r
555 r = ResourcePicture.show @rp.id, @author
\r
557 it '閲覧許可を問い合わせている' do
\r
558 ResourcePicture.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
559 ResourcePicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
560 r = ResourcePicture.show @rp.id, @author
\r
564 r = ResourcePicture.show @rp.id, @author
\r
567 context '他人の素材を開こうとしたとき' do
\r
568 it '403Forbidden例外を返す' do
\r
569 ResourcePicture.any_instance.stub(:visible?).and_return(false)
\r
571 r = ResourcePicture.show @rp.id, @other_author
\r
572 }.should raise_error(ActiveRecord::Forbidden)
\r
575 context '存在しない素材を開こうとしたとき' do
\r
576 it '404RecordNotFound例外を返す' do
\r
578 r = ResourcePicture.show 0, @author
\r
579 }.should raise_error(ActiveRecord::RecordNotFound)
\r
583 describe '単体取得オプションに於いて' do
\r
584 it 'includeキーを含んでいる' do
\r
585 r = ResourcePicture.show_opt
\r
586 r.has_key?(:include).should be_true
\r
588 it '3つの項目を含んでいる' do
\r
589 r = ResourcePicture.show_opt[:include]
\r
590 r.should have(3).items
\r
592 it 'ライセンスを含んでいる' do
\r
593 r = ResourcePicture.show_opt[:include]
\r
594 r.has_key?(:license).should be_true
\r
597 r = ResourcePicture.show_opt[:include]
\r
598 r.has_key?(:artist).should be_true
\r
601 r = ResourcePicture.show_opt[:include]
\r
602 r.has_key?(:picture).should be_true
\r
605 describe 'json単体出力オプションに於いて' do
\r
607 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
608 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
609 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
610 @sbt = FactoryGirl.create :speech_balloon_template
\r
611 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
\r
612 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
\r
613 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
\r
615 it 'ライセンスを含んでいる' do
\r
616 r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
\r
619 i.has_key?('license').should be_true
\r
622 r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
\r
625 i.has_key?('artist').should be_true
\r
628 r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
\r
631 i.has_key?('picture').should be_true
\r
635 describe 'フォーマット変換対象判定に於いて' do
\r
637 @rp = FactoryGirl.build :resource_picture,
\r
638 :artist_id => @artist.id, :license_id => @license.id
\r
640 context '変換するケース' do
\r
641 it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do
\r
642 ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
\r
644 @rp.to_gif?.should be_true
\r
647 context '変換しないケース' do
\r
648 it '画像フォーマットがでない' do
\r
649 ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
\r
651 @rp.to_gif?.should be_false
\r
654 ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)
\r
656 @rp.to_gif?.should be_false
\r
661 describe '新規実素材の取得に於いて' do
\r
663 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
664 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
665 attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester',
\r
666 :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}
\r
667 @rp = FactoryGirl.build :resource_picture, attr
\r
668 @imager = ImagerTest.load "abc\ndef\nghi"
\r
670 context '事前チェック' do
\r
672 Picture.any_instance.stub(:store).with(any_args).and_return(true)
\r
674 it '実素材モデルにデフォルト値補充を依頼している' do
\r
675 Picture.any_instance.should_receive(:supply_default).with(any_args).exactly(1)
\r
676 r = @rp.new_picture @imager
\r
678 it '実素材モデルに上書き補充を依頼している' do
\r
679 Picture.any_instance.should_receive(:overwrite).with(any_args).exactly(1)
\r
680 r = @rp.new_picture @imager
\r
683 Picture.any_instance.should_receive(:store).with(any_args).exactly(1)
\r
684 r = @rp.new_picture @imager
\r
687 context 'つつがなく終わるとき' do
\r
688 it '保存された実素材を返す' do
\r
689 r = @rp.new_picture @imager
\r
690 r.is_a?(Picture).should be_true
\r
693 #以下から例外ケース。処理先頭から失敗させていく
\r
694 context '実素材の保存に失敗したとき' do
\r
696 Picture.any_instance.stub(:store).with(any_args).and_return(false)
\r
699 r = @rp.new_picture @imager
\r
702 it '自身の全体エラーメッセージにその旨をセットしている' do
\r
703 r = @rp.new_picture @imager
\r
704 @rp.errors[:base].should_not be_empty
\r
709 describe '作成・更新に於いて' do
\r
711 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
712 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
713 attr = {:original_picture_id => @op.id, :picture_id => nil, :license_id => @license.id, :artist_name => 'tester', :classname => 'StandardLicense', :credit => '{}', :settings => {}.to_json.to_s}
\r
714 @rp = FactoryGirl.build :resource_picture, attr
\r
715 @imager = ImagerTest.load "abc\ndef\nghi"
\r
717 context '事前チェック' do
\r
719 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
\r
720 #それで外部のメソッド呼び出しだけに着目してテストする。
\r
721 ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)
\r
722 ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)
\r
724 it '新規実素材の取得を依頼している' do
\r
725 ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)
\r
726 r = @rp.store @imager
\r
729 ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
730 r = @rp.store @imager
\r
732 it 'gif付き画像ファイルの作成・更新機能で画像を保存している' do
\r
733 ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@imager).exactly(1)
\r
734 r = @rp.store @imager
\r
737 context 'つつがなく終わるとき' do
\r
739 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
\r
740 ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)
\r
741 ResourcePicture.any_instance.stub(:store_picture_with_gif).with(@imager).and_return(true)
\r
744 r = @rp.store @imager
\r
747 it '実素材idから最新画像idを取得してセットしている' do
\r
748 r = @rp.store @imager
\r
749 @rp.picture_id.should eq @p.id
\r
753 r = @rp.store @imager
\r
754 }.should change ResourcePicture, :count
\r
757 #以下から例外ケース。処理先頭から失敗させていく
\r
758 context '画像オブジェクトの取得に失敗したとき' do
\r
763 r = @rp.store @imager
\r
767 r = @rp.store @imager
\r
768 @rp.should be_a_new ResourcePicture
\r
770 it '処理を中断してロールバックする' do
\r
772 r = @rp.store @imager
\r
773 }.should_not change Picture, :count
\r
776 context '新規実素材の取得に失敗したとき' do
\r
778 ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(false)
\r
781 r = @rp.store @imager
\r
785 r = @rp.store @imager
\r
786 @rp.should be_a_new ResourcePicture
\r
788 it '処理を中断してロールバックする' do
\r
790 r = @rp.store @imager
\r
791 }.should_not change Picture, :count
\r
794 context '自身の保存に失敗したとき' do
\r
796 ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)
\r
797 ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)
\r
800 r = @rp.store @imager
\r
804 r = @rp.store @imager
\r
805 @rp.should be_a_new ResourcePicture
\r
807 it '処理を中断してロールバックする' do
\r
809 r = @rp.store @imager
\r
810 }.should_not change Picture, :count
\r
813 context 'gif付き画像ファイルの作成・更新機能に失敗したとき' do
\r
815 ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)
\r
816 ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(false)
\r
819 r = @rp.store @imager
\r
823 r = @rp.store @imager
\r
824 @rp.should be_a_new ResourcePicture
\r
826 it '処理を中断してロールバックする' do
\r
828 r = @rp.store @imager
\r
829 }.should_not change Picture, :count
\r
834 describe 'gif付き画像ファイルの作成・更新に於いて' do
\r
836 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
837 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
838 attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}
\r
839 @rp = FactoryGirl.build :resource_picture, attr
\r
840 @imager = ImagerTest.load "abc\ndef\nghi"
\r
842 context '事前チェック' do
\r
844 #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
\r
845 #それで外部のメソッド呼び出しだけに着目してテストする。
\r
846 ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)
\r
847 ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
\r
848 ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')
\r
849 ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
\r
851 it '画像ファイルの作成・更新機能で画像を保存している' do
\r
852 #二回目の保存はgif変換の結果を渡す。
\r
853 ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(2)
\r
854 r = @rp.store_picture_with_gif @imager
\r
856 it '自身にフォーマット変換対象かを問い合わせている' do
\r
857 ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
\r
858 r = @rp.store_picture_with_gif @imager
\r
860 it '画像ライブラリにGifフォーマット変換を依頼している' do
\r
861 ImagerTest.any_instance.should_receive(:to_gif).with(any_args).exactly(1)
\r
862 r = @rp.store_picture_with_gif @imager
\r
865 context 'つつがなく終わるとき' do
\r
867 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
\r
868 ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)
\r
869 ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
\r
870 ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')
\r
871 ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
\r
874 r = @rp.store_picture_with_gif @imager
\r
878 context 'gif変換なしで、つつがなく終わるとき' do
\r
880 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
\r
881 ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)
\r
882 ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(false)
\r
883 ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')
\r
884 ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
\r
887 r = @rp.store_picture_with_gif @imager
\r
890 it 'gif保存は呼ばれていない' do
\r
891 ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
\r
892 r = @rp.store_picture_with_gif @imager
\r
895 #以下から例外ケース。処理先頭から失敗させていく
\r
896 context '画像の保存に失敗したとき' do
\r
898 ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(false)
\r
901 r = @rp.store_picture_with_gif @imager
\r
904 it '全体エラーメッセージがセットされている' do
\r
906 r = @rp.store_picture_with_gif @imager
\r
907 }.should change(@rp.errors[:base], :count)
\r
909 it 'gif変換判定は呼ばれていない' do
\r
910 ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)
\r
911 r = @rp.store_picture_with_gif @imager
\r
914 context 'gif変換に失敗したとき' do
\r
916 ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)
\r
917 ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
\r
918 ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(false)
\r
921 r = @rp.store_picture_with_gif @imager
\r
924 it '全体エラーメッセージがセットされている' do
\r
926 r = @rp.store_picture_with_gif @imager
\r
927 }.should change(@rp.errors[:base], :count)
\r
929 it 'gif画像の保存は呼ばれていない' do
\r
930 #本画像の保存があるので、一度は呼ばれる
\r
931 ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
\r
932 r = @rp.store_picture_with_gif @imager
\r
935 context 'gif画像の保存に失敗したとき' do
\r
937 ResourcePicture.any_instance.stub(:store_picture).with(@imager, '1.png').and_return(true)
\r
938 ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
\r
939 @gifimager = @imager.to_gif
\r
940 ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(@gifimager)
\r
941 ResourcePicture.any_instance.stub(:store_picture).with(@gifimager, '1.gif').and_return(false)
\r
942 ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')
\r
943 ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
\r
946 r = @rp.store_picture_with_gif @imager
\r
949 it '全体エラーメッセージがセットされている' do
\r
951 r = @rp.store_picture_with_gif @imager
\r
952 }.should change(@rp.errors[:base], :count)
\r
957 describe '画像ファイルの作成・更新に於いて' do
\r
958 #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。
\r
960 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
961 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
962 attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}
\r
963 @rp = FactoryGirl.build :resource_picture, attr
\r
965 @imager = ImagerTest.load "abc\ndef\nghi"
\r
967 context '事前チェック' do
\r
969 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
\r
970 PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
\r
971 ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
\r
973 it 'サムネイル化が1回呼ばれる' do
\r
974 ImagerTest.any_instance.should_receive(:to_thumbnail).with(any_args).exactly(1)
\r
975 r = @rp.store_picture(@imager, '1.png')
\r
977 it '画像ファイルの保存が2回呼ばれる' do
\r
978 PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)
\r
979 r = @rp.store_picture(@imager, '1.gif')
\r
981 it '画像ファイルのベースへのサムネイル保存が1回呼ばれる' do
\r
982 PictureIO.resource_picture_io.should_receive(:put).with(@imager.to_thumbnail.binary, '1.gif').exactly(1)
\r
983 r = @rp.store_picture(@imager, '1.gif')
\r
985 it '画像ファイルのfullへの保存が1回呼ばれる' do
\r
986 PictureIO.resource_picture_io.should_receive(:put).with(@imager.binary, '1.gif', 'full').exactly(1)
\r
987 r = @rp.store_picture(@imager, '1.gif')
\r
990 context 'つつがなく終わるとき' do
\r
992 #すべての処理を正常パターンで通過させ、保存機能をチェックする。
\r
993 PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
\r
994 ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
\r
997 r = @rp.store_picture(@imager, '1.gif')
\r
1001 #以下から例外ケース。処理先頭から失敗させていく
\r
1002 context 'サムネイル化に失敗したとき' do
\r
1004 ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
\r
1005 ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(false)
\r
1008 r = @rp.store_picture(@imager, '1.gif')
\r
1011 it '画像ファイルの保存は呼ばれていない' do
\r
1012 PictureIO.resource_picture_io.should_not_receive(:put).with(any_args)
\r
1013 r = @rp.store_picture(@imager, '1.gif')
\r
1016 context 'サムネイル画像の保存に失敗したとき' do
\r
1018 ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
\r
1019 @tmbimager = @imager.to_thumbnail
\r
1020 ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)
\r
1021 PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_raise(PictureIO::Error)
\r
1024 r = @rp.store_picture(@imager, '1.gif')
\r
1027 it '画像ファイルの保存は呼ばれていない' do
\r
1028 PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(1)
\r
1029 r = @rp.store_picture(@imager, '1.gif')
\r
1032 context '画像の保存に失敗したとき' do
\r
1034 ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
\r
1035 @tmbimager = @imager.to_thumbnail
\r
1036 ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)
\r
1037 PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_return(true)
\r
1038 PictureIO.resource_picture_io.stub(:put).with(@imager.binary, '1.gif', 'full').and_raise(PictureIO::Error)
\r
1041 r = @rp.store_picture(@imager, '1.gif')
\r
1048 describe '公開停止に於いて' do
\r
1050 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
1051 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
1052 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
1053 PictureIO.resource_picture_io.stub(:exist?).with(@rp.filename).and_return(true)
\r
1054 PictureIO.resource_picture_io.stub(:exist?).with(@rp.filename, 'full').and_return(true)
\r
1056 context '事前チェックしておく' do
\r
1058 ResourcePicture.any_instance.stub(:destroy).and_return(true)
\r
1059 PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_return(true)
\r
1060 PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_return(true)
\r
1062 it '素材モデルに削除を依頼している' do
\r
1063 ResourcePicture.any_instance.should_receive(:destroy).exactly(1)
\r
1066 it '保管庫にサムネイルの画像データ削除を依頼している' do
\r
1067 PictureIO.resource_picture_io.should_receive(:delete).with(@rp.filename).exactly(1)
\r
1070 it '保管庫にフルサイズの画像データ削除を依頼している' do
\r
1071 PictureIO.resource_picture_io.should_receive(:delete).with(@rp.filename, 'full').exactly(1)
\r
1075 context 'つつがなく終わるとき' do
\r
1079 }.should change(ResourcePicture, :count).by(-1)
\r
1081 r = ResourcePicture.find @rp.id
\r
1082 }.should raise_error
\r
1089 context '自身の削除に失敗したとき' do
\r
1091 ResourcePicture.any_instance.stub(:destroy).with(any_args).and_return(false)
\r
1097 it 'ロールバックしている' do
\r
1100 }.should_not change(ResourcePicture, :count)
\r
1103 context 'サムネイル画像の削除に失敗したとき' do
\r
1105 PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_raise(PictureIO::Error)
\r
1106 PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_return(true)
\r
1112 it 'ロールバックしている' do
\r
1115 }.should_not change(ResourcePicture, :count)
\r
1118 context 'フルサイズ画像の削除に失敗したとき' do
\r
1120 PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_return(true)
\r
1121 PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_raise(PictureIO::Error)
\r
1127 it 'ロールバックしている' do
\r
1130 }.should_not change(ResourcePicture, :count)
\r
1135 describe 'クレジットデータに於いて' do
\r
1137 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
1138 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
1139 attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{"system_picture_id": 2}', :settings => {}.to_json.to_s}
\r
1140 @rp = FactoryGirl.build :resource_picture, attr
\r
1142 it 'system_picture_idが入っている' do
\r
1143 res = @rp.credit_data
\r
1144 res["system_picture_id"].should eq 2
\r