1 # -*- encoding: utf-8 -*-
\r
2 require 'spec_helper'
\r
7 @sp = Factory :system_picture
8 @lg = Factory :license_group
9 @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @user = Factory( :user_yas)
\r
11 @author = @user.author
\r
12 @artist = Factory :artist_yas, :author_id => @author.id
\r
13 @other_user = Factory( :user_yas)
\r
14 @other_author = @other_user.author
\r
15 @other_artist = Factory :artist_yas, :author_id => @other_author.id
\r
16 @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
\r
17 @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id
\r
18 @sbt = Factory :speech_balloon_template
\r
21 describe '検証に於いて' do
\r
23 @comic = Factory :comic, :author_id => @author.id
\r
26 it 'オーソドックスなデータなら通る' do
\r
27 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
28 @panel.should be_valid
\r
31 context 'comic_idを検証するとき' do
\r
33 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => nil
\r
36 @panel.comic_id = @comic.id
\r
37 @panel.should be_valid
\r
40 context 'widthを検証するとき' do
\r
42 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
46 @panel.should be_valid
\r
50 @panel.should_not be_valid
\r
54 @panel.should_not be_valid
\r
58 @panel.should_not be_valid
\r
62 @panel.should_not be_valid
\r
65 context 'heightを検証するとき' do
\r
67 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
71 @panel.should be_valid
\r
75 @panel.should_not be_valid
\r
79 @panel.should_not be_valid
\r
83 @panel.should_not be_valid
\r
87 @panel.should_not be_valid
\r
90 context 'borderを検証するとき' do
\r
92 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
96 @panel.should be_valid
\r
100 @panel.should_not be_valid
\r
102 it '数値でなければ失敗する' do
\r
103 @panel.border = 'a'
\r
104 @panel.should_not be_valid
\r
107 @panel.border = '-1'
\r
108 @panel.should_not be_valid
\r
112 @panel.should be_valid
\r
115 context 'xを検証するとき' do
\r
117 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
121 @panel.should be_valid
\r
123 it '数値でなければ失敗する' do
\r
125 @panel.should_not be_valid
\r
129 @panel.should be_valid
\r
133 @panel.should be_valid
\r
136 context 'yを検証するとき' do
\r
138 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
142 @panel.should be_valid
\r
144 it '数値でなければ失敗する' do
\r
146 @panel.should_not be_valid
\r
150 @panel.should be_valid
\r
154 @panel.should be_valid
\r
157 context 'zを検証するとき' do
\r
159 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
163 @panel.should be_valid
\r
165 it '数値でなければ失敗する' do
\r
167 @panel.should_not be_valid
\r
171 @panel.should_not be_valid
\r
175 @panel.should_not be_valid
\r
178 context 'tを検証するとき' do
\r
180 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
184 @panel.should be_valid
\r
186 it '数値でなければ失敗する' do
\r
188 @panel.should_not be_valid
\r
192 @panel.should be_valid
\r
196 @panel.should_not be_valid
\r
199 context 'author_idを検証するとき' do
\r
201 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
204 @panel.author_id = @author.id
\r
205 @panel.should be_valid
\r
208 @panel.author_id = nil
\r
209 @panel.should_not be_valid
\r
211 it '数値でなければ失敗する' do
\r
212 @panel.author_id = 'a'
\r
213 @panel.should_not be_valid
\r
215 it '存在する絵師でなければ失敗する' do
\r
216 @panel.author_id = 0
\r
217 @panel.should_not be_valid
\r
220 context '全体を検証するとき' do
\r
222 @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
227 describe 'データ補充に於いて' do
\r
229 @comic = Factory :comic, :author_id => @author.id
\r
230 @panel = Factory.build :panel, :comic_id => @comic.id
\r
232 context 'widthを補充' do
\r
233 it '空の時はコミックから補充する' do
\r
235 @panel.supply_default @author
\r
236 @panel.width.should eq @comic.width
\r
238 it '空の時でもコミックが不在なら補充しない' do
\r
240 @panel.comic_id = nil
\r
241 @panel.supply_default @author
\r
242 @panel.width.should be_nil
\r
244 it '空でない時は変化しない' do
\r
247 @panel.supply_default @author
\r
248 }.should_not change @panel, :width
\r
251 context 'heightを補充' do
\r
252 it '空の時はコミックから補充する' do
\r
253 @panel.height = nil
\r
254 @panel.supply_default @author
\r
255 @panel.height.should eq @comic.height
\r
257 it '空の時でもコミックが不在なら補充しない' do
\r
258 @panel.height = nil
\r
259 @panel.comic_id = nil
\r
260 @panel.supply_default @author
\r
261 @panel.height.should be_nil
\r
263 it '空でない時は変化しない' do
\r
266 @panel.supply_default @author
\r
267 }.should_not change @panel, :height
\r
270 context 'borderを補充' do
\r
272 @panel.border = nil
\r
273 @panel.supply_default @author
\r
274 @panel.border.should eq 0
\r
276 it '空でない時は変化しない' do
\r
279 @panel.supply_default @author
\r
280 }.should_not change @panel, :border
\r
284 it '空の時はコミック内のtの最大値+1を補充する' do
\r
285 pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 0
\r
287 @panel.supply_default @author
\r
288 @panel.t.should eq 1
\r
290 it '空でコミック初のコマなら0を補充する' do
\r
292 @panel.supply_default @author
\r
293 @panel.t.should eq 0
\r
295 it '空の時でも更新ケースなら補充しない' do
\r
296 pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 1
\r
299 pl.supply_default @author
\r
300 }.should_not change pl, :t
\r
302 it '空でない時は変化しない' do
\r
305 @panel.supply_default @author
\r
306 }.should_not change @panel, :t
\r
309 context 'author_idを補充' do
\r
310 it 'ログイン中の作家idを補充する' do
\r
311 @panel.author_id = nil
\r
312 @panel.supply_default @author
\r
313 @panel.author_id.should eq @author.id
\r
319 describe '作者判定に於いて' do
\r
321 @comic = Factory :comic, :author_id => @author.id
\r
324 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
325 panel.own?(@author).should == true
\r
328 panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id
\r
329 panel.own?(@author).should == false
\r
332 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
333 panel.own?(nil).should == false
\r
336 describe '閲覧許可に於いて' do
\r
338 @comic = Factory :comic, :author_id => @author.id
\r
340 it '自作の公開コミックのコマを見るときは許可する' do
\r
341 Comic.any_instance.stub(:visible?).and_return(true)
\r
342 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
343 panel.visible?(@author).should == true
\r
345 it '自作のコマは非公開コミックでも許可する' do
\r
346 Comic.any_instance.stub(:visible?).and_return(false)
\r
347 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
348 panel.visible?(@author).should == true
\r
350 it '他人のコマでも公開コミックなら許可する' do
\r
351 Comic.any_instance.stub(:visible?).and_return(true)
\r
352 panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id
\r
353 panel.visible?(@author).should == true
\r
355 it '他人のコマで非公開コミックなら許可しない' do
\r
356 Comic.any_instance.stub(:visible?).and_return(false)
\r
357 panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id
\r
358 panel.visible?(@author).should == false
\r
361 describe '単体取得に於いて' do
\r
363 @comic = Factory :comic, :author_id => @author.id
\r
364 @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id
\r
367 Comic.any_instance.stub(:visible?).and_return(true)
\r
368 pl = Panel.show @panel.id, @author
\r
369 pl.should eq @panel
\r
371 context '他人の非公開コミックのコマを開こうとしたとき' do
\r
372 it '403Forbidden例外を返す' do
\r
373 Panel.any_instance.stub(:visible?).and_return(false)
\r
375 Panel.show @panel.id, @author
\r
376 }.should raise_error(ActiveRecord::Forbidden)
\r
379 context '存在しないコマを開こうとしたとき' do
\r
380 it '404RecordNotFound例外を返す' do
\r
382 Panel.show 110, @author
\r
383 }.should raise_error(ActiveRecord::RecordNotFound)
\r
387 describe '関連テーブルプションに於いて' do
\r
388 context 'オプションがないとき' do
\r
389 it '4つの項目を含んでいる' do
\r
390 r = Panel.show_include_opt
\r
391 r.should have(4).items
\r
394 r = Panel.show_include_opt
\r
395 r.has_key?(:comic).should be_true
\r
398 r = Panel.show_include_opt
\r
399 r.has_key?(:panel_pictures).should be_true
\r
401 it 'コマ絵は素材を含んでいる' do
\r
402 r = Panel.show_include_opt
\r
403 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
405 it '素材は絵師を含んでいる' do
\r
406 r = Panel.show_include_opt
\r
407 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
409 it '素材はライセンスを含んでいる' do
\r
410 r = Panel.show_include_opt
\r
411 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
414 r = Panel.show_include_opt
\r
415 r.has_key?(:speech_balloons).should be_true
\r
417 it 'フキダシはフキダシ枠を含んでいる' do
\r
418 r = Panel.show_include_opt
\r
419 r[:speech_balloons].has_key?(:balloons).should be_true
\r
421 it 'フキダシはセリフを含んでいる' do
\r
422 r = Panel.show_include_opt
\r
423 r[:speech_balloons].has_key?(:speeches).should be_true
\r
426 r = Panel.show_include_opt
\r
427 r.has_key?(:author).should be_true
\r
430 context 'オプションで原画を含ませたとき' do
\r
431 it '5つの項目を含んでいる' do
\r
432 r = Panel.show_include_opt(:include => {:test => {}})
\r
433 r.should have(5).items
\r
436 r = Panel.show_include_opt(:include => {:test => {}})
\r
437 r.has_key?(:test).should be_true
\r
441 describe 'json単体出力オプションに於いて' do
\r
442 it 'includeキーを含んでいる' do
\r
443 r = Panel.show_json_include_opt
\r
444 r.has_key?(:include).should be_true
\r
446 it '4つの項目を含んでいる' do
\r
447 r = Panel.show_json_include_opt[:include]
\r
448 r.should have(4).items
\r
451 r = Panel.show_json_include_opt[:include]
\r
452 r.has_key?(:comic).should be_true
\r
455 r = Panel.show_json_include_opt[:include]
\r
456 r.has_key?(:panel_pictures).should be_true
\r
458 it 'コマ絵は素材を含んでいる' do
\r
459 r = Panel.show_json_include_opt[:include]
\r
460 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
462 it '素材は絵師を含んでいる' do
\r
463 r = Panel.show_json_include_opt[:include]
\r
464 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
466 it '素材はライセンスを含んでいる' do
\r
467 r = Panel.show_json_include_opt[:include]
\r
468 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
471 r = Panel.show_include_opt
\r
472 r.has_key?(:speech_balloons).should be_true
\r
474 it 'フキダシはフキダシ枠を含んでいる' do
\r
475 r = Panel.show_include_opt
\r
476 r[:speech_balloons].has_key?(:balloons).should be_true
\r
478 it 'フキダシはセリフを含んでいる' do
\r
479 r = Panel.show_include_opt
\r
480 r[:speech_balloons].has_key?(:speeches).should be_true
\r
483 r = Panel.show_json_include_opt[:include]
\r
484 r.has_key?(:author).should be_true
\r
487 describe '一覧取得に於いて' do
\r
489 @comic = Factory :comic, :author_id => @author.id
\r
490 @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id
\r
492 context 'page補正について' do
\r
493 it '文字列から数値に変換される' do
\r
494 Panel.page('8').should eq 8
\r
496 it 'nilの場合は1になる' do
\r
497 Panel.page().should eq 1
\r
499 it '0以下の場合は1になる' do
\r
500 Panel.page('0').should eq 1
\r
503 context 'page_size補正について' do
\r
504 it '文字列から数値に変換される' do
\r
505 Panel.page_size('7').should eq 7
\r
507 it 'nilの場合はPanel.default_page_sizeになる' do
\r
508 Panel.page_size().should eq Panel.default_page_size
\r
510 it '0以下の場合はPanel.default_page_sizeになる' do
\r
511 Panel.page_size('0').should eq Panel.default_page_size
\r
513 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
514 Panel.page_size('1000').should eq Panel.max_page_size
\r
519 pl.should eq [@panel]
\r
522 npl = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100
\r
524 pl.should eq [npl, @panel]
\r
526 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
528 @npl2 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100
\r
529 @npl3 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 2, :updated_at => Time.now + 200
\r
530 @npl4 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 3, :updated_at => Time.now + 300
\r
531 @npl5 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 4, :updated_at => Time.now + 400
\r
532 Panel.stub(:default_page_size).and_return(2)
\r
536 pl.should have(2).items
\r
538 it 'page=1なら末尾2件を返す' do
\r
540 pl = Panel.list( {}, 1)
\r
541 pl.should eq [@npl5, @npl4]
\r
543 it 'page=2なら中間2件を返す' do
\r
544 pl = Panel.list({}, 2)
\r
545 pl.should eq [@npl3, @npl2]
\r
547 it 'page=3なら先頭1件を返す' do
\r
548 pl = Panel.list({}, 3)
\r
549 pl.should eq [@panel]
\r
553 describe 'list関連テーブルプションに於いて' do
\r
554 it 'includeキーを含んでいる' do
\r
556 r.has_key?(:include).should be_true
\r
558 it '4つの項目を含んでいる' do
\r
559 r = Panel.list_opt[:include]
\r
560 r.should have(4).items
\r
563 r = Panel.list_opt[:include]
\r
564 r.has_key?(:comic).should be_true
\r
567 r = Panel.list_opt[:include]
\r
568 r.has_key?(:panel_pictures).should be_true
\r
570 it 'コマ絵は素材を含んでいる' do
\r
571 r = Panel.list_opt[:include]
\r
572 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
574 it '素材は絵師を含んでいる' do
\r
575 r = Panel.list_opt[:include]
\r
576 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
578 it '素材はライセンスを含んでいる' do
\r
579 r = Panel.list_opt[:include]
\r
580 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
583 r = Panel.show_include_opt
\r
584 r.has_key?(:speech_balloons).should be_true
\r
586 it 'フキダシはフキダシ枠を含んでいる' do
\r
587 r = Panel.show_include_opt
\r
588 r[:speech_balloons].has_key?(:balloons).should be_true
\r
590 it 'フキダシはセリフを含んでいる' do
\r
591 r = Panel.show_include_opt
\r
592 r[:speech_balloons].has_key?(:speeches).should be_true
\r
595 r = Panel.list_opt[:include]
\r
596 r.has_key?(:author).should be_true
\r
599 describe 'json一覧出力オプションに於いて' do
\r
600 it 'includeキーを含んでいる' do
\r
601 r = Panel.list_json_opt
\r
602 r.has_key?(:include).should be_true
\r
604 it '4つの項目を含んでいる' do
\r
605 r = Panel.list_json_opt[:include]
\r
606 r.should have(4).items
\r
609 r = Panel.list_json_opt[:include]
\r
610 r.has_key?(:comic).should be_true
\r
613 r = Panel.list_json_opt[:include]
\r
614 r.has_key?(:panel_pictures).should be_true
\r
616 it 'コマ絵は素材を含んでいる' do
\r
617 r = Panel.list_json_opt[:include]
\r
618 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
620 it '素材は絵師を含んでいる' do
\r
621 r = Panel.list_json_opt[:include]
\r
622 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
624 it '素材はライセンスを含んでいる' do
\r
625 r = Panel.list_json_opt[:include]
\r
626 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
629 r = Panel.show_include_opt
\r
630 r.has_key?(:speech_balloons).should be_true
\r
632 it 'フキダシはフキダシ枠を含んでいる' do
\r
633 r = Panel.show_include_opt
\r
634 r[:speech_balloons].has_key?(:balloons).should be_true
\r
636 it 'フキダシはセリフを含んでいる' do
\r
637 r = Panel.show_include_opt
\r
638 r[:speech_balloons].has_key?(:speeches).should be_true
\r
641 r = Panel.list_json_opt[:include]
\r
642 r.has_key?(:author).should be_true
\r
647 #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった
\r
648 #コマ絵とフキダシの整合チェックをする
\r
649 describe 'id収集に於いて' do
\r
650 context 'つつがなく終わるとき' do
\r
651 it '第一パラメータで指定された配列中から第二引数のidを収集している' do
\r
652 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
653 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
654 r = Panel.collect_element_value a, :panel_id
\r
655 r.should eq [1, 2, 3, 4]
\r
658 context 'Nil除外指示があるとき' do
\r
659 it '収集したpanel_idのうちnilは除外している' do
\r
660 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}],
\r
661 [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
662 r = Panel.collect_element_value a, :panel_id, true
\r
663 r.should eq [1, 2, 3, 4]
\r
667 describe 'id一致チェックに於いて' do
\r
668 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
669 context '親が既存(idが数値)のとき' do
\r
670 it 'すべてid一致するときTrueを返す' do
\r
671 r = Panel.validate_id [1, 1, 1, 1], 1
\r
674 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
675 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
678 it 'すべて数値でも一致しないときFalseを返す' do
\r
679 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
682 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
683 r = Panel.validate_id [1, 1, nil, 2], 1
\r
687 context '親が新規(idがNil)のとき' do
\r
688 it 'すべてNilはTrueを返す' do
\r
689 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
692 it 'すべてnilでなければFalseを返す' do
\r
693 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
698 describe 'idチェック単体に於いて' do
\r
700 # @pp = Factory :panel_picture, :panel_id => @panel.id, :t => 1
\r
702 context 'つつがなく終わるとき' do
\r
703 it 'idを収集依頼している' do
\r
704 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
705 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
706 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
707 r = Panel.validate_element_id [], :panel_id, nil
\r
709 it '収集したidを一致チェック依頼している' do
\r
710 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
711 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
712 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
713 r = Panel.validate_element_id [], :panel_id, nil
\r
717 #依頼チェックだけでは不安なので最低限のチェックを
\r
718 context 'コマ新規のとき' do
\r
719 it 'コマ絵で正常通過している' do
\r
720 @panel = Factory.build :panel, :author_id => @author.id
\r
721 @panel.panel_pictures.build(
\r
722 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
724 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
727 it 'フキダシで正常通過している' do
\r
728 @panel = Factory.build :panel, :author_id => @author.id
\r
729 @panel.speech_balloons.build(
\r
730 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
732 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
736 context 'コマ既存のとき' do
\r
737 it 'コマ絵で正常通過している' do
\r
738 @panel = Factory :panel, :author_id => @author.id
\r
739 @panel.panel_pictures.build(
\r
740 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
742 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
745 it 'フキダシで正常通過している' do
\r
746 @panel = Factory :panel, :author_id => @author.id
\r
747 @panel.speech_balloons.build(
\r
748 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
750 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
754 context 'フキダシ新規のとき' do
\r
755 it 'バルーンで正常通過している' do
\r
756 @panel = Factory.build :panel, :author_id => @author.id
\r
757 @panel.speech_balloons.build(
\r
758 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
760 @panel.speech_balloons.first.balloons.build(
\r
761 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
763 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
766 it 'セリフで正常通過している' do
\r
767 @panel = Factory.build :panel, :author_id => @author.id
\r
768 @panel.speech_balloons.build(
\r
769 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
771 @panel.speech_balloons.first.speeches.build(
\r
772 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
774 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
779 describe 'idチェックリスト生成に於いて' do
\r
781 @panel = Factory.build :panel, :author_id => @author.id
\r
783 context 'つつがなく終わるとき' do
\r
784 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
785 @panel.panel_pictures.build(
\r
786 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
788 @panel.speech_balloons.build(
\r
789 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
791 @panel.speech_balloons.first.balloons.build(
\r
792 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
794 @panel.speech_balloons.first.speeches.build(
\r
795 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
797 r = @panel.validate_id_list
\r
798 r.should have(2).items
\r
800 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
801 @panel.panel_pictures.build(
\r
802 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
804 sb1 = @panel.speech_balloons.build(
\r
805 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
807 sb1.balloons.build(
\r
808 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
810 sb1.speeches.build(
\r
811 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
813 sb2 = @panel.speech_balloons.build(
\r
814 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
816 sb2.balloons.build(
\r
817 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
819 sb2.speeches.build(
\r
820 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
822 r = @panel.validate_id_list
\r
823 r.should have(3).items
\r
827 describe 'idチェック複合に於いて' do
\r
829 @panel = Factory.build :panel, :author_id => @author.id
\r
831 context 'つつがなく終わるとき' do
\r
832 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
833 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
834 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
835 @panel.panel_pictures.build(
\r
836 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
838 sb1 = @panel.speech_balloons.build(
\r
839 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
841 sb1.balloons.build(
\r
842 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
844 sb1.speeches.build(
\r
845 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
847 r = Panel.validate_elements_id(@panel.validate_id_list)
\r
851 describe 'シリアライズチェックに於いて' do
\r
852 context 'つつがなく終わるとき' do
\r
853 it '0からシリアライズされているならTrueを返す' do
\r
854 r = Panel.validate_t [0, 1, 2]
\r
857 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
858 r = Panel.validate_t [0, 2, 1]
\r
861 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
862 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
867 it '0から始まらないならFalseを返す' do
\r
868 r = Panel.validate_t [1, 2, 3]
\r
871 it '連続していないならFalseを返す' do
\r
872 r = Panel.validate_t [0, 1, 2, 4]
\r
875 it '連続していないならFalseを返す' do
\r
876 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
881 describe 'tチェック単体に於いて' do
\r
884 context 'つつがなく終わるとき' do
\r
885 it 'コマ絵とフキダシのtを収集依頼している' do
\r
886 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
887 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
888 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
889 r = Panel.validate_element_t [], :t
\r
891 it '収集したtをシリアライズチェック依頼している' do
\r
892 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
893 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
894 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
895 r = Panel.validate_element_t [], :t
\r
899 #依頼チェックだけでは不安なので最低限のチェックを
\r
901 it 'コマ絵で正常通過している' do
\r
902 @panel = Factory.build :panel, :author_id => @author.id
\r
903 @panel.panel_pictures.build(
\r
904 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
906 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
909 it 'フキダシで正常通過している' do
\r
910 @panel = Factory.build :panel, :author_id => @author.id
\r
911 @panel.speech_balloons.build(
\r
912 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)
\r
914 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
919 it 'コマ絵で正常通過している' do
\r
920 @panel = Factory :panel, :author_id => @author.id
\r
921 @panel.panel_pictures.build(
\r
922 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
924 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
927 it 'フキダシで正常通過している' do
\r
928 @panel = Factory :panel, :author_id => @author.id
\r
929 @panel.speech_balloons.build(
\r
930 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
932 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
937 describe '複合チェックに於いて' do
\r
938 context 'つつがなく終わるとき' do
\r
940 @panel = Factory.build :panel, :author_id => @author.id
\r
941 @panel.panel_pictures.build(
\r
942 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
944 @panel.panel_pictures.build(
\r
945 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
947 sb1 = @panel.speech_balloons.build(
\r
948 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
950 sb1.balloons.build(
\r
951 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
953 sb1.speeches.build(
\r
954 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
956 sb2 = @panel.speech_balloons.build(
\r
957 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
959 sb2.balloons.build(
\r
960 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
962 sb2.speeches.build(
\r
963 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
965 r = @panel.validate_child
\r