1 # -*- encoding: utf-8 -*-
\r
2 require 'spec_helper'
\r
7 @license = Factory :license
\r
8 @user = Factory( :user_yas)
\r
9 @author = @user.author
\r
10 @artist = Factory :artist_yas, :author_id => @author.id
\r
11 @other_user = Factory( :user_yas)
\r
12 @other_author = @other_user.author
\r
13 @other_artist = Factory :artist_yas, :author_id => @other_author.id
\r
14 @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
\r
15 @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id
\r
16 @sbt = Factory :speech_balloon_template
\r
19 describe '検証に於いて' do
\r
21 @comic = Factory :comic, :author_id => @author.id
\r
24 it 'オーソドックスなデータなら通る' do
\r
25 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
26 @panel.should be_valid
\r
29 context 'comic_idを検証するとき' do
\r
31 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => nil
\r
34 @panel.comic_id = @comic.id
\r
35 @panel.should be_valid
\r
38 context 'widthを検証するとき' do
\r
40 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
44 @panel.should be_valid
\r
48 @panel.should_not be_valid
\r
52 @panel.should_not be_valid
\r
56 @panel.should_not be_valid
\r
60 @panel.should_not be_valid
\r
63 context 'heightを検証するとき' do
\r
65 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
69 @panel.should be_valid
\r
73 @panel.should_not be_valid
\r
77 @panel.should_not be_valid
\r
81 @panel.should_not be_valid
\r
85 @panel.should_not be_valid
\r
88 context 'borderを検証するとき' do
\r
90 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
94 @panel.should be_valid
\r
98 @panel.should_not be_valid
\r
100 it '数値でなければ失敗する' do
\r
101 @panel.border = 'a'
\r
102 @panel.should_not be_valid
\r
105 @panel.border = '-1'
\r
106 @panel.should_not be_valid
\r
110 @panel.should be_valid
\r
113 context 'xを検証するとき' do
\r
115 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
119 @panel.should be_valid
\r
121 it '数値でなければ失敗する' do
\r
123 @panel.should_not be_valid
\r
127 @panel.should be_valid
\r
131 @panel.should be_valid
\r
134 context 'yを検証するとき' do
\r
136 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
140 @panel.should be_valid
\r
142 it '数値でなければ失敗する' do
\r
144 @panel.should_not be_valid
\r
148 @panel.should be_valid
\r
152 @panel.should be_valid
\r
155 context 'zを検証するとき' do
\r
157 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
161 @panel.should be_valid
\r
163 it '数値でなければ失敗する' do
\r
165 @panel.should_not be_valid
\r
169 @panel.should_not be_valid
\r
173 @panel.should_not be_valid
\r
176 context 'tを検証するとき' do
\r
178 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
182 @panel.should be_valid
\r
184 it '数値でなければ失敗する' do
\r
186 @panel.should_not be_valid
\r
190 @panel.should be_valid
\r
194 @panel.should_not be_valid
\r
197 context 'author_idを検証するとき' do
\r
199 @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
\r
202 @panel.author_id = @author.id
\r
203 @panel.should be_valid
\r
206 @panel.author_id = nil
\r
207 @panel.should_not be_valid
\r
209 it '数値でなければ失敗する' do
\r
210 @panel.author_id = 'a'
\r
211 @panel.should_not be_valid
\r
213 it '存在する絵師でなければ失敗する' do
\r
214 @panel.author_id = 0
\r
215 @panel.should_not be_valid
\r
218 context '全体を検証するとき' do
\r
220 @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
225 describe 'データ補充に於いて' do
\r
227 @comic = Factory :comic, :author_id => @author.id
\r
228 @panel = Factory.build :panel, :comic_id => @comic.id
\r
230 context 'widthを補充' do
\r
231 it '空の時はコミックから補充する' do
\r
233 @panel.supply_default @author
\r
234 @panel.width.should eq @comic.width
\r
236 it '空の時でもコミックが不在なら補充しない' do
\r
238 @panel.comic_id = nil
\r
239 @panel.supply_default @author
\r
240 @panel.width.should be_nil
\r
242 it '空でない時は変化しない' do
\r
245 @panel.supply_default @author
\r
246 }.should_not change @panel, :width
\r
249 context 'heightを補充' do
\r
250 it '空の時はコミックから補充する' do
\r
251 @panel.height = nil
\r
252 @panel.supply_default @author
\r
253 @panel.height.should eq @comic.height
\r
255 it '空の時でもコミックが不在なら補充しない' do
\r
256 @panel.height = nil
\r
257 @panel.comic_id = nil
\r
258 @panel.supply_default @author
\r
259 @panel.height.should be_nil
\r
261 it '空でない時は変化しない' do
\r
264 @panel.supply_default @author
\r
265 }.should_not change @panel, :height
\r
268 context 'borderを補充' do
\r
270 @panel.border = nil
\r
271 @panel.supply_default @author
\r
272 @panel.border.should eq 0
\r
274 it '空でない時は変化しない' do
\r
277 @panel.supply_default @author
\r
278 }.should_not change @panel, :border
\r
282 it '空の時はコミック内のtの最大値+1を補充する' do
\r
283 pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 0
\r
285 @panel.supply_default @author
\r
286 @panel.t.should eq 1
\r
288 it '空でコミック初のコマなら0を補充する' do
\r
290 @panel.supply_default @author
\r
291 @panel.t.should eq 0
\r
293 it '空の時でも更新ケースなら補充しない' do
\r
294 pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 1
\r
297 pl.supply_default @author
\r
298 }.should_not change pl, :t
\r
300 it '空でない時は変化しない' do
\r
303 @panel.supply_default @author
\r
304 }.should_not change @panel, :t
\r
307 context 'author_idを補充' do
\r
308 it 'ログイン中の作家idを補充する' do
\r
309 @panel.author_id = nil
\r
310 @panel.supply_default @author
\r
311 @panel.author_id.should eq @author.id
\r
317 describe '作者判定に於いて' do
\r
319 @comic = Factory :comic, :author_id => @author.id
\r
322 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
323 panel.own?(@author).should == true
\r
326 panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id
\r
327 panel.own?(@author).should == false
\r
330 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
331 panel.own?(nil).should == false
\r
334 describe '閲覧許可に於いて' do
\r
336 @comic = Factory :comic, :author_id => @author.id
\r
338 it '自作の公開コミックのコマを見るときは許可する' do
\r
339 Comic.any_instance.stub(:visible?).and_return(true)
\r
340 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
341 panel.visible?(@author).should == true
\r
343 it '自作のコマは非公開コミックでも許可する' do
\r
344 Comic.any_instance.stub(:visible?).and_return(false)
\r
345 panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
\r
346 panel.visible?(@author).should == true
\r
348 it '他人のコマでも公開コミックなら許可する' do
\r
349 Comic.any_instance.stub(:visible?).and_return(true)
\r
350 panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id
\r
351 panel.visible?(@author).should == true
\r
353 it '他人のコマで非公開コミックなら許可しない' do
\r
354 Comic.any_instance.stub(:visible?).and_return(false)
\r
355 panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id
\r
356 panel.visible?(@author).should == false
\r
359 describe '単体取得に於いて' do
\r
361 @comic = Factory :comic, :author_id => @author.id
\r
362 @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id
\r
365 Comic.any_instance.stub(:visible?).and_return(true)
\r
366 pl = Panel.show @panel.id, @author
\r
367 pl.should eq @panel
\r
369 context '他人の非公開コミックのコマを開こうとしたとき' do
\r
370 it '403Forbidden例外を返す' do
\r
371 Panel.any_instance.stub(:visible?).and_return(false)
\r
373 Panel.show @panel.id, @author
\r
374 }.should raise_error(ActiveRecord::Forbidden)
\r
377 context '存在しないコマを開こうとしたとき' do
\r
378 it '404RecordNotFound例外を返す' do
\r
380 Panel.show 110, @author
\r
381 }.should raise_error(ActiveRecord::RecordNotFound)
\r
385 describe '関連テーブルプションに於いて' do
\r
386 context 'オプションがないとき' do
\r
387 it '4つの項目を含んでいる' do
\r
388 r = Panel.show_include_opt
\r
389 r.should have(4).items
\r
392 r = Panel.show_include_opt
\r
393 r.has_key?(:comic).should be_true
\r
396 r = Panel.show_include_opt
\r
397 r.has_key?(:panel_pictures).should be_true
\r
399 it 'コマ絵は素材を含んでいる' do
\r
400 r = Panel.show_include_opt
\r
401 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
403 it '素材は絵師を含んでいる' do
\r
404 r = Panel.show_include_opt
\r
405 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
407 it '素材はライセンスを含んでいる' do
\r
408 r = Panel.show_include_opt
\r
409 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
412 r = Panel.show_include_opt
\r
413 r.has_key?(:speech_balloons).should be_true
\r
415 it 'フキダシはフキダシ枠を含んでいる' do
\r
416 r = Panel.show_include_opt
\r
417 r[:speech_balloons].has_key?(:balloons).should be_true
\r
419 it 'フキダシはセリフを含んでいる' do
\r
420 r = Panel.show_include_opt
\r
421 r[:speech_balloons].has_key?(:speeches).should be_true
\r
424 r = Panel.show_include_opt
\r
425 r.has_key?(:author).should be_true
\r
428 context 'オプションで原画を含ませたとき' do
\r
429 it '5つの項目を含んでいる' do
\r
430 r = Panel.show_include_opt(:include => {:test => {}})
\r
431 r.should have(5).items
\r
434 r = Panel.show_include_opt(:include => {:test => {}})
\r
435 r.has_key?(:test).should be_true
\r
439 describe 'json単体出力オプションに於いて' do
\r
440 it 'includeキーを含んでいる' do
\r
441 r = Panel.show_json_include_opt
\r
442 r.has_key?(:include).should be_true
\r
444 it '4つの項目を含んでいる' do
\r
445 r = Panel.show_json_include_opt[:include]
\r
446 r.should have(4).items
\r
449 r = Panel.show_json_include_opt[:include]
\r
450 r.has_key?(:comic).should be_true
\r
453 r = Panel.show_json_include_opt[:include]
\r
454 r.has_key?(:panel_pictures).should be_true
\r
456 it 'コマ絵は素材を含んでいる' do
\r
457 r = Panel.show_json_include_opt[:include]
\r
458 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
460 it '素材は絵師を含んでいる' do
\r
461 r = Panel.show_json_include_opt[:include]
\r
462 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
464 it '素材はライセンスを含んでいる' do
\r
465 r = Panel.show_json_include_opt[:include]
\r
466 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
469 r = Panel.show_include_opt
\r
470 r.has_key?(:speech_balloons).should be_true
\r
472 it 'フキダシはフキダシ枠を含んでいる' do
\r
473 r = Panel.show_include_opt
\r
474 r[:speech_balloons].has_key?(:balloons).should be_true
\r
476 it 'フキダシはセリフを含んでいる' do
\r
477 r = Panel.show_include_opt
\r
478 r[:speech_balloons].has_key?(:speeches).should be_true
\r
481 r = Panel.show_json_include_opt[:include]
\r
482 r.has_key?(:author).should be_true
\r
485 describe '一覧取得に於いて' do
\r
487 @comic = Factory :comic, :author_id => @author.id
\r
488 @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id
\r
490 context 'page補正について' do
\r
491 it '文字列から数値に変換される' do
\r
492 Panel.page('8').should eq 8
\r
494 it 'nilの場合は1になる' do
\r
495 Panel.page().should eq 1
\r
497 it '0以下の場合は1になる' do
\r
498 Panel.page('0').should eq 1
\r
501 context 'page_size補正について' do
\r
502 it '文字列から数値に変換される' do
\r
503 Panel.page_size('7').should eq 7
\r
505 it 'nilの場合はPanel.default_page_sizeになる' do
\r
506 Panel.page_size().should eq Panel.default_page_size
\r
508 it '0以下の場合はPanel.default_page_sizeになる' do
\r
509 Panel.page_size('0').should eq Panel.default_page_size
\r
511 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
512 Panel.page_size('1000').should eq Panel.max_page_size
\r
517 pl.should eq [@panel]
\r
520 npl = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100
\r
522 pl.should eq [npl, @panel]
\r
524 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
526 @npl2 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100
\r
527 @npl3 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 2, :updated_at => Time.now + 200
\r
528 @npl4 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 3, :updated_at => Time.now + 300
\r
529 @npl5 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 4, :updated_at => Time.now + 400
\r
530 Panel.stub(:default_page_size).and_return(2)
\r
534 pl.should have(2).items
\r
536 it 'page=1なら末尾2件を返す' do
\r
538 pl = Panel.list( {}, 1)
\r
539 pl.should eq [@npl5, @npl4]
\r
541 it 'page=2なら中間2件を返す' do
\r
542 pl = Panel.list({}, 2)
\r
543 pl.should eq [@npl3, @npl2]
\r
545 it 'page=3なら先頭1件を返す' do
\r
546 pl = Panel.list({}, 3)
\r
547 pl.should eq [@panel]
\r
551 describe 'list関連テーブルプションに於いて' do
\r
552 it 'includeキーを含んでいる' do
\r
554 r.has_key?(:include).should be_true
\r
556 it '4つの項目を含んでいる' do
\r
557 r = Panel.list_opt[:include]
\r
558 r.should have(4).items
\r
561 r = Panel.list_opt[:include]
\r
562 r.has_key?(:comic).should be_true
\r
565 r = Panel.list_opt[:include]
\r
566 r.has_key?(:panel_pictures).should be_true
\r
568 it 'コマ絵は素材を含んでいる' do
\r
569 r = Panel.list_opt[:include]
\r
570 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
572 it '素材は絵師を含んでいる' do
\r
573 r = Panel.list_opt[:include]
\r
574 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
576 it '素材はライセンスを含んでいる' do
\r
577 r = Panel.list_opt[:include]
\r
578 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
581 r = Panel.show_include_opt
\r
582 r.has_key?(:speech_balloons).should be_true
\r
584 it 'フキダシはフキダシ枠を含んでいる' do
\r
585 r = Panel.show_include_opt
\r
586 r[:speech_balloons].has_key?(:balloons).should be_true
\r
588 it 'フキダシはセリフを含んでいる' do
\r
589 r = Panel.show_include_opt
\r
590 r[:speech_balloons].has_key?(:speeches).should be_true
\r
593 r = Panel.list_opt[:include]
\r
594 r.has_key?(:author).should be_true
\r
597 describe 'json一覧出力オプションに於いて' do
\r
598 it 'includeキーを含んでいる' do
\r
599 r = Panel.list_json_opt
\r
600 r.has_key?(:include).should be_true
\r
602 it '4つの項目を含んでいる' do
\r
603 r = Panel.list_json_opt[:include]
\r
604 r.should have(4).items
\r
607 r = Panel.list_json_opt[:include]
\r
608 r.has_key?(:comic).should be_true
\r
611 r = Panel.list_json_opt[:include]
\r
612 r.has_key?(:panel_pictures).should be_true
\r
614 it 'コマ絵は素材を含んでいる' do
\r
615 r = Panel.list_json_opt[:include]
\r
616 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
618 it '素材は絵師を含んでいる' do
\r
619 r = Panel.list_json_opt[:include]
\r
620 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
622 it '素材はライセンスを含んでいる' do
\r
623 r = Panel.list_json_opt[:include]
\r
624 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
627 r = Panel.show_include_opt
\r
628 r.has_key?(:speech_balloons).should be_true
\r
630 it 'フキダシはフキダシ枠を含んでいる' do
\r
631 r = Panel.show_include_opt
\r
632 r[:speech_balloons].has_key?(:balloons).should be_true
\r
634 it 'フキダシはセリフを含んでいる' do
\r
635 r = Panel.show_include_opt
\r
636 r[:speech_balloons].has_key?(:speeches).should be_true
\r
639 r = Panel.list_json_opt[:include]
\r
640 r.has_key?(:author).should be_true
\r
645 #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった
\r
646 #コマ絵とフキダシの整合チェックをする
\r
647 describe 'id収集に於いて' do
\r
648 context 'つつがなく終わるとき' do
\r
649 it '第一パラメータで指定された配列中から第二引数のidを収集している' do
\r
650 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
651 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
652 r = Panel.collect_element_value a, :panel_id
\r
653 r.should eq [1, 2, 3, 4]
\r
656 context 'Nil除外指示があるとき' do
\r
657 it '収集したpanel_idのうちnilは除外している' do
\r
658 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}],
\r
659 [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
660 r = Panel.collect_element_value a, :panel_id, true
\r
661 r.should eq [1, 2, 3, 4]
\r
665 describe 'id一致チェックに於いて' do
\r
666 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
667 context '親が既存(idが数値)のとき' do
\r
668 it 'すべてid一致するときTrueを返す' do
\r
669 r = Panel.validate_id [1, 1, 1, 1], 1
\r
672 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
673 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
676 it 'すべて数値でも一致しないときFalseを返す' do
\r
677 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
680 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
681 r = Panel.validate_id [1, 1, nil, 2], 1
\r
685 context '親が新規(idがNil)のとき' do
\r
686 it 'すべてNilはTrueを返す' do
\r
687 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
690 it 'すべてnilでなければFalseを返す' do
\r
691 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
696 describe 'idチェック単体に於いて' do
\r
698 # @pp = Factory :panel_picture, :panel_id => @panel.id, :t => 1
\r
700 context 'つつがなく終わるとき' do
\r
701 it 'idを収集依頼している' do
\r
702 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
703 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
704 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
705 r = Panel.validate_element_id [], :panel_id, nil
\r
707 it '収集したidを一致チェック依頼している' do
\r
708 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
709 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
710 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
711 r = Panel.validate_element_id [], :panel_id, nil
\r
715 #依頼チェックだけでは不安なので最低限のチェックを
\r
716 context 'コマ新規のとき' do
\r
717 it 'コマ絵で正常通過している' do
\r
718 @panel = Factory.build :panel, :author_id => @author.id
\r
719 @panel.panel_pictures.build(
\r
720 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
722 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
725 it 'フキダシで正常通過している' do
\r
726 @panel = Factory.build :panel, :author_id => @author.id
\r
727 @panel.speech_balloons.build(
\r
728 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
730 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
734 context 'コマ既存のとき' do
\r
735 it 'コマ絵で正常通過している' do
\r
736 @panel = Factory :panel, :author_id => @author.id
\r
737 @panel.panel_pictures.build(
\r
738 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
740 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
743 it 'フキダシで正常通過している' do
\r
744 @panel = Factory :panel, :author_id => @author.id
\r
745 @panel.speech_balloons.build(
\r
746 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
748 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
752 context 'フキダシ新規のとき' do
\r
753 it 'バルーンで正常通過している' do
\r
754 @panel = Factory.build :panel, :author_id => @author.id
\r
755 @panel.speech_balloons.build(
\r
756 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
758 @panel.speech_balloons.first.balloons.build(
\r
759 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
761 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
764 it 'セリフで正常通過している' do
\r
765 @panel = Factory.build :panel, :author_id => @author.id
\r
766 @panel.speech_balloons.build(
\r
767 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
769 @panel.speech_balloons.first.speeches.build(
\r
770 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
772 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
777 describe 'idチェックリスト生成に於いて' do
\r
779 @panel = Factory.build :panel, :author_id => @author.id
\r
781 context 'つつがなく終わるとき' do
\r
782 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
783 @panel.panel_pictures.build(
\r
784 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
786 @panel.speech_balloons.build(
\r
787 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
789 @panel.speech_balloons.first.balloons.build(
\r
790 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
792 @panel.speech_balloons.first.speeches.build(
\r
793 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
795 r = @panel.validate_id_list
\r
796 r.should have(2).items
\r
798 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
799 @panel.panel_pictures.build(
\r
800 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
802 sb1 = @panel.speech_balloons.build(
\r
803 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
805 sb1.balloons.build(
\r
806 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
808 sb1.speeches.build(
\r
809 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
811 sb2 = @panel.speech_balloons.build(
\r
812 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
814 sb2.balloons.build(
\r
815 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
817 sb2.speeches.build(
\r
818 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
820 r = @panel.validate_id_list
\r
821 r.should have(3).items
\r
825 describe 'idチェック複合に於いて' do
\r
827 @panel = Factory.build :panel, :author_id => @author.id
\r
829 context 'つつがなく終わるとき' do
\r
830 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
831 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
832 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
833 @panel.panel_pictures.build(
\r
834 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
836 sb1 = @panel.speech_balloons.build(
\r
837 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
839 sb1.balloons.build(
\r
840 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
842 sb1.speeches.build(
\r
843 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
845 r = Panel.validate_elements_id(@panel.validate_id_list)
\r
849 describe 'シリアライズチェックに於いて' do
\r
850 context 'つつがなく終わるとき' do
\r
851 it '0からシリアライズされているならTrueを返す' do
\r
852 r = Panel.validate_t [0, 1, 2]
\r
855 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
856 r = Panel.validate_t [0, 2, 1]
\r
859 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
860 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
865 it '0から始まらないならFalseを返す' do
\r
866 r = Panel.validate_t [1, 2, 3]
\r
869 it '連続していないならFalseを返す' do
\r
870 r = Panel.validate_t [0, 1, 2, 4]
\r
873 it '連続していないならFalseを返す' do
\r
874 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
879 describe 'tチェック単体に於いて' do
\r
882 context 'つつがなく終わるとき' do
\r
883 it 'コマ絵とフキダシのtを収集依頼している' do
\r
884 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
885 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
886 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
887 r = Panel.validate_element_t [], :t
\r
889 it '収集したtをシリアライズチェック依頼している' do
\r
890 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
891 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
892 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
893 r = Panel.validate_element_t [], :t
\r
897 #依頼チェックだけでは不安なので最低限のチェックを
\r
899 it 'コマ絵で正常通過している' do
\r
900 @panel = Factory.build :panel, :author_id => @author.id
\r
901 @panel.panel_pictures.build(
\r
902 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
904 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
907 it 'フキダシで正常通過している' do
\r
908 @panel = Factory.build :panel, :author_id => @author.id
\r
909 @panel.speech_balloons.build(
\r
910 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)
\r
912 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
917 it 'コマ絵で正常通過している' do
\r
918 @panel = Factory :panel, :author_id => @author.id
\r
919 @panel.panel_pictures.build(
\r
920 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
922 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
925 it 'フキダシで正常通過している' do
\r
926 @panel = Factory :panel, :author_id => @author.id
\r
927 @panel.speech_balloons.build(
\r
928 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
930 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
935 describe '複合チェックに於いて' do
\r
936 context 'つつがなく終わるとき' do
\r
938 @panel = Factory.build :panel, :author_id => @author.id
\r
939 @panel.panel_pictures.build(
\r
940 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
942 @panel.panel_pictures.build(
\r
943 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
945 sb1 = @panel.speech_balloons.build(
\r
946 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
948 sb1.balloons.build(
\r
949 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
951 sb1.speeches.build(
\r
952 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
954 sb2 = @panel.speech_balloons.build(
\r
955 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
957 sb2.balloons.build(
\r
958 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
960 sb2.speeches.build(
\r
961 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
963 r = @panel.validate_child
\r