1 # -*- encoding: utf-8 -*-
\r
2 require 'spec_helper'
\r
6 FactoryGirl.create :admin
\r
7 @sp = FactoryGirl.create :system_picture
\r
8 @lg = FactoryGirl.create :license_group
\r
9 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
\r
10 @user = FactoryGirl.create( :user_yas)
\r
11 @author = @user.author
\r
12 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
\r
13 @other_user = FactoryGirl.create( :user_yas)
\r
14 @other_author = @other_user.author
\r
15 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
\r
16 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
17 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
18 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
19 @sbt = FactoryGirl.create :speech_balloon_template
\r
22 describe '検証に於いて' do
\r
26 it 'オーソドックスなデータなら通る' do
\r
27 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
28 @panel.should be_valid
\r
31 context 'widthを検証するとき' do
\r
33 @panel = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.create :panel, :author_id => @author.id
\r
197 describe 'デフォルト値補充に於いて' do
\r
199 @panel = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.create :panel, :author_id => @author.id
\r
227 panel.own?(@author).should == true
\r
230 panel = FactoryGirl.create :panel, :author_id => @author.id
\r
231 panel.own?(@other_author).should == false
\r
234 panel = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :panel, :author_id => @author.id
\r
263 panel.visible?(@author).should == false
\r
266 describe '単体取得に於いて' do
\r
268 @panel = FactoryGirl.create :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 = FactoryGirl.create :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 it '6つの項目を含んでいる' do
\r
318 r = Panel.show_include_opt
\r
319 r.should have(6).items
\r
322 r = Panel.show_include_opt
\r
323 r.has_key?(:panel_pictures).should be_true
\r
325 it 'コマ絵は実素材を含んでいる' do
\r
326 r = Panel.show_include_opt
\r
327 r[:panel_pictures].has_key?(:picture).should be_true
\r
329 it '実素材は絵師を含んでいる' do
\r
330 r = Panel.show_include_opt
\r
331 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
333 it '実素材はライセンスを含んでいる' do
\r
334 r = Panel.show_include_opt
\r
335 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
338 r = Panel.show_include_opt
\r
339 r.has_key?(:speech_balloons).should be_true
\r
341 it 'フキダシはフキダシ枠を含んでいる' do
\r
342 r = Panel.show_include_opt
\r
343 r[:speech_balloons].has_key?(:balloons).should be_true
\r
345 it 'フキダシはセリフを含んでいる' do
\r
346 r = Panel.show_include_opt
\r
347 r[:speech_balloons].has_key?(:speeches).should be_true
\r
350 r = Panel.show_include_opt
\r
351 r.has_key?(:ground_pictures).should be_true
\r
353 it '景色画像は実素材を含んでいる' do
\r
354 r = Panel.show_include_opt
\r
355 r[:ground_pictures].has_key?(:picture).should be_true
\r
357 it '実素材は絵師を含んでいる' do
\r
358 r = Panel.show_include_opt
\r
359 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
361 it '実素材はライセンスを含んでいる' do
\r
362 r = Panel.show_include_opt
\r
363 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
366 r = Panel.show_include_opt
\r
367 r.has_key?(:ground_colors).should be_true
\r
369 it '間接色は色を含んでいる' do
\r
370 r = Panel.show_include_opt
\r
371 r[:ground_colors].has_key?(:color).should be_true
\r
374 r = Panel.show_include_opt
\r
375 r.has_key?(:panel_colors).should be_true
\r
378 r = Panel.show_include_opt
\r
379 r.has_key?(:author).should be_true
\r
382 describe 'json単体出力オプションに於いて' do
\r
383 it 'includeキーを含んでいる' do
\r
384 r = Panel.show_json_include_opt
\r
385 r.has_key?(:include).should be_true
\r
387 it '6つの項目を含んでいる' do
\r
388 r = Panel.show_json_include_opt[:include]
\r
389 r.should have(6).items
\r
392 r = Panel.show_json_include_opt[:include]
\r
393 r.has_key?(:panel_pictures).should be_true
\r
395 it 'コマ絵は実素材を含んでいる' do
\r
396 r = Panel.show_json_include_opt[:include]
\r
397 r[:panel_pictures].has_key?(:picture).should be_true
\r
399 it '実素材は絵師を含んでいる' do
\r
400 r = Panel.show_json_include_opt[:include]
\r
401 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
403 it '実素材はライセンスを含んでいる' do
\r
404 r = Panel.show_json_include_opt[:include]
\r
405 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
408 r = Panel.show_json_include_opt[:include]
\r
409 r.has_key?(:speech_balloons).should be_true
\r
411 it 'フキダシはフキダシ枠を含んでいる' do
\r
412 r = Panel.show_json_include_opt[:include]
\r
413 r[:speech_balloons].has_key?(:balloons).should be_true
\r
415 it 'フキダシはセリフを含んでいる' do
\r
416 r = Panel.show_json_include_opt[:include]
\r
417 r[:speech_balloons].has_key?(:speeches).should be_true
\r
420 r = Panel.show_json_include_opt[:include]
\r
421 r.has_key?(:ground_pictures).should be_true
\r
423 it '景色画像は実素材を含んでいる' do
\r
424 r = Panel.show_json_include_opt[:include]
\r
425 r[:ground_pictures].has_key?(:picture).should be_true
\r
427 it '実素材は絵師を含んでいる' do
\r
428 r = Panel.show_json_include_opt[:include]
\r
429 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
431 it '実素材はライセンスを含んでいる' do
\r
432 r = Panel.show_json_include_opt[:include]
\r
433 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
436 r = Panel.show_json_include_opt[:include]
\r
437 r.has_key?(:ground_colors).should be_true
\r
439 it '間接色は色を含んでいる' do
\r
440 r = Panel.show_json_include_opt[:include]
\r
441 r[:ground_colors].has_key?(:color).should be_true
\r
444 r = Panel.show_json_include_opt[:include]
\r
445 r.has_key?(:panel_colors).should be_true
\r
448 r = Panel.show_json_include_opt[:include]
\r
449 r.has_key?(:author).should be_true
\r
452 describe '一覧取得に於いて' do
\r
454 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
456 context 'page補正について' do
\r
457 it '文字列から数値に変換される' do
\r
458 Panel.page('8').should eq 8
\r
460 it 'nilの場合は1になる' do
\r
461 Panel.page().should eq 1
\r
463 it '0以下の場合は1になる' do
\r
464 Panel.page('0').should eq 1
\r
467 context 'page_size補正について' do
\r
468 it '文字列から数値に変換される' do
\r
469 Panel.page_size('7').should eq 7
\r
471 it 'nilの場合はPanel.default_page_sizeになる' do
\r
472 Panel.page_size().should eq Panel.default_page_size
\r
474 it '0以下の場合はPanel.default_page_sizeになる' do
\r
475 Panel.page_size('0').should eq Panel.default_page_size
\r
477 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
478 Panel.page_size('1000').should eq Panel.max_page_size
\r
483 pl.should eq [@panel]
\r
486 npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
488 pl.should eq [npl, @panel]
\r
490 it '非公開のコマは含まない' do
\r
491 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
493 pl.should eq [@panel]
\r
495 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
497 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
498 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
499 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
500 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
501 Panel.stub(:default_page_size).and_return(2)
\r
505 pl.should have(2).items
\r
507 it 'page=1なら末尾2件を返す' do
\r
509 pl = Panel.list( {}, 1)
\r
510 pl.should eq [@npl5, @npl4]
\r
512 it 'page=2なら中間2件を返す' do
\r
513 pl = Panel.list({}, 2)
\r
514 pl.should eq [@npl3, @npl2]
\r
516 it 'page=3なら先頭1件を返す' do
\r
517 pl = Panel.list({}, 3)
\r
518 pl.should eq [@panel]
\r
522 describe 'list関連テーブルプションに於いて' do
\r
523 it 'includeキーを含んでいる' do
\r
525 r.has_key?(:include).should be_true
\r
527 it '6つの項目を含んでいる' do
\r
528 r = Panel.list_opt[:include]
\r
529 r.should have(6).items
\r
532 r = Panel.list_opt[:include]
\r
533 r.has_key?(:panel_pictures).should be_true
\r
535 it 'コマ絵は実素材を含んでいる' do
\r
536 r = Panel.list_opt[:include]
\r
537 r[:panel_pictures].has_key?(:picture).should be_true
\r
539 it '実素材は絵師を含んでいる' do
\r
540 r = Panel.list_opt[:include]
\r
541 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
543 it '実素材はライセンスを含んでいる' do
\r
544 r = Panel.list_opt[:include]
\r
545 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
548 r = Panel.list_opt[:include]
\r
549 r.has_key?(:speech_balloons).should be_true
\r
551 it 'フキダシはフキダシ枠を含んでいる' do
\r
552 r = Panel.list_opt[:include]
\r
553 r[:speech_balloons].has_key?(:balloons).should be_true
\r
555 it 'フキダシはセリフを含んでいる' do
\r
556 r = Panel.list_opt[:include]
\r
557 r[:speech_balloons].has_key?(:speeches).should be_true
\r
560 r = Panel.list_opt[:include]
\r
561 r.has_key?(:ground_pictures).should be_true
\r
563 it '景色画像は実素材を含んでいる' do
\r
564 r = Panel.list_opt[:include]
\r
565 r[:ground_pictures].has_key?(:picture).should be_true
\r
567 it '実素材は絵師を含んでいる' do
\r
568 r = Panel.list_opt[:include]
\r
569 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
571 it '実素材はライセンスを含んでいる' do
\r
572 r = Panel.list_opt[:include]
\r
573 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
576 r = Panel.list_opt[:include]
\r
577 r.has_key?(:ground_colors).should be_true
\r
579 it '間接色は色を含んでいる' do
\r
580 r = Panel.list_opt[:include]
\r
581 r[:ground_colors].has_key?(:color).should be_true
\r
584 r = Panel.list_opt[:include]
\r
585 r.has_key?(:panel_colors).should be_true
\r
588 r = Panel.list_opt[:include]
\r
589 r.has_key?(:author).should be_true
\r
592 describe 'json一覧出力オプションに於いて' do
\r
593 it 'includeキーを含んでいる' do
\r
594 r = Panel.list_json_opt
\r
595 r.has_key?(:include).should be_true
\r
597 it '6つの項目を含んでいる' do
\r
598 r = Panel.list_json_opt[:include]
\r
599 r.should have(6).items
\r
602 r = Panel.list_json_opt[:include]
\r
603 r.has_key?(:panel_pictures).should be_true
\r
605 it 'コマ絵は実素材を含んでいる' do
\r
606 r = Panel.list_json_opt[:include]
\r
607 r[:panel_pictures].has_key?(:picture).should be_true
\r
609 it '実素材は絵師を含んでいる' do
\r
610 r = Panel.list_json_opt[:include]
\r
611 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
613 it '実素材はライセンスを含んでいる' do
\r
614 r = Panel.list_json_opt[:include]
\r
615 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
618 r = Panel.list_json_opt[:include]
\r
619 r.has_key?(:speech_balloons).should be_true
\r
621 it 'フキダシはフキダシ枠を含んでいる' do
\r
622 r = Panel.list_json_opt[:include]
\r
623 r[:speech_balloons].has_key?(:balloons).should be_true
\r
625 it 'フキダシはセリフを含んでいる' do
\r
626 r = Panel.list_json_opt[:include]
\r
627 r[:speech_balloons].has_key?(:speeches).should be_true
\r
630 r = Panel.list_json_opt[:include]
\r
631 r.has_key?(:ground_pictures).should be_true
\r
633 it '景色画像は実素材を含んでいる' do
\r
634 r = Panel.list_json_opt[:include]
\r
635 r[:ground_pictures].has_key?(:picture).should be_true
\r
637 it '実素材は絵師を含んでいる' do
\r
638 r = Panel.list_json_opt[:include]
\r
639 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
641 it '実素材はライセンスを含んでいる' do
\r
642 r = Panel.list_json_opt[:include]
\r
643 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
646 r = Panel.list_json_opt[:include]
\r
647 r.has_key?(:ground_colors).should be_true
\r
649 it '間接色は色を含んでいる' do
\r
650 r = Panel.list_json_opt[:include]
\r
651 r[:ground_colors].has_key?(:color).should be_true
\r
654 r = Panel.list_json_opt[:include]
\r
655 r.has_key?(:panel_colors).should be_true
\r
658 r = Panel.list_json_opt[:include]
\r
659 r.has_key?(:author).should be_true
\r
663 describe '自分のコマ一覧取得に於いて' do
\r
665 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
668 pl = Panel.mylist @author
\r
669 pl.should eq [@panel]
\r
672 npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
673 pl = Panel.mylist @author
\r
674 pl.should eq [npl, @panel]
\r
676 it '他人のコマは公開でも含まない' do
\r
677 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
678 pl = Panel.mylist @author
\r
679 pl.should eq [@panel]
\r
681 it '自分のコマは非公開でも含んでいる' do
\r
682 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100
\r
683 pl = Panel.mylist @author
\r
684 pl.should eq [npl, @panel]
\r
689 #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった
\r
690 #コマ絵とフキダシの整合チェックをする
\r
691 describe 'id収集に於いて' do
\r
692 context 'つつがなく終わるとき' do
\r
693 it '第一パラメータで指定された配列中から第二引数のidを収集している' do
\r
694 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
695 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
696 r = Panel.collect_element_value a, :panel_id
\r
697 r.should eq [1, 2, 3, 4]
\r
700 context 'Nil除外指示があるとき' do
\r
701 it '収集したpanel_idのうちnilは除外している' do
\r
702 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}],
\r
703 [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
704 r = Panel.collect_element_value a, :panel_id, true
\r
705 r.should eq [1, 2, 3, 4]
\r
709 describe 'id一致チェックに於いて' do
\r
710 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
711 context '親が既存(idが数値)のとき' do
\r
712 it 'すべてid一致するときTrueを返す' do
\r
713 r = Panel.validate_id [1, 1, 1, 1], 1
\r
716 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
717 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
720 it 'すべて数値でも一致しないときFalseを返す' do
\r
721 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
724 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
725 r = Panel.validate_id [1, 1, nil, 2], 1
\r
729 context '親が新規(idがNil)のとき' do
\r
730 it 'すべてNilはTrueを返す' do
\r
731 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
734 it 'すべてnilでなければFalseを返す' do
\r
735 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
740 describe 'idチェック単体に於いて' do
\r
742 # @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1
\r
744 context 'つつがなく終わるとき' do
\r
745 it 'idを収集依頼している' do
\r
746 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
747 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
748 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
749 r = Panel.validate_element_id [], :panel_id, nil
\r
751 it '収集したidを一致チェック依頼している' do
\r
752 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
753 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
754 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
755 r = Panel.validate_element_id [], :panel_id, nil
\r
759 #依頼チェックだけでは不安なので最低限のチェックを
\r
760 context 'コマ新規のとき' do
\r
761 it 'コマ絵で正常通過している' do
\r
762 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
763 @panel.panel_pictures.build(
\r
764 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
766 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
769 it 'フキダシで正常通過している' do
\r
770 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
771 @panel.speech_balloons.build(
\r
772 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
774 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
778 context 'コマ既存のとき' do
\r
779 it 'コマ絵で正常通過している' do
\r
780 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
781 @panel.panel_pictures.build(
\r
782 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
784 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
787 it 'フキダシで正常通過している' do
\r
788 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
789 @panel.speech_balloons.build(
\r
790 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
792 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
796 context 'フキダシ新規のとき' do
\r
797 it 'バルーンで正常通過している' do
\r
798 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
799 @panel.speech_balloons.build(
\r
800 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
802 @panel.speech_balloons.first.balloons.build(
\r
803 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
805 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
808 it 'セリフで正常通過している' do
\r
809 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
810 @panel.speech_balloons.build(
\r
811 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
813 @panel.speech_balloons.first.speeches.build(
\r
814 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
816 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
821 describe 'idチェックリスト生成に於いて' do
\r
823 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
825 context 'つつがなく終わるとき' do
\r
826 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
827 @panel.panel_pictures.build(
\r
828 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
830 @panel.speech_balloons.build(
\r
831 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
833 @panel.speech_balloons.first.balloons.build(
\r
834 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
836 @panel.speech_balloons.first.speeches.build(
\r
837 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
839 r = @panel.validate_id_list
\r
840 r.should have(2).items
\r
842 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
843 @panel.panel_pictures.build(
\r
844 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
846 sb1 = @panel.speech_balloons.build(
\r
847 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
849 sb1.balloons.build(
\r
850 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
852 sb1.speeches.build(
\r
853 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
855 sb2 = @panel.speech_balloons.build(
\r
856 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
858 sb2.balloons.build(
\r
859 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
861 sb2.speeches.build(
\r
862 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
864 r = @panel.validate_id_list
\r
865 r.should have(3).items
\r
869 describe 'idチェック複合に於いて' do
\r
871 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
873 context 'つつがなく終わるとき' do
\r
874 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
875 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
876 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
877 @panel.panel_pictures.build(
\r
878 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
880 sb1 = @panel.speech_balloons.build(
\r
881 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
883 sb1.balloons.build(
\r
884 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
886 sb1.speeches.build(
\r
887 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
889 r = Panel.validate_elements_id(@panel.validate_id_list)
\r
893 describe 'シリアライズチェックに於いて' do
\r
894 context 'つつがなく終わるとき' do
\r
895 it '0からシリアライズされているならTrueを返す' do
\r
896 r = Panel.validate_t [0, 1, 2]
\r
899 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
900 r = Panel.validate_t [0, 2, 1]
\r
903 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
904 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
909 it '0から始まらないならFalseを返す' do
\r
910 r = Panel.validate_t [1, 2, 3]
\r
913 it '連続していないならFalseを返す' do
\r
914 r = Panel.validate_t [0, 1, 2, 4]
\r
917 it '連続していないならFalseを返す' do
\r
918 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
923 describe 'tチェック単体に於いて' do
\r
926 context 'つつがなく終わるとき' do
\r
927 it 'コマ絵とフキダシのtを収集依頼している' do
\r
928 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
929 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
930 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
931 r = Panel.validate_element_t [], :t
\r
933 it '収集したtをシリアライズチェック依頼している' do
\r
934 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
935 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
936 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
937 r = Panel.validate_element_t [], :t
\r
941 #依頼チェックだけでは不安なので最低限のチェックを
\r
943 it 'コマ絵で正常通過している' do
\r
944 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
945 @panel.panel_pictures.build(
\r
946 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
948 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
951 it 'フキダシで正常通過している' do
\r
952 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
953 @panel.speech_balloons.build(
\r
954 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)
\r
956 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
961 it 'コマ絵で正常通過している' do
\r
962 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
963 @panel.panel_pictures.build(
\r
964 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
966 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
969 it 'フキダシで正常通過している' do
\r
970 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
971 @panel.speech_balloons.build(
\r
972 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
974 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
979 describe '複合チェックに於いて' do
\r
980 context 'つつがなく終わるとき' do
\r
982 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
983 @panel.panel_pictures.build(
\r
984 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
986 @panel.panel_pictures.build(
\r
987 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)
\r
989 sb1 = @panel.speech_balloons.build(
\r
990 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
992 sb1.balloons.build(
\r
993 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
995 sb1.speeches.build(
\r
996 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
998 sb2 = @panel.speech_balloons.build(
\r
999 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
1001 sb2.balloons.build(
\r
1002 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1004 sb2.speeches.build(
\r
1005 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1007 r = @panel.validate_child
\r
1012 describe '複合チェックに於いて' do
\r
1013 context 'つつがなく終わるとき' do
\r
1015 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1016 @panel.panel_pictures.build(
\r
1017 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
1019 @panel.panel_pictures.build(
\r
1020 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)
\r
1022 sb1 = @panel.speech_balloons.build(
\r
1023 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
1025 sb1.balloons.build(
\r
1026 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1028 sb1.speeches.build(
\r
1029 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1031 sb2 = @panel.speech_balloons.build(
\r
1032 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
1034 sb2.balloons.build(
\r
1035 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1037 sb2.speeches.build(
\r
1038 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1040 r = @panel.validate_child
\r
1045 describe '保存に於いて' do
\r
1046 context 'つつがなく終わるとき' do
\r
1047 it 'idチェックを依頼している' do
\r
1048 Panel.should_receive(:validate_elements_id).with(any_args).exactly(1)
\r
1049 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1050 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1054 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1055 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
1056 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1057 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1061 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1062 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1066 it 'エラーメッセージがセットされていない' do
\r
1067 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1068 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1070 @panel.errors.empty?.should be_true
\r
1072 context '新規のとき' do
\r
1074 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1075 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1080 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1081 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1084 }.should change(Panel, :count)
\r
1087 context '更新のとき' do
\r
1089 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1090 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1094 it '行が追加されていない' do
\r
1095 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
1096 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1099 }.should_not change(Panel, :count)
\r
1103 context 'idチェックが失敗するとき' do
\r
1105 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
1106 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1110 it 'エラーメッセージがセットされている' do
\r
1111 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
1112 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1114 @panel.errors.empty?.should be_false
\r
1116 it '行が追加されていない' do
\r
1117 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
1118 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1121 }.should_not change(Panel, :count)
\r