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 @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
\r
14 @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id
\r
15 @sbt = Factory :speech_balloon_template
\r
18 describe '検証に於いて' do
\r
22 it 'オーソドックスなデータなら通る' do
\r
23 @panel = Factory.build :panel, :author_id => @author.id
\r
24 @panel.should be_valid
\r
27 context 'widthを検証するとき' do
\r
29 @panel = Factory.build :panel, :author_id => @author.id
\r
33 @panel.should be_valid
\r
37 @panel.should_not be_valid
\r
41 @panel.should_not be_valid
\r
45 @panel.should_not be_valid
\r
49 @panel.should_not be_valid
\r
52 context 'heightを検証するとき' do
\r
54 @panel = Factory.build :panel, :author_id => @author.id
\r
58 @panel.should be_valid
\r
62 @panel.should_not be_valid
\r
66 @panel.should_not be_valid
\r
70 @panel.should_not be_valid
\r
74 @panel.should_not be_valid
\r
77 context 'borderを検証するとき' do
\r
79 @panel = Factory.build :panel, :author_id => @author.id
\r
83 @panel.should be_valid
\r
87 @panel.should_not be_valid
\r
91 @panel.should_not be_valid
\r
94 @panel.border = '-1'
\r
95 @panel.should_not be_valid
\r
99 @panel.should be_valid
\r
102 context 'xを検証するとき' do
\r
104 @panel = Factory.build :panel, :author_id => @author.id
\r
108 @panel.should be_valid
\r
110 it '数値でなければ失敗する' do
\r
112 @panel.should_not be_valid
\r
116 @panel.should be_valid
\r
120 @panel.should be_valid
\r
123 context 'yを検証するとき' do
\r
125 @panel = Factory.build :panel, :author_id => @author.id
\r
129 @panel.should be_valid
\r
131 it '数値でなければ失敗する' do
\r
133 @panel.should_not be_valid
\r
137 @panel.should be_valid
\r
141 @panel.should be_valid
\r
144 context 'zを検証するとき' do
\r
146 @panel = Factory.build :panel, :author_id => @author.id
\r
150 @panel.should be_valid
\r
152 it '数値でなければ失敗する' do
\r
154 @panel.should_not be_valid
\r
158 @panel.should_not be_valid
\r
162 @panel.should_not be_valid
\r
165 context 'author_idを検証するとき' do
\r
167 @panel = Factory.build :panel, :author_id => @author.id
\r
170 @panel.author_id = @author.id
\r
171 @panel.should be_valid
\r
174 @panel.author_id = nil
\r
175 @panel.should_not be_valid
\r
177 it '数値でなければ失敗する' do
\r
178 @panel.author_id = 'a'
\r
179 @panel.should_not be_valid
\r
181 it '存在する絵師でなければ失敗する' do
\r
182 @panel.author_id = 0
\r
183 @panel.should_not be_valid
\r
186 context '全体を検証するとき' do
\r
188 @panel = Factory :panel, :author_id => @author.id
\r
193 describe 'デフォルト値補充に於いて' do
\r
195 @panel = Factory.build :panel, :author_id => @author.id
\r
197 it 'borderは2を補充する' do
\r
198 @panel.border = nil
\r
199 @panel.supply_default
\r
200 @panel.border.should eq 2
\r
204 describe '上書き補充に於いて' do
\r
206 @panel = Factory.build :panel, :author_id => @author.id
\r
208 context 'author_idを補充' do
\r
209 it 'ログイン中の作家idを補充する' do
\r
210 @panel.author_id = nil
\r
211 @panel.overwrite @author
\r
212 @panel.author_id.should eq @author.id
\r
218 describe '作者判定に於いて' do
\r
222 panel = Factory :panel, :author_id => @author.id
\r
223 panel.own?(@author).should == true
\r
226 panel = Factory :panel, :author_id => @author.id
\r
227 panel.own?(@other_author).should == false
\r
230 panel = Factory :panel, :author_id => @author.id
\r
231 panel.own?(nil).should == false
\r
234 describe '閲覧許可に於いて' do
\r
237 it '自作のコマを見るときは許可する' do
\r
238 Panel.any_instance.stub(:own?).and_return(true)
\r
239 Panel.any_instance.stub(:publish?).and_return(true)
\r
240 panel = Factory :panel, :author_id => @author.id
\r
241 panel.visible?(@author).should == true
\r
243 it '自作のコマは非公開でも許可する' do
\r
244 Panel.any_instance.stub(:own?).and_return(true)
\r
245 Panel.any_instance.stub(:publish?).and_return(false)
\r
246 panel = Factory :panel, :author_id => @author.id
\r
247 panel.visible?(@author).should == true
\r
249 it '他人のコマでも公開なら許可する' do
\r
250 Panel.any_instance.stub(:own?).and_return(false)
\r
251 Panel.any_instance.stub(:publish?).and_return(true)
\r
252 panel = Factory :panel, :author_id => @author.id
\r
253 panel.visible?(@author).should == true
\r
255 it '他人のコマで非公開なら許可しない' do
\r
256 Panel.any_instance.stub(:own?).and_return(false)
\r
257 Panel.any_instance.stub(:publish?).and_return(false)
\r
258 panel = Factory :panel, :author_id => @author.id
\r
259 panel.visible?(@author).should == false
\r
262 describe '単体取得に於いて' do
\r
264 @panel = Factory :panel, :author_id => @author.id
\r
267 Comic.any_instance.stub(:visible?).and_return(true)
\r
268 pl = Panel.show @panel.id, @author
\r
269 pl.should eq @panel
\r
271 context '他人の非公開コミックのコマを開こうとしたとき' do
\r
272 it '403Forbidden例外を返す' do
\r
273 Panel.any_instance.stub(:visible?).and_return(false)
\r
275 Panel.show @panel.id, @author
\r
276 }.should raise_error(ActiveRecord::Forbidden)
\r
279 context '存在しないコマを開こうとしたとき' do
\r
280 it '404RecordNotFound例外を返す' do
\r
282 Panel.show 110, @author
\r
283 }.should raise_error(ActiveRecord::RecordNotFound)
\r
287 describe '関連テーブルプションに於いて' do
\r
288 context 'オプションがないとき' do
\r
289 it '3つの項目を含んでいる' do
\r
290 r = Panel.show_include_opt
\r
291 r.should have(3).items
\r
294 r = Panel.show_include_opt
\r
295 r.has_key?(:panel_pictures).should be_true
\r
297 it 'コマ絵は素材を含んでいる' do
\r
298 r = Panel.show_include_opt
\r
299 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
301 it '素材は絵師を含んでいる' do
\r
302 r = Panel.show_include_opt
\r
303 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
305 it '素材はライセンスを含んでいる' do
\r
306 r = Panel.show_include_opt
\r
307 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
310 r = Panel.show_include_opt
\r
311 r.has_key?(:speech_balloons).should be_true
\r
313 it 'フキダシはフキダシ枠を含んでいる' do
\r
314 r = Panel.show_include_opt
\r
315 r[:speech_balloons].has_key?(:balloons).should be_true
\r
317 it 'フキダシはセリフを含んでいる' do
\r
318 r = Panel.show_include_opt
\r
319 r[:speech_balloons].has_key?(:speeches).should be_true
\r
322 r = Panel.show_include_opt
\r
323 r.has_key?(:author).should be_true
\r
326 context 'オプションで原画を含ませたとき' do
\r
327 it '4つの項目を含んでいる' do
\r
328 r = Panel.show_include_opt(:include => {:test => {}})
\r
329 r.should have(4).items
\r
332 r = Panel.show_include_opt(:include => {:test => {}})
\r
333 r.has_key?(:test).should be_true
\r
337 describe 'json単体出力オプションに於いて' do
\r
338 it 'includeキーを含んでいる' do
\r
339 r = Panel.show_json_include_opt
\r
340 r.has_key?(:include).should be_true
\r
342 it '3つの項目を含んでいる' do
\r
343 r = Panel.show_json_include_opt[:include]
\r
344 r.should have(3).items
\r
347 r = Panel.show_json_include_opt[:include]
\r
348 r.has_key?(:panel_pictures).should be_true
\r
350 it 'コマ絵は素材を含んでいる' do
\r
351 r = Panel.show_json_include_opt[:include]
\r
352 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
354 it '素材は絵師を含んでいる' do
\r
355 r = Panel.show_json_include_opt[:include]
\r
356 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
358 it '素材はライセンスを含んでいる' do
\r
359 r = Panel.show_json_include_opt[:include]
\r
360 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
363 r = Panel.show_include_opt
\r
364 r.has_key?(:speech_balloons).should be_true
\r
366 it 'フキダシはフキダシ枠を含んでいる' do
\r
367 r = Panel.show_include_opt
\r
368 r[:speech_balloons].has_key?(:balloons).should be_true
\r
370 it 'フキダシはセリフを含んでいる' do
\r
371 r = Panel.show_include_opt
\r
372 r[:speech_balloons].has_key?(:speeches).should be_true
\r
375 r = Panel.show_json_include_opt[:include]
\r
376 r.has_key?(:author).should be_true
\r
379 describe '一覧取得に於いて' do
\r
381 @panel = Factory :panel, :author_id => @author.id
\r
383 context 'page補正について' do
\r
384 it '文字列から数値に変換される' do
\r
385 Panel.page('8').should eq 8
\r
387 it 'nilの場合は1になる' do
\r
388 Panel.page().should eq 1
\r
390 it '0以下の場合は1になる' do
\r
391 Panel.page('0').should eq 1
\r
394 context 'page_size補正について' do
\r
395 it '文字列から数値に変換される' do
\r
396 Panel.page_size('7').should eq 7
\r
398 it 'nilの場合はPanel.default_page_sizeになる' do
\r
399 Panel.page_size().should eq Panel.default_page_size
\r
401 it '0以下の場合はPanel.default_page_sizeになる' do
\r
402 Panel.page_size('0').should eq Panel.default_page_size
\r
404 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
405 Panel.page_size('1000').should eq Panel.max_page_size
\r
410 pl.should eq [@panel]
\r
413 npl = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
415 pl.should eq [npl, @panel]
\r
417 it '非公開のコマは含まない' do
\r
418 npl = Factory :panel, :author_id => @author.id, :publish => 0
\r
420 pl.should eq [@panel]
\r
422 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
424 @npl2 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
425 @npl3 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
426 @npl4 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
427 @npl5 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
428 Panel.stub(:default_page_size).and_return(2)
\r
432 pl.should have(2).items
\r
434 it 'page=1なら末尾2件を返す' do
\r
436 pl = Panel.list( {}, 1)
\r
437 pl.should eq [@npl5, @npl4]
\r
439 it 'page=2なら中間2件を返す' do
\r
440 pl = Panel.list({}, 2)
\r
441 pl.should eq [@npl3, @npl2]
\r
443 it 'page=3なら先頭1件を返す' do
\r
444 pl = Panel.list({}, 3)
\r
445 pl.should eq [@panel]
\r
449 describe 'list関連テーブルプションに於いて' do
\r
450 it 'includeキーを含んでいる' do
\r
452 r.has_key?(:include).should be_true
\r
454 it '3つの項目を含んでいる' do
\r
455 r = Panel.list_opt[:include]
\r
456 r.should have(3).items
\r
459 r = Panel.list_opt[:include]
\r
460 r.has_key?(:panel_pictures).should be_true
\r
462 it 'コマ絵は素材を含んでいる' do
\r
463 r = Panel.list_opt[:include]
\r
464 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
466 it '素材は絵師を含んでいる' do
\r
467 r = Panel.list_opt[:include]
\r
468 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
470 it '素材はライセンスを含んでいる' do
\r
471 r = Panel.list_opt[:include]
\r
472 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
475 r = Panel.show_include_opt
\r
476 r.has_key?(:speech_balloons).should be_true
\r
478 it 'フキダシはフキダシ枠を含んでいる' do
\r
479 r = Panel.show_include_opt
\r
480 r[:speech_balloons].has_key?(:balloons).should be_true
\r
482 it 'フキダシはセリフを含んでいる' do
\r
483 r = Panel.show_include_opt
\r
484 r[:speech_balloons].has_key?(:speeches).should be_true
\r
487 r = Panel.list_opt[:include]
\r
488 r.has_key?(:author).should be_true
\r
491 describe 'json一覧出力オプションに於いて' do
\r
492 it 'includeキーを含んでいる' do
\r
493 r = Panel.list_json_opt
\r
494 r.has_key?(:include).should be_true
\r
496 it '3つの項目を含んでいる' do
\r
497 r = Panel.list_json_opt[:include]
\r
498 r.should have(3).items
\r
501 r = Panel.list_json_opt[:include]
\r
502 r.has_key?(:panel_pictures).should be_true
\r
504 it 'コマ絵は素材を含んでいる' do
\r
505 r = Panel.list_json_opt[:include]
\r
506 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
508 it '素材は絵師を含んでいる' do
\r
509 r = Panel.list_json_opt[:include]
\r
510 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
512 it '素材はライセンスを含んでいる' do
\r
513 r = Panel.list_json_opt[:include]
\r
514 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
517 r = Panel.show_include_opt
\r
518 r.has_key?(:speech_balloons).should be_true
\r
520 it 'フキダシはフキダシ枠を含んでいる' do
\r
521 r = Panel.show_include_opt
\r
522 r[:speech_balloons].has_key?(:balloons).should be_true
\r
524 it 'フキダシはセリフを含んでいる' do
\r
525 r = Panel.show_include_opt
\r
526 r[:speech_balloons].has_key?(:speeches).should be_true
\r
529 r = Panel.list_json_opt[:include]
\r
530 r.has_key?(:author).should be_true
\r
535 #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった
\r
536 #コマ絵とフキダシの整合チェックをする
\r
537 describe 'id収集に於いて' do
\r
538 context 'つつがなく終わるとき' do
\r
539 it '第一パラメータで指定された配列中から第二引数のidを収集している' do
\r
540 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
541 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
542 r = Panel.collect_element_value a, :panel_id
\r
543 r.should eq [1, 2, 3, 4]
\r
546 context 'Nil除外指示があるとき' do
\r
547 it '収集したpanel_idのうちnilは除外している' do
\r
548 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}],
\r
549 [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
550 r = Panel.collect_element_value a, :panel_id, true
\r
551 r.should eq [1, 2, 3, 4]
\r
555 describe 'id一致チェックに於いて' do
\r
556 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
557 context '親が既存(idが数値)のとき' do
\r
558 it 'すべてid一致するときTrueを返す' do
\r
559 r = Panel.validate_id [1, 1, 1, 1], 1
\r
562 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
563 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
566 it 'すべて数値でも一致しないときFalseを返す' do
\r
567 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
570 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
571 r = Panel.validate_id [1, 1, nil, 2], 1
\r
575 context '親が新規(idがNil)のとき' do
\r
576 it 'すべてNilはTrueを返す' do
\r
577 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
580 it 'すべてnilでなければFalseを返す' do
\r
581 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
586 describe 'idチェック単体に於いて' do
\r
588 # @pp = Factory :panel_picture, :panel_id => @panel.id, :t => 1
\r
590 context 'つつがなく終わるとき' do
\r
591 it 'idを収集依頼している' do
\r
592 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
593 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
594 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
595 r = Panel.validate_element_id [], :panel_id, nil
\r
597 it '収集したidを一致チェック依頼している' do
\r
598 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
599 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
600 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
601 r = Panel.validate_element_id [], :panel_id, nil
\r
605 #依頼チェックだけでは不安なので最低限のチェックを
\r
606 context 'コマ新規のとき' do
\r
607 it 'コマ絵で正常通過している' do
\r
608 @panel = Factory.build :panel, :author_id => @author.id
\r
609 @panel.panel_pictures.build(
\r
610 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
612 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
615 it 'フキダシで正常通過している' do
\r
616 @panel = Factory.build :panel, :author_id => @author.id
\r
617 @panel.speech_balloons.build(
\r
618 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
620 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
624 context 'コマ既存のとき' do
\r
625 it 'コマ絵で正常通過している' do
\r
626 @panel = Factory :panel, :author_id => @author.id
\r
627 @panel.panel_pictures.build(
\r
628 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
630 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
633 it 'フキダシで正常通過している' do
\r
634 @panel = Factory :panel, :author_id => @author.id
\r
635 @panel.speech_balloons.build(
\r
636 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
638 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
642 context 'フキダシ新規のとき' do
\r
643 it 'バルーンで正常通過している' do
\r
644 @panel = Factory.build :panel, :author_id => @author.id
\r
645 @panel.speech_balloons.build(
\r
646 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
648 @panel.speech_balloons.first.balloons.build(
\r
649 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
651 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
654 it 'セリフで正常通過している' do
\r
655 @panel = Factory.build :panel, :author_id => @author.id
\r
656 @panel.speech_balloons.build(
\r
657 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
659 @panel.speech_balloons.first.speeches.build(
\r
660 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
662 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
667 describe 'idチェックリスト生成に於いて' do
\r
669 @panel = Factory.build :panel, :author_id => @author.id
\r
671 context 'つつがなく終わるとき' do
\r
672 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
673 @panel.panel_pictures.build(
\r
674 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
676 @panel.speech_balloons.build(
\r
677 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
679 @panel.speech_balloons.first.balloons.build(
\r
680 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
682 @panel.speech_balloons.first.speeches.build(
\r
683 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
685 r = @panel.validate_id_list
\r
686 r.should have(2).items
\r
688 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
689 @panel.panel_pictures.build(
\r
690 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
692 sb1 = @panel.speech_balloons.build(
\r
693 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
695 sb1.balloons.build(
\r
696 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
698 sb1.speeches.build(
\r
699 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
701 sb2 = @panel.speech_balloons.build(
\r
702 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
704 sb2.balloons.build(
\r
705 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
707 sb2.speeches.build(
\r
708 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
710 r = @panel.validate_id_list
\r
711 r.should have(3).items
\r
715 describe 'idチェック複合に於いて' do
\r
717 @panel = Factory.build :panel, :author_id => @author.id
\r
719 context 'つつがなく終わるとき' do
\r
720 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
721 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
722 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
723 @panel.panel_pictures.build(
\r
724 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
726 sb1 = @panel.speech_balloons.build(
\r
727 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
729 sb1.balloons.build(
\r
730 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
732 sb1.speeches.build(
\r
733 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
735 r = Panel.validate_elements_id(@panel.validate_id_list)
\r
739 describe 'シリアライズチェックに於いて' do
\r
740 context 'つつがなく終わるとき' do
\r
741 it '0からシリアライズされているならTrueを返す' do
\r
742 r = Panel.validate_t [0, 1, 2]
\r
745 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
746 r = Panel.validate_t [0, 2, 1]
\r
749 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
750 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
755 it '0から始まらないならFalseを返す' do
\r
756 r = Panel.validate_t [1, 2, 3]
\r
759 it '連続していないならFalseを返す' do
\r
760 r = Panel.validate_t [0, 1, 2, 4]
\r
763 it '連続していないならFalseを返す' do
\r
764 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
769 describe 'tチェック単体に於いて' do
\r
772 context 'つつがなく終わるとき' do
\r
773 it 'コマ絵とフキダシのtを収集依頼している' do
\r
774 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
775 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
776 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
777 r = Panel.validate_element_t [], :t
\r
779 it '収集したtをシリアライズチェック依頼している' do
\r
780 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
781 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
782 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
783 r = Panel.validate_element_t [], :t
\r
787 #依頼チェックだけでは不安なので最低限のチェックを
\r
789 it 'コマ絵で正常通過している' do
\r
790 @panel = Factory.build :panel, :author_id => @author.id
\r
791 @panel.panel_pictures.build(
\r
792 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
794 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
797 it 'フキダシで正常通過している' do
\r
798 @panel = Factory.build :panel, :author_id => @author.id
\r
799 @panel.speech_balloons.build(
\r
800 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)
\r
802 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
807 it 'コマ絵で正常通過している' do
\r
808 @panel = Factory :panel, :author_id => @author.id
\r
809 @panel.panel_pictures.build(
\r
810 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
812 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
815 it 'フキダシで正常通過している' do
\r
816 @panel = Factory :panel, :author_id => @author.id
\r
817 @panel.speech_balloons.build(
\r
818 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
820 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
825 describe '複合チェックに於いて' do
\r
826 context 'つつがなく終わるとき' do
\r
828 @panel = Factory.build :panel, :author_id => @author.id
\r
829 @panel.panel_pictures.build(
\r
830 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
832 @panel.panel_pictures.build(
\r
833 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
835 sb1 = @panel.speech_balloons.build(
\r
836 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
838 sb1.balloons.build(
\r
839 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
841 sb1.speeches.build(
\r
842 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
844 sb2 = @panel.speech_balloons.build(
\r
845 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
847 sb2.balloons.build(
\r
848 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
850 sb2.speeches.build(
\r
851 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
853 r = @panel.validate_child
\r
858 describe '複合チェックに於いて' do
\r
859 context 'つつがなく終わるとき' do
\r
861 @panel = Factory.build :panel, :author_id => @author.id
\r
862 @panel.panel_pictures.build(
\r
863 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
865 @panel.panel_pictures.build(
\r
866 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
868 sb1 = @panel.speech_balloons.build(
\r
869 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
871 sb1.balloons.build(
\r
872 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
874 sb1.speeches.build(
\r
875 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
877 sb2 = @panel.speech_balloons.build(
\r
878 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
880 sb2.balloons.build(
\r
881 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
883 sb2.speeches.build(
\r
884 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
886 r = @panel.validate_child
\r
891 describe '保存に於いて' do
\r
892 context 'つつがなく終わるとき' do
\r
893 it 'idチェックを依頼している' do
\r
894 Panel.should_receive(:validate_elements_id).with(any_args).exactly(1)
\r
895 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
896 @panel = Factory.build :panel, :author_id => @author.id
\r
900 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
901 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
902 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
903 @panel = Factory.build :panel, :author_id => @author.id
\r
907 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
908 @panel = Factory.build :panel, :author_id => @author.id
\r
912 it 'エラーメッセージがセットされていない' do
\r
913 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
914 @panel = Factory :panel, :author_id => @author.id
\r
916 @panel.errors.empty?.should be_true
\r
920 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
921 @panel = Factory.build :panel, :author_id => @author.id
\r
926 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
927 @panel = Factory.build :panel, :author_id => @author.id
\r
930 }.should change(Panel, :count)
\r
935 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
936 @panel = Factory :panel, :author_id => @author.id
\r
941 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
942 @panel = Factory :panel, :author_id => @author.id
\r
945 }.should_not change(Panel, :count)
\r
949 context 'idチェックが失敗するとき' do
\r
951 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
952 @panel = Factory :panel, :author_id => @author.id
\r
956 it 'エラーメッセージがセットされている' do
\r
957 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
958 @panel = Factory :panel, :author_id => @author.id
\r
960 @panel.errors.empty?.should be_false
\r
963 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
964 @panel = Factory.build :panel, :author_id => @author.id
\r
967 }.should_not change(Panel, :count)
\r