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
17 @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
18 @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
19 @sbt = Factory :speech_balloon_template
\r
22 describe '検証に於いて' do
\r
26 it 'オーソドックスなデータなら通る' do
\r
27 @panel = Factory.build :panel, :author_id => @author.id
\r
28 @panel.should be_valid
\r
31 context 'widthを検証するとき' do
\r
33 @panel = Factory.build :panel, :author_id => @author.id
\r
37 @panel.should be_valid
\r
41 @panel.should_not be_valid
\r
45 @panel.should_not be_valid
\r
49 @panel.should_not be_valid
\r
53 @panel.should_not be_valid
\r
56 context 'heightを検証するとき' do
\r
58 @panel = Factory.build :panel, :author_id => @author.id
\r
62 @panel.should be_valid
\r
66 @panel.should_not be_valid
\r
70 @panel.should_not be_valid
\r
74 @panel.should_not be_valid
\r
78 @panel.should_not be_valid
\r
81 context 'borderを検証するとき' do
\r
83 @panel = Factory.build :panel, :author_id => @author.id
\r
87 @panel.should be_valid
\r
91 @panel.should_not be_valid
\r
95 @panel.should_not be_valid
\r
98 @panel.border = '-1'
\r
99 @panel.should_not be_valid
\r
103 @panel.should be_valid
\r
106 context 'xを検証するとき' do
\r
108 @panel = Factory.build :panel, :author_id => @author.id
\r
112 @panel.should be_valid
\r
114 it '数値でなければ失敗する' do
\r
116 @panel.should_not be_valid
\r
120 @panel.should be_valid
\r
124 @panel.should be_valid
\r
127 context 'yを検証するとき' do
\r
129 @panel = Factory.build :panel, :author_id => @author.id
\r
133 @panel.should be_valid
\r
135 it '数値でなければ失敗する' do
\r
137 @panel.should_not be_valid
\r
141 @panel.should be_valid
\r
145 @panel.should be_valid
\r
148 context 'zを検証するとき' do
\r
150 @panel = Factory.build :panel, :author_id => @author.id
\r
154 @panel.should be_valid
\r
156 it '数値でなければ失敗する' do
\r
158 @panel.should_not be_valid
\r
162 @panel.should_not be_valid
\r
166 @panel.should_not be_valid
\r
169 context 'author_idを検証するとき' do
\r
171 @panel = Factory.build :panel, :author_id => @author.id
\r
174 @panel.author_id = @author.id
\r
175 @panel.should be_valid
\r
178 @panel.author_id = nil
\r
179 @panel.should_not be_valid
\r
181 it '数値でなければ失敗する' do
\r
182 @panel.author_id = 'a'
\r
183 @panel.should_not be_valid
\r
185 it '存在する絵師でなければ失敗する' do
\r
186 @panel.author_id = 0
\r
187 @panel.should_not be_valid
\r
190 context '全体を検証するとき' do
\r
192 @panel = Factory :panel, :author_id => @author.id
\r
197 describe 'デフォルト値補充に於いて' do
\r
199 @panel = Factory.build :panel, :author_id => @author.id
\r
201 it 'borderは2を補充する' do
\r
202 @panel.border = nil
\r
203 @panel.supply_default
\r
204 @panel.border.should eq 2
\r
208 describe '上書き補充に於いて' do
\r
210 @panel = Factory.build :panel, :author_id => @author.id
\r
212 context 'author_idを補充' do
\r
213 it 'ログイン中の作家idを補充する' do
\r
214 @panel.author_id = nil
\r
215 @panel.overwrite @author
\r
216 @panel.author_id.should eq @author.id
\r
222 describe '作者判定に於いて' do
\r
226 panel = Factory :panel, :author_id => @author.id
\r
227 panel.own?(@author).should == true
\r
230 panel = Factory :panel, :author_id => @author.id
\r
231 panel.own?(@other_author).should == false
\r
234 panel = Factory :panel, :author_id => @author.id
\r
235 panel.own?(nil).should == false
\r
238 describe '閲覧許可に於いて' do
\r
241 it '自作のコマを見るときは許可する' do
\r
242 Panel.any_instance.stub(:own?).and_return(true)
\r
243 Panel.any_instance.stub(:publish?).and_return(true)
\r
244 panel = Factory :panel, :author_id => @author.id
\r
245 panel.visible?(@author).should == true
\r
247 it '自作のコマは非公開でも許可する' do
\r
248 Panel.any_instance.stub(:own?).and_return(true)
\r
249 Panel.any_instance.stub(:publish?).and_return(false)
\r
250 panel = Factory :panel, :author_id => @author.id
\r
251 panel.visible?(@author).should == true
\r
253 it '他人のコマでも公開なら許可する' do
\r
254 Panel.any_instance.stub(:own?).and_return(false)
\r
255 Panel.any_instance.stub(:publish?).and_return(true)
\r
256 panel = Factory :panel, :author_id => @author.id
\r
257 panel.visible?(@author).should == true
\r
259 it '他人のコマで非公開なら許可しない' do
\r
260 Panel.any_instance.stub(:own?).and_return(false)
\r
261 Panel.any_instance.stub(:publish?).and_return(false)
\r
262 panel = Factory :panel, :author_id => @author.id
\r
263 panel.visible?(@author).should == false
\r
266 describe '単体取得に於いて' do
\r
268 @panel = Factory :panel, :author_id => @author.id
\r
271 Panel.any_instance.stub(:visible?).and_return(true)
\r
272 pl = Panel.show @panel.id, @author
\r
273 pl.should eq @panel
\r
275 context '他人の非公開コミックのコマを開こうとしたとき' do
\r
276 it '403Forbidden例外を返す' do
\r
277 Panel.any_instance.stub(:visible?).and_return(false)
\r
279 Panel.show @panel.id, @author
\r
280 }.should raise_error(ActiveRecord::Forbidden)
\r
283 context '存在しないコマを開こうとしたとき' do
\r
284 it '404RecordNotFound例外を返す' do
\r
286 Panel.show 110, @author
\r
287 }.should raise_error(ActiveRecord::RecordNotFound)
\r
291 describe '単体取得に於いて' do
\r
293 @panel = Factory :panel, :author_id => @author.id
\r
296 Panel.any_instance.stub(:own?).and_return(true)
\r
297 pl = Panel.edit @panel.id, @author
\r
298 pl.should eq @panel
\r
300 context '他人のコマを開こうとしたとき' do
\r
301 it '403Forbidden例外を返す' do
\r
302 Panel.any_instance.stub(:own?).and_return(false)
\r
304 Panel.edit @panel.id, @author
\r
305 }.should raise_error(ActiveRecord::Forbidden)
\r
308 context '存在しないコマを開こうとしたとき' do
\r
309 it '404RecordNotFound例外を返す' do
\r
311 Panel.edit 110, @author
\r
312 }.should raise_error(ActiveRecord::RecordNotFound)
\r
316 describe '関連テーブルプションに於いて' do
\r
317 context 'オプションがないとき' do
\r
318 it '3つの項目を含んでいる' do
\r
319 r = Panel.show_include_opt
\r
320 r.should have(3).items
\r
323 r = Panel.show_include_opt
\r
324 r.has_key?(:panel_pictures).should be_true
\r
326 it 'コマ絵は素材を含んでいる' do
\r
327 r = Panel.show_include_opt
\r
328 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
330 it '素材は絵師を含んでいる' do
\r
331 r = Panel.show_include_opt
\r
332 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
334 it '素材はライセンスを含んでいる' do
\r
335 r = Panel.show_include_opt
\r
336 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
339 r = Panel.show_include_opt
\r
340 r.has_key?(:speech_balloons).should be_true
\r
342 it 'フキダシはフキダシ枠を含んでいる' do
\r
343 r = Panel.show_include_opt
\r
344 r[:speech_balloons].has_key?(:balloons).should be_true
\r
346 it 'フキダシはセリフを含んでいる' do
\r
347 r = Panel.show_include_opt
\r
348 r[:speech_balloons].has_key?(:speeches).should be_true
\r
351 r = Panel.show_include_opt
\r
352 r.has_key?(:author).should be_true
\r
355 context 'オプションで原画を含ませたとき' do
\r
356 it '4つの項目を含んでいる' do
\r
357 r = Panel.show_include_opt(:include => {:test => {}})
\r
358 r.should have(4).items
\r
361 r = Panel.show_include_opt(:include => {:test => {}})
\r
362 r.has_key?(:test).should be_true
\r
366 describe 'json単体出力オプションに於いて' do
\r
367 it 'includeキーを含んでいる' do
\r
368 r = Panel.show_json_include_opt
\r
369 r.has_key?(:include).should be_true
\r
371 it '3つの項目を含んでいる' do
\r
372 r = Panel.show_json_include_opt[:include]
\r
373 r.should have(3).items
\r
376 r = Panel.show_json_include_opt[:include]
\r
377 r.has_key?(:panel_pictures).should be_true
\r
379 it 'コマ絵は素材を含んでいる' do
\r
380 r = Panel.show_json_include_opt[:include]
\r
381 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
383 it '素材は絵師を含んでいる' do
\r
384 r = Panel.show_json_include_opt[:include]
\r
385 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
387 it '素材はライセンスを含んでいる' do
\r
388 r = Panel.show_json_include_opt[:include]
\r
389 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
392 r = Panel.show_include_opt
\r
393 r.has_key?(:speech_balloons).should be_true
\r
395 it 'フキダシはフキダシ枠を含んでいる' do
\r
396 r = Panel.show_include_opt
\r
397 r[:speech_balloons].has_key?(:balloons).should be_true
\r
399 it 'フキダシはセリフを含んでいる' do
\r
400 r = Panel.show_include_opt
\r
401 r[:speech_balloons].has_key?(:speeches).should be_true
\r
404 r = Panel.show_json_include_opt[:include]
\r
405 r.has_key?(:author).should be_true
\r
408 describe '一覧取得に於いて' do
\r
410 @panel = Factory :panel, :author_id => @author.id
\r
412 context 'page補正について' do
\r
413 it '文字列から数値に変換される' do
\r
414 Panel.page('8').should eq 8
\r
416 it 'nilの場合は1になる' do
\r
417 Panel.page().should eq 1
\r
419 it '0以下の場合は1になる' do
\r
420 Panel.page('0').should eq 1
\r
423 context 'page_size補正について' do
\r
424 it '文字列から数値に変換される' do
\r
425 Panel.page_size('7').should eq 7
\r
427 it 'nilの場合はPanel.default_page_sizeになる' do
\r
428 Panel.page_size().should eq Panel.default_page_size
\r
430 it '0以下の場合はPanel.default_page_sizeになる' do
\r
431 Panel.page_size('0').should eq Panel.default_page_size
\r
433 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
434 Panel.page_size('1000').should eq Panel.max_page_size
\r
439 pl.should eq [@panel]
\r
442 npl = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
444 pl.should eq [npl, @panel]
\r
446 it '非公開のコマは含まない' do
\r
447 npl = Factory :panel, :author_id => @author.id, :publish => 0
\r
449 pl.should eq [@panel]
\r
451 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
453 @npl2 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
454 @npl3 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
455 @npl4 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
456 @npl5 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
457 Panel.stub(:default_page_size).and_return(2)
\r
461 pl.should have(2).items
\r
463 it 'page=1なら末尾2件を返す' do
\r
465 pl = Panel.list( {}, 1)
\r
466 pl.should eq [@npl5, @npl4]
\r
468 it 'page=2なら中間2件を返す' do
\r
469 pl = Panel.list({}, 2)
\r
470 pl.should eq [@npl3, @npl2]
\r
472 it 'page=3なら先頭1件を返す' do
\r
473 pl = Panel.list({}, 3)
\r
474 pl.should eq [@panel]
\r
478 describe 'list関連テーブルプションに於いて' do
\r
479 it 'includeキーを含んでいる' do
\r
481 r.has_key?(:include).should be_true
\r
483 it '3つの項目を含んでいる' do
\r
484 r = Panel.list_opt[:include]
\r
485 r.should have(3).items
\r
488 r = Panel.list_opt[:include]
\r
489 r.has_key?(:panel_pictures).should be_true
\r
491 it 'コマ絵は素材を含んでいる' do
\r
492 r = Panel.list_opt[:include]
\r
493 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
495 it '素材は絵師を含んでいる' do
\r
496 r = Panel.list_opt[:include]
\r
497 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
499 it '素材はライセンスを含んでいる' do
\r
500 r = Panel.list_opt[:include]
\r
501 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
504 r = Panel.show_include_opt
\r
505 r.has_key?(:speech_balloons).should be_true
\r
507 it 'フキダシはフキダシ枠を含んでいる' do
\r
508 r = Panel.show_include_opt
\r
509 r[:speech_balloons].has_key?(:balloons).should be_true
\r
511 it 'フキダシはセリフを含んでいる' do
\r
512 r = Panel.show_include_opt
\r
513 r[:speech_balloons].has_key?(:speeches).should be_true
\r
516 r = Panel.list_opt[:include]
\r
517 r.has_key?(:author).should be_true
\r
520 describe 'json一覧出力オプションに於いて' do
\r
521 it 'includeキーを含んでいる' do
\r
522 r = Panel.list_json_opt
\r
523 r.has_key?(:include).should be_true
\r
525 it '3つの項目を含んでいる' do
\r
526 r = Panel.list_json_opt[:include]
\r
527 r.should have(3).items
\r
530 r = Panel.list_json_opt[:include]
\r
531 r.has_key?(:panel_pictures).should be_true
\r
533 it 'コマ絵は素材を含んでいる' do
\r
534 r = Panel.list_json_opt[:include]
\r
535 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
537 it '素材は絵師を含んでいる' do
\r
538 r = Panel.list_json_opt[:include]
\r
539 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
541 it '素材はライセンスを含んでいる' do
\r
542 r = Panel.list_json_opt[:include]
\r
543 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
546 r = Panel.show_include_opt
\r
547 r.has_key?(:speech_balloons).should be_true
\r
549 it 'フキダシはフキダシ枠を含んでいる' do
\r
550 r = Panel.show_include_opt
\r
551 r[:speech_balloons].has_key?(:balloons).should be_true
\r
553 it 'フキダシはセリフを含んでいる' do
\r
554 r = Panel.show_include_opt
\r
555 r[:speech_balloons].has_key?(:speeches).should be_true
\r
558 r = Panel.list_json_opt[:include]
\r
559 r.has_key?(:author).should be_true
\r
564 #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった
\r
565 #コマ絵とフキダシの整合チェックをする
\r
566 describe 'id収集に於いて' do
\r
567 context 'つつがなく終わるとき' do
\r
568 it '第一パラメータで指定された配列中から第二引数のidを収集している' do
\r
569 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
570 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
571 r = Panel.collect_element_value a, :panel_id
\r
572 r.should eq [1, 2, 3, 4]
\r
575 context 'Nil除外指示があるとき' do
\r
576 it '収集したpanel_idのうちnilは除外している' do
\r
577 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}],
\r
578 [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
579 r = Panel.collect_element_value a, :panel_id, true
\r
580 r.should eq [1, 2, 3, 4]
\r
584 describe 'id一致チェックに於いて' do
\r
585 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
586 context '親が既存(idが数値)のとき' do
\r
587 it 'すべてid一致するときTrueを返す' do
\r
588 r = Panel.validate_id [1, 1, 1, 1], 1
\r
591 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
592 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
595 it 'すべて数値でも一致しないときFalseを返す' do
\r
596 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
599 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
600 r = Panel.validate_id [1, 1, nil, 2], 1
\r
604 context '親が新規(idがNil)のとき' do
\r
605 it 'すべてNilはTrueを返す' do
\r
606 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
609 it 'すべてnilでなければFalseを返す' do
\r
610 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
615 describe 'idチェック単体に於いて' do
\r
617 # @pp = Factory :panel_picture, :panel_id => @panel.id, :t => 1
\r
619 context 'つつがなく終わるとき' do
\r
620 it 'idを収集依頼している' do
\r
621 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
622 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
623 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
624 r = Panel.validate_element_id [], :panel_id, nil
\r
626 it '収集したidを一致チェック依頼している' do
\r
627 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
628 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
629 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
630 r = Panel.validate_element_id [], :panel_id, nil
\r
634 #依頼チェックだけでは不安なので最低限のチェックを
\r
635 context 'コマ新規のとき' do
\r
636 it 'コマ絵で正常通過している' do
\r
637 @panel = Factory.build :panel, :author_id => @author.id
\r
638 @panel.panel_pictures.build(
\r
639 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
641 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
644 it 'フキダシで正常通過している' do
\r
645 @panel = Factory.build :panel, :author_id => @author.id
\r
646 @panel.speech_balloons.build(
\r
647 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
649 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
653 context 'コマ既存のとき' do
\r
654 it 'コマ絵で正常通過している' do
\r
655 @panel = Factory :panel, :author_id => @author.id
\r
656 @panel.panel_pictures.build(
\r
657 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
659 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
662 it 'フキダシで正常通過している' do
\r
663 @panel = Factory :panel, :author_id => @author.id
\r
664 @panel.speech_balloons.build(
\r
665 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
667 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
671 context 'フキダシ新規のとき' do
\r
672 it 'バルーンで正常通過している' do
\r
673 @panel = Factory.build :panel, :author_id => @author.id
\r
674 @panel.speech_balloons.build(
\r
675 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
677 @panel.speech_balloons.first.balloons.build(
\r
678 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
680 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
683 it 'セリフで正常通過している' do
\r
684 @panel = Factory.build :panel, :author_id => @author.id
\r
685 @panel.speech_balloons.build(
\r
686 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
688 @panel.speech_balloons.first.speeches.build(
\r
689 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
691 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
696 describe 'idチェックリスト生成に於いて' do
\r
698 @panel = Factory.build :panel, :author_id => @author.id
\r
700 context 'つつがなく終わるとき' do
\r
701 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
702 @panel.panel_pictures.build(
\r
703 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
705 @panel.speech_balloons.build(
\r
706 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
708 @panel.speech_balloons.first.balloons.build(
\r
709 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
711 @panel.speech_balloons.first.speeches.build(
\r
712 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
714 r = @panel.validate_id_list
\r
715 r.should have(2).items
\r
717 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
718 @panel.panel_pictures.build(
\r
719 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
721 sb1 = @panel.speech_balloons.build(
\r
722 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
724 sb1.balloons.build(
\r
725 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
727 sb1.speeches.build(
\r
728 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
730 sb2 = @panel.speech_balloons.build(
\r
731 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
733 sb2.balloons.build(
\r
734 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
736 sb2.speeches.build(
\r
737 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
739 r = @panel.validate_id_list
\r
740 r.should have(3).items
\r
744 describe 'idチェック複合に於いて' do
\r
746 @panel = Factory.build :panel, :author_id => @author.id
\r
748 context 'つつがなく終わるとき' do
\r
749 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
750 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
751 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
752 @panel.panel_pictures.build(
\r
753 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
755 sb1 = @panel.speech_balloons.build(
\r
756 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
758 sb1.balloons.build(
\r
759 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
761 sb1.speeches.build(
\r
762 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
764 r = Panel.validate_elements_id(@panel.validate_id_list)
\r
768 describe 'シリアライズチェックに於いて' do
\r
769 context 'つつがなく終わるとき' do
\r
770 it '0からシリアライズされているならTrueを返す' do
\r
771 r = Panel.validate_t [0, 1, 2]
\r
774 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
775 r = Panel.validate_t [0, 2, 1]
\r
778 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
779 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
784 it '0から始まらないならFalseを返す' do
\r
785 r = Panel.validate_t [1, 2, 3]
\r
788 it '連続していないならFalseを返す' do
\r
789 r = Panel.validate_t [0, 1, 2, 4]
\r
792 it '連続していないならFalseを返す' do
\r
793 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
798 describe 'tチェック単体に於いて' do
\r
801 context 'つつがなく終わるとき' do
\r
802 it 'コマ絵とフキダシのtを収集依頼している' do
\r
803 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
804 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
805 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
806 r = Panel.validate_element_t [], :t
\r
808 it '収集したtをシリアライズチェック依頼している' do
\r
809 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
810 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
811 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
812 r = Panel.validate_element_t [], :t
\r
816 #依頼チェックだけでは不安なので最低限のチェックを
\r
818 it 'コマ絵で正常通過している' do
\r
819 @panel = Factory.build :panel, :author_id => @author.id
\r
820 @panel.panel_pictures.build(
\r
821 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
823 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
826 it 'フキダシで正常通過している' do
\r
827 @panel = Factory.build :panel, :author_id => @author.id
\r
828 @panel.speech_balloons.build(
\r
829 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)
\r
831 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
836 it 'コマ絵で正常通過している' do
\r
837 @panel = Factory :panel, :author_id => @author.id
\r
838 @panel.panel_pictures.build(
\r
839 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
841 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
844 it 'フキダシで正常通過している' do
\r
845 @panel = Factory :panel, :author_id => @author.id
\r
846 @panel.speech_balloons.build(
\r
847 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
849 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
854 describe '複合チェックに於いて' do
\r
855 context 'つつがなく終わるとき' do
\r
857 @panel = Factory.build :panel, :author_id => @author.id
\r
858 @panel.panel_pictures.build(
\r
859 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
861 @panel.panel_pictures.build(
\r
862 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
864 sb1 = @panel.speech_balloons.build(
\r
865 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
867 sb1.balloons.build(
\r
868 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
870 sb1.speeches.build(
\r
871 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
873 sb2 = @panel.speech_balloons.build(
\r
874 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
876 sb2.balloons.build(
\r
877 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
879 sb2.speeches.build(
\r
880 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
882 r = @panel.validate_child
\r
887 describe '複合チェックに於いて' do
\r
888 context 'つつがなく終わるとき' do
\r
890 @panel = Factory.build :panel, :author_id => @author.id
\r
891 @panel.panel_pictures.build(
\r
892 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
894 @panel.panel_pictures.build(
\r
895 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
897 sb1 = @panel.speech_balloons.build(
\r
898 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
900 sb1.balloons.build(
\r
901 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
903 sb1.speeches.build(
\r
904 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
906 sb2 = @panel.speech_balloons.build(
\r
907 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
909 sb2.balloons.build(
\r
910 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
912 sb2.speeches.build(
\r
913 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
915 r = @panel.validate_child
\r
920 describe '保存に於いて' do
\r
921 context 'つつがなく終わるとき' do
\r
922 it 'idチェックを依頼している' do
\r
923 Panel.should_receive(:validate_elements_id).with(any_args).exactly(1)
\r
924 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
925 @panel = Factory.build :panel, :author_id => @author.id
\r
929 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
930 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
931 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
932 @panel = Factory.build :panel, :author_id => @author.id
\r
936 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
937 @panel = Factory.build :panel, :author_id => @author.id
\r
941 it 'エラーメッセージがセットされていない' do
\r
942 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
943 @panel = Factory :panel, :author_id => @author.id
\r
945 @panel.errors.empty?.should be_true
\r
949 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
950 @panel = Factory.build :panel, :author_id => @author.id
\r
955 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
956 @panel = Factory.build :panel, :author_id => @author.id
\r
959 }.should change(Panel, :count)
\r
964 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
965 @panel = Factory :panel, :author_id => @author.id
\r
970 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
971 @panel = Factory :panel, :author_id => @author.id
\r
974 }.should_not change(Panel, :count)
\r
978 context 'idチェックが失敗するとき' do
\r
980 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
981 @panel = Factory :panel, :author_id => @author.id
\r
985 it 'エラーメッセージがセットされている' do
\r
986 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
987 @panel = Factory :panel, :author_id => @author.id
\r
989 @panel.errors.empty?.should be_false
\r
992 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
993 @panel = Factory.build :panel, :author_id => @author.id
\r
996 }.should_not change(Panel, :count)
\r