1 # -*- encoding: utf-8 -*-
4 describe PanelPicture do
6 FactoryGirl.create :admin
7 @user = FactoryGirl.create( :user_yas)
9 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
10 @other_user = FactoryGirl.create( :user_yas)
11 @other_author = @other_user.author
12 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
13 @sp = FactoryGirl.create :system_picture
14 @lg = FactoryGirl.create :license_group
15 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
16 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
17 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
18 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
19 @panel = FactoryGirl.create :panel, :author_id => @author.id
24 @pp = FactoryGirl.build :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
25 :width => @p.width, :height => @p.height
26 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
27 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
28 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
31 context 'オーソドックスなデータのとき' do
33 @pp.link = 'http://test.jp/'
43 @pp.link = 'http://test.jp/aaaaa' + 'a' * 180
54 context 'panel_idを検証するとき' do
55 #ネストの保存はnilを許可しなければならないので数値チェックだけ
58 @pp.should_not be_valid
61 context 'linkを検証するとき' do
68 @pp.should_not be_valid
70 it 'url形式でないなら失敗する' do
72 @pp.should_not be_valid
\r
78 @pp.should_not be_valid
82 @pp.should_not be_valid
96 @pp.should_not be_valid
100 @pp.should_not be_valid
111 context 'widthを検証するとき' do
114 @pp.should_not be_valid
118 @pp.should_not be_valid
122 @pp.should_not be_valid
134 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
138 @pp.should_not be_valid
141 context 'サイズ変更許可のとき' do
144 it '実素材のサイズと違っても通る' do
145 @pp.width = @p.width-1
149 context 'サイズ変更禁止のとき' do
151 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(-1)
153 it '実素材のサイズと違うなら失敗する' do
154 @pp.width = @p.width-1
155 @pp.should_not be_valid
158 context '縦横比変更許可のとき' do
161 it '実素材の縦横比と違っても通る' do
162 @pp.width = @p.width / 2
166 context '縦横比変更禁止のとき' do
168 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(-1)
170 it '実素材の縦横比と違うなら失敗する' do
171 @pp.width = @p.width / 2
172 @pp.should_not be_valid
176 context 'heightを検証するとき' do
179 @pp.should_not be_valid
183 @pp.should_not be_valid
187 @pp.should_not be_valid
203 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
207 @pp.should_not be_valid
210 context 'サイズ変更許可のとき' do
213 it '実素材のサイズと違っても通る' do
214 @pp.height = @p.height-1
218 context 'サイズ変更禁止のとき' do
220 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(-1)
222 it '実素材のサイズと違うなら失敗する' do
223 @pp.height = @p.height-1
224 @pp.should_not be_valid
227 context '縦横比変更許可のとき' do
230 it '実素材の縦横比と違っても通る' do
231 @pp.height = @p.height / 2
235 context '縦横比変更禁止のとき' do
237 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(-1)
239 it '実素材の縦横比と違うなら失敗する' do
240 @pp.height = @p.height / 2
241 @pp.should_not be_valid
245 context 'zを検証するとき' do
248 @pp.should_not be_valid
252 @pp.should_not be_valid
256 @pp.should_not be_valid
260 @pp.should_not be_valid
263 context 'tを検証するとき' do
266 @pp.should_not be_valid
270 @pp.should_not be_valid
274 @pp.should_not be_valid
277 context 'picture_idを検証するとき' do
280 @pp.should_not be_valid
284 @pp.should_not be_valid
286 it '存在する実素材でなければ失敗する' do
288 @pp.should_not be_valid
292 describe '一覧取得に於いて' do
294 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
295 :width => @p.width, :height => @p.height
297 context 'page補正について' do
298 it '文字列から数値に変換される' do
299 PanelPicture.page('8').should eq 8
302 PanelPicture.page().should eq 1
305 PanelPicture.page('0').should eq 1
308 context 'page_size補正について' do
309 it '文字列から数値に変換される' do
310 PanelPicture.page_size('7').should eq 7
312 it 'nilの場合はPanelPicture.default_page_sizeになる' do
313 PanelPicture.page_size().should eq PanelPicture.default_page_size
315 it '0以下の場合はPanelPicture.default_page_sizeになる' do
316 PanelPicture.page_size('0').should eq PanelPicture.default_page_size
318 it 'PanelPicture.max_page_sizeを超えた場合はPanelPicture.max_page_sizeになる' do
319 PanelPicture.page_size('1000').should eq PanelPicture.max_page_size
322 context 'つつがなく終わるとき' do
\r
323 it '一覧取得オプションを利用している' do
\r
324 PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
\r
325 PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
\r
326 r = PanelPicture.list
330 r = PanelPicture.list
334 #公開されたコマのコマ絵は(他人のコマ絵であっても)含んでいる
335 hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
336 npl = FactoryGirl.create :panel_picture, :panel_id => hc.id, :t => 0, :picture_id => @p.id,
337 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
338 r = PanelPicture.list
339 r.should eq [npl, @pp]
341 it '非公開のコマのコマ絵は自分のコマであっても含まない' do
342 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
343 npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
344 :width => @p.width, :height => @p.height
345 pl = PanelPicture.list
348 context 'DBに5件あって1ページの件数を2件に変えたとして' do
350 @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
351 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
352 @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
353 :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
354 @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
355 :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
356 @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
357 :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
358 PanelPicture.stub(:default_page_size).and_return(2)
361 pl = PanelPicture.list
362 pl.should have(2).items
364 it 'page=1なら末尾2件を返す' do
366 pl = PanelPicture.list(1)
367 pl.should eq [@npl5, @npl4]
369 it 'page=2なら中間2件を返す' do
370 pl = PanelPicture.list(2)
371 pl.should eq [@npl3, @npl2]
373 it 'page=3なら先頭1件を返す' do
374 pl = PanelPicture.list(3)
378 context 'DBに5件あって1ページの件数を0件に変えたとして' do
380 @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
381 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
382 @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
383 :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
384 @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
385 :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
386 @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
387 :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
390 r = PanelPicture.list 5, 0
391 r.should have(5).items
395 describe '一覧取得オプションに於いて' do
396 it 'includeキーを含んでいる' do
397 r = PanelPicture.list_opt
398 r.has_key?(:include).should be_true
401 r = PanelPicture.list_opt[:include]
402 r.should have(2).items
405 r = PanelPicture.list_opt[:include]
406 r.has_key?(:panel).should be_true
409 r = PanelPicture.list_opt[:include]
410 r[:panel].has_key?(:author).should be_true
413 r = PanelPicture.list_opt[:include]
414 r.has_key?(:picture).should be_true
417 r = PanelPicture.list_opt[:include]
418 r[:picture].has_key?(:artist).should be_true
420 it '実素材はライセンスを含んでいる' do
421 r = PanelPicture.list_opt[:include]
422 r[:picture].has_key?(:license).should be_true
425 describe 'json一覧出力オプションに於いて' do
427 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
428 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
429 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
430 @sbt = FactoryGirl.create :speech_balloon_template
\r
431 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
432 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
433 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
434 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
435 :width => @p.width, :height => @p.height
438 r = PanelPicture.list.to_json PanelPicture.list_json_opt
441 i.has_key?('panel').should be_true
444 r = PanelPicture.list.to_json PanelPicture.list_json_opt
448 s.has_key?('author').should be_true
451 r = PanelPicture.list.to_json PanelPicture.list_json_opt
454 i.has_key?('picture').should be_true
457 r = PanelPicture.list.to_json PanelPicture.list_json_opt
461 s.has_key?('artist').should be_true
463 it '実素材はライセンスを含んでいる' do
464 r = PanelPicture.list.to_json PanelPicture.list_json_opt
468 s.has_key?('license').should be_true
472 describe '自分のコマ一覧取得に於いて' do
474 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
475 :width => @p.width, :height => @p.height
477 context 'つつがなく終わるとき' do
\r
478 it '一覧取得オプションを利用している' do
\r
479 PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
\r
480 PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
\r
481 r = PanelPicture.mylist @author
485 pl = PanelPicture.mylist @author
489 npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
490 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
491 pl = PanelPicture.mylist @author
492 pl.should eq [npl, @pp]
494 it '他人のコマのコマ絵は公開コマでも含まない' do
495 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
496 npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
497 :width => @p.width, :height => @p.height
498 pl = PanelPicture.mylist @author
501 it '自分のコマのコマ絵は非公開コマでも含んでいる' do
502 pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
503 ni = FactoryGirl.create :panel_picture, :panel_id => pl.id, :picture_id => @p.id,
504 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
505 r = PanelPicture.mylist @author
506 r.should eq [ni, @pp]
508 context 'DBに5件あって1ページの件数を2件に変えたとして' do
510 @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
511 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
512 @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
513 :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
514 @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
515 :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
516 @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
517 :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
520 r = PanelPicture.mylist @author, 1, 2
521 r.should have(2).items
523 it 'page=1なら末尾2件を返す' do
525 r = PanelPicture.mylist(@author, 1, 2)
526 r.should eq [@npl5, @npl4]
528 it 'page=2なら中間2件を返す' do
529 r = PanelPicture.mylist(@author, 2, 2)
530 r.should eq [@npl3, @npl2]
532 it 'page=3なら先頭1件を返す' do
533 r = PanelPicture.mylist(@author, 3, 2)
537 context 'DBに5件あって1ページの件数を0件に変えたとして' do
539 @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
540 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
541 @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
542 :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
543 @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
544 :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
545 @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
546 :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
549 r = PanelPicture.mylist @author, 5, 0
550 r.should have(5).items