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 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?(:picture).should be_true
\r
330 it '実素材は絵師を含んでいる' do
\r
331 r = Panel.show_include_opt
\r
332 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
334 it '実素材はライセンスを含んでいる' do
\r
335 r = Panel.show_include_opt
\r
336 r[:panel_pictures][: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?(:picture).should be_true
\r
383 it '実素材は絵師を含んでいる' do
\r
384 r = Panel.show_json_include_opt[:include]
\r
385 r[:panel_pictures][: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][: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 = FactoryGirl.create :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 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
444 pl.should eq [npl, @panel]
\r
446 it '非公開のコマは含まない' do
\r
447 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
449 pl.should eq [@panel]
\r
451 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
453 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
454 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
455 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
456 @npl5 = FactoryGirl.create :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?(:picture).should be_true
\r
495 it '実素材は絵師を含んでいる' do
\r
496 r = Panel.list_opt[:include]
\r
497 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
499 it '実素材はライセンスを含んでいる' do
\r
500 r = Panel.list_opt[:include]
\r
501 r[:panel_pictures][: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?(:picture).should be_true
\r
537 it '実素材は絵師を含んでいる' do
\r
538 r = Panel.list_json_opt[:include]
\r
539 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
541 it '実素材はライセンスを含んでいる' do
\r
542 r = Panel.list_json_opt[:include]
\r
543 r[:panel_pictures][: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
563 describe '自分のコマ一覧取得に於いて' do
\r
565 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
568 pl = Panel.mylist @author
\r
569 pl.should eq [@panel]
\r
572 npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
573 pl = Panel.mylist @author
\r
574 pl.should eq [npl, @panel]
\r
576 it '他人のコマは公開でも含まない' do
\r
577 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
578 pl = Panel.mylist @author
\r
579 pl.should eq [@panel]
\r
581 it '自分のコマは非公開でも含んでいる' do
\r
582 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100
\r
583 pl = Panel.mylist @author
\r
584 pl.should eq [npl, @panel]
\r
589 #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった
\r
590 #コマ絵とフキダシの整合チェックをする
\r
591 describe 'id収集に於いて' do
\r
592 context 'つつがなく終わるとき' do
\r
593 it '第一パラメータで指定された配列中から第二引数のidを収集している' do
\r
594 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
595 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
596 r = Panel.collect_element_value a, :panel_id
\r
597 r.should eq [1, 2, 3, 4]
\r
600 context 'Nil除外指示があるとき' do
\r
601 it '収集したpanel_idのうちnilは除外している' do
\r
602 a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}],
\r
603 [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
604 r = Panel.collect_element_value a, :panel_id, true
\r
605 r.should eq [1, 2, 3, 4]
\r
609 describe 'id一致チェックに於いて' do
\r
610 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
611 context '親が既存(idが数値)のとき' do
\r
612 it 'すべてid一致するときTrueを返す' do
\r
613 r = Panel.validate_id [1, 1, 1, 1], 1
\r
616 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
617 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
620 it 'すべて数値でも一致しないときFalseを返す' do
\r
621 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
624 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
625 r = Panel.validate_id [1, 1, nil, 2], 1
\r
629 context '親が新規(idがNil)のとき' do
\r
630 it 'すべてNilはTrueを返す' do
\r
631 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
634 it 'すべてnilでなければFalseを返す' do
\r
635 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
640 describe 'idチェック単体に於いて' do
\r
642 # @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1
\r
644 context 'つつがなく終わるとき' do
\r
645 it 'idを収集依頼している' do
\r
646 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
647 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
648 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
649 r = Panel.validate_element_id [], :panel_id, nil
\r
651 it '収集したidを一致チェック依頼している' do
\r
652 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
653 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
654 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
655 r = Panel.validate_element_id [], :panel_id, nil
\r
659 #依頼チェックだけでは不安なので最低限のチェックを
\r
660 context 'コマ新規のとき' do
\r
661 it 'コマ絵で正常通過している' do
\r
662 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
663 @panel.panel_pictures.build(
\r
664 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
666 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
669 it 'フキダシで正常通過している' do
\r
670 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
671 @panel.speech_balloons.build(
\r
672 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
674 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
678 context 'コマ既存のとき' do
\r
679 it 'コマ絵で正常通過している' do
\r
680 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
681 @panel.panel_pictures.build(
\r
682 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
684 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
687 it 'フキダシで正常通過している' do
\r
688 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
689 @panel.speech_balloons.build(
\r
690 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
692 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
696 context 'フキダシ新規のとき' do
\r
697 it 'バルーンで正常通過している' do
\r
698 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
699 @panel.speech_balloons.build(
\r
700 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
702 @panel.speech_balloons.first.balloons.build(
\r
703 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
705 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
708 it 'セリフで正常通過している' do
\r
709 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
710 @panel.speech_balloons.build(
\r
711 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
713 @panel.speech_balloons.first.speeches.build(
\r
714 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
716 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
721 describe 'idチェックリスト生成に於いて' do
\r
723 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
725 context 'つつがなく終わるとき' do
\r
726 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
727 @panel.panel_pictures.build(
\r
728 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
730 @panel.speech_balloons.build(
\r
731 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
733 @panel.speech_balloons.first.balloons.build(
\r
734 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
736 @panel.speech_balloons.first.speeches.build(
\r
737 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
739 r = @panel.validate_id_list
\r
740 r.should have(2).items
\r
742 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
743 @panel.panel_pictures.build(
\r
744 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
746 sb1 = @panel.speech_balloons.build(
\r
747 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
749 sb1.balloons.build(
\r
750 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
752 sb1.speeches.build(
\r
753 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
755 sb2 = @panel.speech_balloons.build(
\r
756 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
758 sb2.balloons.build(
\r
759 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
761 sb2.speeches.build(
\r
762 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
764 r = @panel.validate_id_list
\r
765 r.should have(3).items
\r
769 describe 'idチェック複合に於いて' do
\r
771 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
773 context 'つつがなく終わるとき' do
\r
774 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
775 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
776 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
777 @panel.panel_pictures.build(
\r
778 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
780 sb1 = @panel.speech_balloons.build(
\r
781 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
783 sb1.balloons.build(
\r
784 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
786 sb1.speeches.build(
\r
787 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
789 r = Panel.validate_elements_id(@panel.validate_id_list)
\r
793 describe 'シリアライズチェックに於いて' do
\r
794 context 'つつがなく終わるとき' do
\r
795 it '0からシリアライズされているならTrueを返す' do
\r
796 r = Panel.validate_t [0, 1, 2]
\r
799 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
800 r = Panel.validate_t [0, 2, 1]
\r
803 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
804 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
809 it '0から始まらないならFalseを返す' do
\r
810 r = Panel.validate_t [1, 2, 3]
\r
813 it '連続していないならFalseを返す' do
\r
814 r = Panel.validate_t [0, 1, 2, 4]
\r
817 it '連続していないならFalseを返す' do
\r
818 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
823 describe 'tチェック単体に於いて' do
\r
826 context 'つつがなく終わるとき' do
\r
827 it 'コマ絵とフキダシのtを収集依頼している' do
\r
828 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
829 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
830 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
831 r = Panel.validate_element_t [], :t
\r
833 it '収集したtをシリアライズチェック依頼している' do
\r
834 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
835 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
836 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
837 r = Panel.validate_element_t [], :t
\r
841 #依頼チェックだけでは不安なので最低限のチェックを
\r
843 it 'コマ絵で正常通過している' do
\r
844 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
845 @panel.panel_pictures.build(
\r
846 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
848 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
851 it 'フキダシで正常通過している' do
\r
852 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
853 @panel.speech_balloons.build(
\r
854 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)
\r
856 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
861 it 'コマ絵で正常通過している' do
\r
862 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
863 @panel.panel_pictures.build(
\r
864 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
866 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
869 it 'フキダシで正常通過している' do
\r
870 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
871 @panel.speech_balloons.build(
\r
872 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
874 r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t
\r
879 describe '複合チェックに於いて' do
\r
880 context 'つつがなく終わるとき' do
\r
882 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
883 @panel.panel_pictures.build(
\r
884 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
886 @panel.panel_pictures.build(
\r
887 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)
\r
889 sb1 = @panel.speech_balloons.build(
\r
890 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
892 sb1.balloons.build(
\r
893 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
895 sb1.speeches.build(
\r
896 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
898 sb2 = @panel.speech_balloons.build(
\r
899 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
901 sb2.balloons.build(
\r
902 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
904 sb2.speeches.build(
\r
905 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
907 r = @panel.validate_child
\r
912 describe '複合チェックに於いて' do
\r
913 context 'つつがなく終わるとき' do
\r
915 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
916 @panel.panel_pictures.build(
\r
917 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
919 @panel.panel_pictures.build(
\r
920 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)
\r
922 sb1 = @panel.speech_balloons.build(
\r
923 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
925 sb1.balloons.build(
\r
926 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
928 sb1.speeches.build(
\r
929 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
931 sb2 = @panel.speech_balloons.build(
\r
932 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
934 sb2.balloons.build(
\r
935 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
937 sb2.speeches.build(
\r
938 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
940 r = @panel.validate_child
\r
945 describe '保存に於いて' do
\r
946 context 'つつがなく終わるとき' do
\r
947 it 'idチェックを依頼している' do
\r
948 Panel.should_receive(:validate_elements_id).with(any_args).exactly(1)
\r
949 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
950 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
954 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
955 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
956 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
957 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
961 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
962 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
966 it 'エラーメッセージがセットされていない' do
\r
967 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
968 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
970 @panel.errors.empty?.should be_true
\r
974 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
975 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
980 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
981 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
984 }.should change(Panel, :count)
\r
989 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
990 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
995 Panel.stub(:validate_elements_id).with(any_args).and_return(true)
\r
996 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
999 }.should_not change(Panel, :count)
\r
1003 context 'idチェックが失敗するとき' do
\r
1005 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
1006 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1010 it 'エラーメッセージがセットされている' do
\r
1011 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
1012 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1014 @panel.errors.empty?.should be_false
\r
1016 it '行が追加されていない' do
\r
1017 Panel.stub(:validate_elements_id).with(any_args).and_return(false)
\r
1018 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1021 }.should_not change(Panel, :count)
\r