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 Panel.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
289 @panel = Factory :panel, :author_id => @author.id
\r
292 Panel.any_instance.stub(:own?).and_return(true)
\r
293 pl = Panel.edit @panel.id, @author
\r
294 pl.should eq @panel
\r
296 context '他人のコマを開こうとしたとき' do
\r
297 it '403Forbidden例外を返す' do
\r
298 Panel.any_instance.stub(:own?).and_return(false)
\r
300 Panel.edit @panel.id, @author
\r
301 }.should raise_error(ActiveRecord::Forbidden)
\r
304 context '存在しないコマを開こうとしたとき' do
\r
305 it '404RecordNotFound例外を返す' do
\r
307 Panel.edit 110, @author
\r
308 }.should raise_error(ActiveRecord::RecordNotFound)
\r
312 describe '関連テーブルプションに於いて' do
\r
313 context 'オプションがないとき' do
\r
314 it '3つの項目を含んでいる' do
\r
315 r = Panel.show_include_opt
\r
316 r.should have(3).items
\r
319 r = Panel.show_include_opt
\r
320 r.has_key?(:panel_pictures).should be_true
\r
322 it 'コマ絵は素材を含んでいる' do
\r
323 r = Panel.show_include_opt
\r
324 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
326 it '素材は絵師を含んでいる' do
\r
327 r = Panel.show_include_opt
\r
328 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
330 it '素材はライセンスを含んでいる' do
\r
331 r = Panel.show_include_opt
\r
332 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
335 r = Panel.show_include_opt
\r
336 r.has_key?(:speech_balloons).should be_true
\r
338 it 'フキダシはフキダシ枠を含んでいる' do
\r
339 r = Panel.show_include_opt
\r
340 r[:speech_balloons].has_key?(:balloons).should be_true
\r
342 it 'フキダシはセリフを含んでいる' do
\r
343 r = Panel.show_include_opt
\r
344 r[:speech_balloons].has_key?(:speeches).should be_true
\r
347 r = Panel.show_include_opt
\r
348 r.has_key?(:author).should be_true
\r
351 context 'オプションで原画を含ませたとき' do
\r
352 it '4つの項目を含んでいる' do
\r
353 r = Panel.show_include_opt(:include => {:test => {}})
\r
354 r.should have(4).items
\r
357 r = Panel.show_include_opt(:include => {:test => {}})
\r
358 r.has_key?(:test).should be_true
\r
362 describe 'json単体出力オプションに於いて' do
\r
363 it 'includeキーを含んでいる' do
\r
364 r = Panel.show_json_include_opt
\r
365 r.has_key?(:include).should be_true
\r
367 it '3つの項目を含んでいる' do
\r
368 r = Panel.show_json_include_opt[:include]
\r
369 r.should have(3).items
\r
372 r = Panel.show_json_include_opt[:include]
\r
373 r.has_key?(:panel_pictures).should be_true
\r
375 it 'コマ絵は素材を含んでいる' do
\r
376 r = Panel.show_json_include_opt[:include]
\r
377 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
379 it '素材は絵師を含んでいる' do
\r
380 r = Panel.show_json_include_opt[:include]
\r
381 r[:panel_pictures][:resource_picture].has_key?(:artist).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?(:license).should be_true
\r
388 r = Panel.show_include_opt
\r
389 r.has_key?(:speech_balloons).should be_true
\r
391 it 'フキダシはフキダシ枠を含んでいる' do
\r
392 r = Panel.show_include_opt
\r
393 r[:speech_balloons].has_key?(:balloons).should be_true
\r
395 it 'フキダシはセリフを含んでいる' do
\r
396 r = Panel.show_include_opt
\r
397 r[:speech_balloons].has_key?(:speeches).should be_true
\r
400 r = Panel.show_json_include_opt[:include]
\r
401 r.has_key?(:author).should be_true
\r
404 describe '一覧取得に於いて' do
\r
406 @panel = Factory :panel, :author_id => @author.id
\r
408 context 'page補正について' do
\r
409 it '文字列から数値に変換される' do
\r
410 Panel.page('8').should eq 8
\r
412 it 'nilの場合は1になる' do
\r
413 Panel.page().should eq 1
\r
415 it '0以下の場合は1になる' do
\r
416 Panel.page('0').should eq 1
\r
419 context 'page_size補正について' do
\r
420 it '文字列から数値に変換される' do
\r
421 Panel.page_size('7').should eq 7
\r
423 it 'nilの場合はPanel.default_page_sizeになる' do
\r
424 Panel.page_size().should eq Panel.default_page_size
\r
426 it '0以下の場合はPanel.default_page_sizeになる' do
\r
427 Panel.page_size('0').should eq Panel.default_page_size
\r
429 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
430 Panel.page_size('1000').should eq Panel.max_page_size
\r
435 pl.should eq [@panel]
\r
438 npl = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
440 pl.should eq [npl, @panel]
\r
442 it '非公開のコマは含まない' do
\r
443 npl = Factory :panel, :author_id => @author.id, :publish => 0
\r
445 pl.should eq [@panel]
\r
447 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
449 @npl2 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
450 @npl3 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
451 @npl4 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
452 @npl5 = Factory :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
453 Panel.stub(:default_page_size).and_return(2)
\r
457 pl.should have(2).items
\r
459 it 'page=1なら末尾2件を返す' do
\r
461 pl = Panel.list( {}, 1)
\r
462 pl.should eq [@npl5, @npl4]
\r
464 it 'page=2なら中間2件を返す' do
\r
465 pl = Panel.list({}, 2)
\r
466 pl.should eq [@npl3, @npl2]
\r
468 it 'page=3なら先頭1件を返す' do
\r
469 pl = Panel.list({}, 3)
\r
470 pl.should eq [@panel]
\r
474 describe 'list関連テーブルプションに於いて' do
\r
475 it 'includeキーを含んでいる' do
\r
477 r.has_key?(:include).should be_true
\r
479 it '3つの項目を含んでいる' do
\r
480 r = Panel.list_opt[:include]
\r
481 r.should have(3).items
\r
484 r = Panel.list_opt[:include]
\r
485 r.has_key?(:panel_pictures).should be_true
\r
487 it 'コマ絵は素材を含んでいる' do
\r
488 r = Panel.list_opt[:include]
\r
489 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
491 it '素材は絵師を含んでいる' do
\r
492 r = Panel.list_opt[:include]
\r
493 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
495 it '素材はライセンスを含んでいる' do
\r
496 r = Panel.list_opt[:include]
\r
497 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
500 r = Panel.show_include_opt
\r
501 r.has_key?(:speech_balloons).should be_true
\r
503 it 'フキダシはフキダシ枠を含んでいる' do
\r
504 r = Panel.show_include_opt
\r
505 r[:speech_balloons].has_key?(:balloons).should be_true
\r
507 it 'フキダシはセリフを含んでいる' do
\r
508 r = Panel.show_include_opt
\r
509 r[:speech_balloons].has_key?(:speeches).should be_true
\r
512 r = Panel.list_opt[:include]
\r
513 r.has_key?(:author).should be_true
\r
516 describe 'json一覧出力オプションに於いて' do
\r
517 it 'includeキーを含んでいる' do
\r
518 r = Panel.list_json_opt
\r
519 r.has_key?(:include).should be_true
\r
521 it '3つの項目を含んでいる' do
\r
522 r = Panel.list_json_opt[:include]
\r
523 r.should have(3).items
\r
526 r = Panel.list_json_opt[:include]
\r
527 r.has_key?(:panel_pictures).should be_true
\r
529 it 'コマ絵は素材を含んでいる' do
\r
530 r = Panel.list_json_opt[:include]
\r
531 r[:panel_pictures].has_key?(:resource_picture).should be_true
\r
533 it '素材は絵師を含んでいる' do
\r
534 r = Panel.list_json_opt[:include]
\r
535 r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true
\r
537 it '素材はライセンスを含んでいる' do
\r
538 r = Panel.list_json_opt[:include]
\r
539 r[:panel_pictures][:resource_picture].has_key?(:license).should be_true
\r
542 r = Panel.show_include_opt
\r
543 r.has_key?(:speech_balloons).should be_true
\r
545 it 'フキダシはフキダシ枠を含んでいる' do
\r
546 r = Panel.show_include_opt
\r
547 r[:speech_balloons].has_key?(:balloons).should be_true
\r
549 it 'フキダシはセリフを含んでいる' do
\r
550 r = Panel.show_include_opt
\r
551 r[:speech_balloons].has_key?(:speeches).should be_true
\r
554 r = Panel.list_json_opt[:include]
\r
555 r.has_key?(:author).should be_true
\r
560 #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった
\r
561 #コマ絵とフキダシの整合チェックをする
\r
562 describe 'id収集に於いて' do
\r
563 context 'つつがなく終わるとき' do
\r
564 it '第一パラメータで指定された配列中から第二引数のidを収集している' do
\r
565 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
566 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
567 r = Panel.collect_element_value a, :panel_id
\r
568 r.should eq [1, 2, 3, 4]
\r
571 context 'Nil除外指示があるとき' do
\r
572 it '収集したpanel_idのうちnilは除外している' do
\r
573 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}],
\r
574 [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
575 r = Panel.collect_element_value a, :panel_id, true
\r
576 r.should eq [1, 2, 3, 4]
\r
580 describe 'id一致チェックに於いて' do
\r
581 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
582 context '親が既存(idが数値)のとき' do
\r
583 it 'すべてid一致するときTrueを返す' do
\r
584 r = Panel.validate_id [1, 1, 1, 1], 1
\r
587 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
588 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
591 it 'すべて数値でも一致しないときFalseを返す' do
\r
592 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
595 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
596 r = Panel.validate_id [1, 1, nil, 2], 1
\r
600 context '親が新規(idがNil)のとき' do
\r
601 it 'すべてNilはTrueを返す' do
\r
602 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
605 it 'すべてnilでなければFalseを返す' do
\r
606 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
611 describe 'idチェック単体に於いて' do
\r
613 # @pp = Factory :panel_picture, :panel_id => @panel.id, :t => 1
\r
615 context 'つつがなく終わるとき' do
\r
616 it 'idを収集依頼している' do
\r
617 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
618 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
619 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
620 r = Panel.validate_element_id [], :panel_id, nil
\r
622 it '収集したidを一致チェック依頼している' do
\r
623 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
624 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
625 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
626 r = Panel.validate_element_id [], :panel_id, nil
\r
630 #依頼チェックだけでは不安なので最低限のチェックを
\r
631 context 'コマ新規のとき' do
\r
632 it 'コマ絵で正常通過している' do
\r
633 @panel = Factory.build :panel, :author_id => @author.id
\r
634 @panel.panel_pictures.build(
\r
635 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
637 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
640 it 'フキダシで正常通過している' do
\r
641 @panel = Factory.build :panel, :author_id => @author.id
\r
642 @panel.speech_balloons.build(
\r
643 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
645 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
649 context 'コマ既存のとき' do
\r
650 it 'コマ絵で正常通過している' do
\r
651 @panel = Factory :panel, :author_id => @author.id
\r
652 @panel.panel_pictures.build(
\r
653 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
655 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
658 it 'フキダシで正常通過している' do
\r
659 @panel = Factory :panel, :author_id => @author.id
\r
660 @panel.speech_balloons.build(
\r
661 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
663 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
667 context 'フキダシ新規のとき' do
\r
668 it 'バルーンで正常通過している' do
\r
669 @panel = Factory.build :panel, :author_id => @author.id
\r
670 @panel.speech_balloons.build(
\r
671 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
673 @panel.speech_balloons.first.balloons.build(
\r
674 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
676 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
679 it 'セリフで正常通過している' do
\r
680 @panel = Factory.build :panel, :author_id => @author.id
\r
681 @panel.speech_balloons.build(
\r
682 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
684 @panel.speech_balloons.first.speeches.build(
\r
685 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
687 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
692 describe 'idチェックリスト生成に於いて' do
\r
694 @panel = Factory.build :panel, :author_id => @author.id
\r
696 context 'つつがなく終わるとき' do
\r
697 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
698 @panel.panel_pictures.build(
\r
699 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
701 @panel.speech_balloons.build(
\r
702 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
704 @panel.speech_balloons.first.balloons.build(
\r
705 Factory.attributes_for(:balloon, :speech_balloon_id => nil)
\r
707 @panel.speech_balloons.first.speeches.build(
\r
708 Factory.attributes_for(:speech, :speech_balloon_id => nil)
\r
710 r = @panel.validate_id_list
\r
711 r.should have(2).items
\r
713 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
714 @panel.panel_pictures.build(
\r
715 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
717 sb1 = @panel.speech_balloons.build(
\r
718 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
720 sb1.balloons.build(
\r
721 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
723 sb1.speeches.build(
\r
724 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
726 sb2 = @panel.speech_balloons.build(
\r
727 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
729 sb2.balloons.build(
\r
730 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
732 sb2.speeches.build(
\r
733 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
735 r = @panel.validate_id_list
\r
736 r.should have(3).items
\r
740 describe 'idチェック複合に於いて' do
\r
742 @panel = Factory.build :panel, :author_id => @author.id
\r
744 context 'つつがなく終わるとき' do
\r
745 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
746 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
747 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
748 @panel.panel_pictures.build(
\r
749 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)
\r
751 sb1 = @panel.speech_balloons.build(
\r
752 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
754 sb1.balloons.build(
\r
755 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
757 sb1.speeches.build(
\r
758 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
760 r = Panel.validate_elements_id(@panel.validate_id_list)
\r
764 describe 'シリアライズチェックに於いて' do
\r
765 context 'つつがなく終わるとき' do
\r
766 it '0からシリアライズされているならTrueを返す' do
\r
767 r = Panel.validate_t [0, 1, 2]
\r
770 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
771 r = Panel.validate_t [0, 2, 1]
\r
774 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
775 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
780 it '0から始まらないならFalseを返す' do
\r
781 r = Panel.validate_t [1, 2, 3]
\r
784 it '連続していないならFalseを返す' do
\r
785 r = Panel.validate_t [0, 1, 2, 4]
\r
788 it '連続していないならFalseを返す' do
\r
789 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
794 describe 'tチェック単体に於いて' do
\r
797 context 'つつがなく終わるとき' do
\r
798 it 'コマ絵とフキダシのtを収集依頼している' do
\r
799 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
800 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
801 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
802 r = Panel.validate_element_t [], :t
\r
804 it '収集したtをシリアライズチェック依頼している' do
\r
805 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
806 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
807 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
808 r = Panel.validate_element_t [], :t
\r
812 #依頼チェックだけでは不安なので最低限のチェックを
\r
814 it 'コマ絵で正常通過している' do
\r
815 @panel = Factory.build :panel, :author_id => @author.id
\r
816 @panel.panel_pictures.build(
\r
817 Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)
\r
819 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
822 it 'フキダシで正常通過している' do
\r
823 @panel = Factory.build :panel, :author_id => @author.id
\r
824 @panel.speech_balloons.build(
\r
825 Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)
\r
827 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
832 it 'コマ絵で正常通過している' do
\r
833 @panel = Factory :panel, :author_id => @author.id
\r
834 @panel.panel_pictures.build(
\r
835 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
837 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
840 it 'フキダシで正常通過している' do
\r
841 @panel = Factory :panel, :author_id => @author.id
\r
842 @panel.speech_balloons.build(
\r
843 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
845 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
850 describe '複合チェックに於いて' do
\r
851 context 'つつがなく終わるとき' do
\r
853 @panel = Factory.build :panel, :author_id => @author.id
\r
854 @panel.panel_pictures.build(
\r
855 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
857 @panel.panel_pictures.build(
\r
858 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
860 sb1 = @panel.speech_balloons.build(
\r
861 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
863 sb1.balloons.build(
\r
864 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
866 sb1.speeches.build(
\r
867 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
869 sb2 = @panel.speech_balloons.build(
\r
870 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
872 sb2.balloons.build(
\r
873 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
875 sb2.speeches.build(
\r
876 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
878 r = @panel.validate_child
\r
883 describe '複合チェックに於いて' do
\r
884 context 'つつがなく終わるとき' do
\r
886 @panel = Factory.build :panel, :author_id => @author.id
\r
887 @panel.panel_pictures.build(
\r
888 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)
\r
890 @panel.panel_pictures.build(
\r
891 Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)
\r
893 sb1 = @panel.speech_balloons.build(
\r
894 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
896 sb1.balloons.build(
\r
897 Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
899 sb1.speeches.build(
\r
900 Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
902 sb2 = @panel.speech_balloons.build(
\r
903 Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
905 sb2.balloons.build(
\r
906 Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
908 sb2.speeches.build(
\r
909 Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
911 r = @panel.validate_child
\r
916 describe '保存に於いて' do
\r
917 context 'つつがなく終わるとき' do
\r
918 it 'idチェックを依頼している' do
\r
919 Panel.should_receive(:validate_elements_id).with(any_args).exactly(1)
\r
920 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
921 @panel = Factory.build :panel, :author_id => @author.id
\r
925 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
926 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
927 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
928 @panel = Factory.build :panel, :author_id => @author.id
\r
932 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
933 @panel = Factory.build :panel, :author_id => @author.id
\r
937 it 'エラーメッセージがセットされていない' do
\r
938 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
939 @panel = Factory :panel, :author_id => @author.id
\r
941 @panel.errors.empty?.should be_true
\r
945 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
946 @panel = Factory.build :panel, :author_id => @author.id
\r
951 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
952 @panel = Factory.build :panel, :author_id => @author.id
\r
955 }.should change(Panel, :count)
\r
960 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
961 @panel = Factory :panel, :author_id => @author.id
\r
966 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
967 @panel = Factory :panel, :author_id => @author.id
\r
970 }.should_not change(Panel, :count)
\r
974 context 'idチェックが失敗するとき' do
\r
976 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
977 @panel = Factory :panel, :author_id => @author.id
\r
981 it 'エラーメッセージがセットされている' do
\r
982 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
983 @panel = Factory :panel, :author_id => @author.id
\r
985 @panel.errors.empty?.should be_false
\r
988 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
989 @panel = Factory.build :panel, :author_id => @author.id
\r
992 }.should_not change(Panel, :count)
\r