1 # -*- encoding: utf-8 -*-
\r
2 require 'spec_helper'
\r
6 @admin = 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 @color = FactoryGirl.create :color
\r
11 @user = FactoryGirl.create( :user_yas)
\r
12 @author = FactoryGirl.create :author, :user_id => @user.id
\r
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
\r
14 @other_user = FactoryGirl.create( :user_yas)
\r
15 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
\r
16 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
\r
17 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
18 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
19 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
20 @sbt = FactoryGirl.create :speech_balloon_template
\r
23 describe '検証に於いて' do
\r
25 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
28 context 'オーソドックスなデータのとき' do
\r
37 @panel.should be_valid
\r
40 @panel.width = 99999
\r
41 @panel.height = 99999
\r
42 @panel.border = 99999
\r
46 @panel.publish = 99999
\r
47 @panel.should be_valid
\r
51 context 'widthを検証するとき' do
\r
54 @panel.should_not be_valid
\r
58 @panel.should_not be_valid
\r
62 @panel.should_not be_valid
\r
66 @panel.should_not be_valid
\r
69 context 'heightを検証するとき' do
\r
72 @panel.should_not be_valid
\r
76 @panel.should_not be_valid
\r
80 @panel.should_not be_valid
\r
84 @panel.should_not be_valid
\r
87 context 'borderを検証するとき' do
\r
90 @panel.should_not be_valid
\r
94 @panel.should_not be_valid
\r
97 @panel.border = '-1'
\r
98 @panel.should_not be_valid
\r
102 @panel.should be_valid
\r
105 context 'xを検証するとき' do
\r
106 it '数値でなければ失敗する' do
\r
108 @panel.should_not be_valid
\r
112 @panel.should be_valid
\r
116 @panel.should be_valid
\r
119 context 'yを検証するとき' do
\r
120 it '数値でなければ失敗する' do
\r
122 @panel.should_not be_valid
\r
126 @panel.should be_valid
\r
130 @panel.should be_valid
\r
133 context 'zを検証するとき' do
\r
134 it '数値でなければ失敗する' do
\r
136 @panel.should_not be_valid
\r
140 @panel.should_not be_valid
\r
144 @panel.should_not be_valid
\r
147 context 'author_idを検証するとき' do
\r
149 @panel.author_id = nil
\r
150 @panel.should_not be_valid
\r
152 it '数値でなければ失敗する' do
\r
153 @panel.author_id = 'a'
\r
154 @panel.should_not be_valid
\r
156 it '存在する作家でなければ失敗する' do
\r
157 @panel.author_id = 0
\r
158 @panel.should_not be_valid
\r
161 context '公開フラグを検証するとき' do
\r
162 it '数値でなければ失敗する' do
\r
163 @panel.publish = 'a'
\r
164 @panel.should_not be_valid
\r
167 context '全体を検証するとき' do
\r
169 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
174 describe 'デフォルト値補充に於いて' do
\r
176 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
178 it 'borderは2を補充する' do
\r
179 @panel.border = nil
\r
180 @panel.supply_default
\r
181 @panel.border.should eq 2
\r
183 it 'publishは0を補充する' do
\r
184 @panel.publish = nil
\r
185 @panel.supply_default
\r
186 @panel.publish.should eq 0
\r
190 describe '上書き補充に於いて' do
\r
192 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
194 context 'author_idを補充' do
\r
195 it 'ログイン中の作家idを補充する' do
\r
196 @panel.author_id = nil
\r
197 @panel.overwrite @author
\r
198 @panel.author_id.should eq @author.id
\r
204 describe '所持判定に於いて' do
\r
206 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
208 context '事前チェックする' do
\r
209 it '自身にロールリストからの作家取得を依頼している' do
\r
210 Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
\r
211 r = @panel.own?([@author])
\r
214 context 'ロール内作家が取得できるとき' do
\r
217 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
\r
218 Panel.stub(:get_author_from_roles).with(any_args).and_return(@author)
\r
219 r = @panel.own?([@author])
\r
222 it 'ロール内作家のidが自身の作家idと一致しないならno' do
\r
223 Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
\r
224 @panel.own?(@other_author).should be_false
\r
227 context 'ロール内作家が取得できないとき' do
\r
229 Panel.stub(:get_author_from_roles).with(any_args).and_return(nil)
\r
232 r = @panel.own?([@author])
\r
238 describe '閲覧許可に於いて' do
\r
240 @comic = FactoryGirl.create :comic, :author_id => @author.id
\r
241 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
242 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
\r
244 context 'オープンモードのとき' do
\r
246 MagicNumber['run_mode'] = 0
\r
248 it '自身にゲスト用ロールチェックを問い合わせしている' do
\r
249 Panel.any_instance.stub(:guest_role_check).and_return(true)
\r
250 Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
\r
251 r = @panel.visible?([@author])
\r
253 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
\r
254 Panel.any_instance.stub(:guest_role_check).and_return(false)
\r
255 r = @panel.visible?([@author])
\r
259 context 'クローズドモードのとき' do
\r
261 MagicNumber['run_mode'] = 1
\r
263 it '自身に読者用ロールチェックを問い合わせしている' do
\r
264 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
265 Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
\r
266 r = @panel.visible?([@author])
\r
268 it '読者用ロールチェックが失敗したとき、falseを返す' do
\r
269 Panel.any_instance.stub(:reader_role_check).and_return(false)
\r
270 r = @panel.visible?([@author])
\r
274 context '事前チェックする' do
\r
276 MagicNumber['run_mode'] = 1
\r
277 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
279 it '自身に所持判定を問い合わせしている' do
\r
280 Panel.any_instance.stub(:own?).and_return(true)
\r
281 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
282 r = @panel.visible?([@author])
\r
284 it '自身に閲覧許可を問い合わせしている' do
\r
285 Panel.any_instance.stub(:own?).and_return(false)
\r
286 Panel.any_instance.stub(:publish?).and_return(true)
\r
287 Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1)
\r
288 r = @panel.visible?([@author])
\r
291 context 'つつがなく終わるとき' do
\r
293 MagicNumber['run_mode'] = 1
\r
294 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
296 it '自分のコマなら許可する' do
\r
297 Panel.any_instance.stub(:own?).and_return(true)
\r
298 Panel.any_instance.stub(:publish?).and_return(false)
\r
299 r = @panel.visible?([@author])
\r
302 it '他人の非公開コマなら許可しない' do
\r
303 Panel.any_instance.stub(:own?).and_return(false)
\r
304 Panel.any_instance.stub(:publish?).and_return(false)
\r
305 r = @panel.visible?([@author])
\r
308 it '他人のコマでも公開なら許可する' do
\r
309 Panel.any_instance.stub(:own?).and_return(false)
\r
310 Panel.any_instance.stub(:publish?).and_return(true)
\r
311 r = @panel.visible?([@author])
\r
317 describe '一覧取得に於いて' do
\r
319 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
321 context 'page補正について' do
\r
322 it '文字列から数値に変換される' do
\r
323 Panel.page('8').should eq 8
\r
325 it 'nilの場合は1になる' do
\r
326 Panel.page().should eq 1
\r
328 it '0以下の場合は1になる' do
\r
329 Panel.page('0').should eq 1
\r
332 context 'page_size補正について' do
\r
333 it '文字列から数値に変換される' do
\r
334 Panel.page_size('7').should eq 7
\r
336 it 'nilの場合はPanel.default_page_sizeになる' do
\r
337 Panel.page_size().should eq Panel.default_page_size
\r
339 it '0以下の場合はPanel.default_page_sizeになる' do
\r
340 Panel.page_size('0').should eq Panel.default_page_size
\r
342 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
343 Panel.page_size('1000').should eq Panel.max_page_size
\r
348 r.should eq [@panel]
\r
351 #公開コミックは(他人のコミックであっても)含んでいる
\r
352 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
354 r.should eq [npl, @panel]
\r
356 it '非公開のコマ(自分のコマであっても)は含まない' do
\r
357 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
359 r.should eq [@panel]
\r
361 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
363 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
364 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
365 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
366 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
367 Panel.stub(:default_page_size).and_return(2)
\r
371 pl.should have(2).items
\r
373 it 'page=1なら末尾2件を返す' do
\r
376 pl.should eq [@npl5, @npl4]
\r
378 it 'page=2なら中間2件を返す' do
\r
380 pl.should eq [@npl3, @npl2]
\r
382 it 'page=3なら先頭1件を返す' do
\r
384 pl.should eq [@panel]
\r
387 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
389 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
390 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
391 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
392 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
393 Panel.stub(:default_page_size).and_return(2)
\r
395 it '件数0は全件(5件)を返す' do
\r
396 r = Panel.list 5, 0
\r
397 r.should have(5).items
\r
401 describe '一覧取得オプションに於いて' do
\r
402 it 'includeキーを含んでいる' do
\r
404 r.has_key?(:include).should be_true
\r
406 it '6つの項目を含んでいる' do
\r
407 r = Panel.list_opt[:include]
\r
408 r.should have(6).items
\r
411 r = Panel.list_opt[:include]
\r
412 r.has_key?(:panel_pictures).should be_true
\r
414 it 'コマ絵は実素材を含んでいる' do
\r
415 r = Panel.list_opt[:include]
\r
416 r[:panel_pictures].has_key?(:picture).should be_true
\r
418 it '実素材は絵師を含んでいる' do
\r
419 r = Panel.list_opt[:include]
\r
420 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
422 it '実素材はライセンスを含んでいる' do
\r
423 r = Panel.list_opt[:include]
\r
424 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
427 r = Panel.list_opt[:include]
\r
428 r.has_key?(:speech_balloons).should be_true
\r
430 it 'フキダシはフキダシ枠を含んでいる' do
\r
431 r = Panel.list_opt[:include]
\r
432 r[:speech_balloons].has_key?(:balloons).should be_true
\r
434 it 'フキダシはセリフを含んでいる' do
\r
435 r = Panel.list_opt[:include]
\r
436 r[:speech_balloons].has_key?(:speeches).should be_true
\r
439 r = Panel.list_opt[:include]
\r
440 r.has_key?(:ground_pictures).should be_true
\r
442 it '景色画像は実素材を含んでいる' do
\r
443 r = Panel.list_opt[:include]
\r
444 r[:ground_pictures].has_key?(:picture).should be_true
\r
446 it '実素材は絵師を含んでいる' do
\r
447 r = Panel.list_opt[:include]
\r
448 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
450 it '実素材はライセンスを含んでいる' do
\r
451 r = Panel.list_opt[:include]
\r
452 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
455 r = Panel.list_opt[:include]
\r
456 r.has_key?(:ground_colors).should be_true
\r
458 it '間接色は色を含んでいる' do
\r
459 r = Panel.list_opt[:include]
\r
460 r[:ground_colors].has_key?(:color).should be_true
\r
463 r = Panel.list_opt[:include]
\r
464 r.has_key?(:panel_colors).should be_true
\r
467 r = Panel.list_opt[:include]
\r
468 r.has_key?(:author).should be_true
\r
471 describe 'json一覧出力オプションに於いて' do
\r
474 describe '自分のコマ一覧取得に於いて' do
\r
476 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
479 pl = Panel.mylist @author
\r
480 pl.should eq [@panel]
\r
483 npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
484 pl = Panel.mylist @author
\r
485 pl.should eq [npl, @panel]
\r
487 it '他人のコマは公開でも含まない' do
\r
488 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
489 pl = Panel.mylist @author
\r
490 pl.should eq [@panel]
\r
492 it '自分のコマは非公開でも含んでいる' do
\r
493 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100
\r
494 pl = Panel.mylist @author
\r
495 pl.should eq [npl, @panel]
\r
497 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
499 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
500 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
501 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
502 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
505 pl = Panel.list 1, 2
\r
506 pl.should have(2).items
\r
508 it 'page=1なら末尾2件を返す' do
\r
510 pl = Panel.mylist @author, 1, 2
\r
511 pl.should eq [@npl5, @npl4]
\r
513 it 'page=2なら中間2件を返す' do
\r
514 pl = Panel.mylist @author, 2, 2
\r
515 pl.should eq [@npl3, @npl2]
\r
517 it 'page=3なら先頭1件を返す' do
\r
518 pl = Panel.mylist @author, 3, 2
\r
519 pl.should eq [@panel]
\r
522 context 'DBに5件あって1ページの件数を0件に変えたとして' do
\r
524 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
525 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
526 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
527 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
528 Author.stub(:default_panel_page_size).and_return(2)
\r
530 it '通常は全件(5件)を返す' do
\r
531 r = Panel.mylist @author, 5, 0
\r
532 r.should have(5).items
\r
537 describe '単体取得に於いて' do
\r
539 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
541 context 'つつがなく終わるとき' do
\r
542 it '単体取得オプションを利用している' do
\r
543 Panel.stub(:show_opt).with(any_args).and_return({})
\r
544 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
545 r = Panel.show @panel.id, @author
\r
547 it '閲覧許可を問い合わせている' do
\r
548 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
549 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
550 r = Panel.show @panel.id, @author
\r
554 Panel.any_instance.stub(:visible?).and_return(true)
\r
555 pl = Panel.show @panel.id, @author
\r
556 pl.should eq @panel
\r
558 context '閲覧許可が出なかったとき' do
\r
559 it '403Forbidden例外を返す' do
\r
560 Panel.any_instance.stub(:visible?).and_return(false)
\r
562 Panel.show @panel.id, @author
\r
563 }.should raise_error(ActiveRecord::Forbidden)
\r
566 context '存在しないコマを開こうとしたとき' do
\r
567 it '404RecordNotFound例外を返す' do
\r
569 Panel.show 110, @author
\r
570 }.should raise_error(ActiveRecord::RecordNotFound)
\r
574 describe '編集取得に於いて' do
\r
576 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
578 context 'つつがなく終わるとき' do
\r
579 it '単体取得オプションを利用している' do
\r
580 Panel.stub(:show_opt).with(any_args).and_return({})
\r
581 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
582 r = Panel.edit @panel.id, @author
\r
584 it '所持判定を問い合わせている' do
\r
585 Panel.any_instance.stub(:own?).with(any_args).and_return(true)
\r
586 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
587 r = Panel.edit @panel.id, @author
\r
591 Panel.any_instance.stub(:own?).and_return(true)
\r
592 pl = Panel.edit @panel.id, @author
\r
593 pl.should eq @panel
\r
595 context '他人のコマを開こうとしたとき' do
\r
596 it '403Forbidden例外を返す' do
\r
597 Panel.any_instance.stub(:own?).and_return(false)
\r
599 Panel.edit @panel.id, @author
\r
600 }.should raise_error(ActiveRecord::Forbidden)
\r
603 context '存在しないコマを開こうとしたとき' do
\r
604 it '404RecordNotFound例外を返す' do
\r
606 Panel.edit 110, @author
\r
607 }.should raise_error(ActiveRecord::RecordNotFound)
\r
611 describe '単体取得オプションに於いて' do
\r
612 it 'includeキーを含んでいる' do
\r
614 r.has_key?(:include).should be_true
\r
616 it '6つの項目を含んでいる' do
\r
617 r = Panel.show_opt[:include]
\r
618 r.should have(6).items
\r
621 r = Panel.show_opt[:include]
\r
622 r.has_key?(:panel_pictures).should be_true
\r
624 it 'コマ絵は実素材を含んでいる' do
\r
625 r = Panel.show_opt[:include]
\r
626 r[:panel_pictures].has_key?(:picture).should be_true
\r
628 it '実素材は絵師を含んでいる' do
\r
629 r = Panel.show_opt[:include]
\r
630 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
632 it '実素材はライセンスを含んでいる' do
\r
633 r = Panel.show_opt[:include]
\r
634 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
637 r = Panel.show_opt[:include]
\r
638 r.has_key?(:speech_balloons).should be_true
\r
640 it 'フキダシはフキダシ枠を含んでいる' do
\r
641 r = Panel.show_opt[:include]
\r
642 r[:speech_balloons].has_key?(:balloons).should be_true
\r
644 it 'フキダシはセリフを含んでいる' do
\r
645 r = Panel.show_opt[:include]
\r
646 r[:speech_balloons].has_key?(:speeches).should be_true
\r
649 r = Panel.show_opt[:include]
\r
650 r.has_key?(:ground_pictures).should be_true
\r
652 it '景色画像は実素材を含んでいる' do
\r
653 r = Panel.show_opt[:include]
\r
654 r[:ground_pictures].has_key?(:picture).should be_true
\r
656 it '実素材は絵師を含んでいる' do
\r
657 r = Panel.show_opt[:include]
\r
658 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
660 it '実素材はライセンスを含んでいる' do
\r
661 r = Panel.show_opt[:include]
\r
662 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
665 r = Panel.show_opt[:include]
\r
666 r.has_key?(:ground_colors).should be_true
\r
668 it '間接色は色を含んでいる' do
\r
669 r = Panel.show_opt[:include]
\r
670 r[:ground_colors].has_key?(:color).should be_true
\r
673 r = Panel.show_opt[:include]
\r
674 r.has_key?(:panel_colors).should be_true
\r
677 r = Panel.show_opt[:include]
\r
678 r.has_key?(:author).should be_true
\r
681 describe 'json単体出力オプションに於いて' do
\r
683 describe 'コマ部品集合に於いて' do
\r
686 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
687 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
688 @sb = @panel.speech_balloons.create(
\r
689 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
691 @gc = @panel.ground_colors.create(
\r
692 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
694 @gp = @panel.ground_pictures.create(
\r
695 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
697 @pc = @panel.panel_colors.create(
\r
698 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
703 r = @panel.parts_element
\r
704 r.is_a?(Array).should be_true
\r
706 it 'コマ絵とフキダシを合わせている' do
\r
707 r = @panel.parts_element
\r
708 r.include?(@pp).should be_true
\r
709 r.include?(@sb).should be_true
\r
711 it '景色素材と景色カラーと景色カラーコードを含んでいない' do
\r
712 r = @panel.parts_element
\r
713 r.include?(@gc).should_not be_true
\r
714 r.include?(@gp).should_not be_true
\r
715 r.include?(@pc).should_not be_true
\r
718 describe 'コマ部品に於いて' do
\r
721 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
722 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
723 @sb = @panel.speech_balloons.create(
\r
724 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
726 @gc = @panel.ground_colors.create(
\r
727 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
729 @gp = @panel.ground_pictures.create(
\r
730 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
732 @pc = @panel.panel_colors.create(
\r
733 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
737 context 'つつがなく終わるとき' do
\r
738 it 'コマ部品集合を利用している' do
\r
739 Panel.any_instance.stub(:parts_element).with(any_args).and_return([])
\r
740 Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)
\r
746 r.is_a?(Array).should be_true
\r
754 context 'さらに末尾にフキダシを追加したとき' do
\r
756 @sb2 = @panel.speech_balloons.create(
\r
757 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
765 r[2].should eq @sb2
\r
769 describe 'コマ地に於いて' do
\r
772 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
773 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
774 @sb = @panel.speech_balloons.create(
\r
775 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
777 @gc = @panel.ground_colors.create(
\r
778 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
780 @gp = @panel.ground_pictures.create(
\r
781 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
783 @pc = @panel.panel_colors.create(
\r
784 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
790 r.is_a?(Array).should be_true
\r
792 it '景色素材と景色カラーと景色カラーコードを合わせている' do
\r
794 r.include?(@gc).should be_true
\r
795 r.include?(@gp).should be_true
\r
796 r.include?(@pc).should be_true
\r
798 it 'コマ絵とフキダシを含んでいない' do
\r
800 r.include?(@pp).should_not be_true
\r
801 r.include?(@sb).should_not be_true
\r
804 describe 'コマ要素に於いて' do
\r
807 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
808 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
809 @sb = @panel.speech_balloons.create(
\r
810 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
812 @gc = @panel.ground_colors.create(
\r
813 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
815 @gp = @panel.ground_pictures.create(
\r
816 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
818 @pc = @panel.panel_colors.create(
\r
819 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
823 context 'つつがなく終わるとき' do
\r
824 it 'コマ部品を利用している' do
\r
825 Panel.any_instance.stub(:parts).with(any_args).and_return([])
\r
826 Panel.any_instance.should_receive(:parts).with(any_args).exactly(1)
\r
827 r = @panel.panel_elements
\r
830 Panel.any_instance.stub(:grounds).with(any_args).and_return([])
\r
831 Panel.any_instance.should_receive(:grounds).with(any_args).exactly(1)
\r
832 r = @panel.panel_elements
\r
836 r = @panel.panel_elements
\r
837 r.is_a?(Array).should be_true
\r
839 it 'コマ絵とフキダシを合わせている' do
\r
840 r = @panel.panel_elements
\r
841 r.include?(@pp).should be_true
\r
842 r.include?(@sb).should be_true
\r
844 it '景色素材と景色カラーと景色カラーコードを合わせている' do
\r
845 r = @panel.panel_elements
\r
846 r.include?(@gc).should be_true
\r
847 r.include?(@gp).should be_true
\r
848 r.include?(@pc).should be_true
\r
850 it 'tでソートしている[t順にソートできる部品の方が優先順位は高い。]' do
\r
851 r = @panel.panel_elements
\r
856 describe 'コマ要素のjson出力に於いて' do
\r
859 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
860 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
861 @sb = @panel.speech_balloons.create(
\r
862 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
864 @gc = @panel.ground_colors.create(
\r
865 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
867 @gp = @panel.ground_pictures.create(
\r
868 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
870 @pc = @panel.panel_colors.create(
\r
871 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
875 context 'つつがなく終わるとき' do
\r
877 Panel.stub(:elm_json_opt).with(@pp).and_return({})
\r
878 Panel.stub(:elm_json_opt).with(@sb).and_return({})
\r
879 Panel.stub(:elm_json_opt).with(@gp).and_return({})
\r
880 Panel.stub(:elm_json_opt).with(@gc).and_return({})
\r
881 Panel.stub(:elm_json_opt).with(@pc).and_return({})
\r
883 it 'コマ要素のjson出力オプションにコマ絵json出力オプションを依頼している' do
\r
884 Panel.should_receive(:elm_json_opt).with(@pp).exactly(1)
\r
885 r = @panel.elements
\r
887 it 'コマ要素のjson出力オプションにフキダシjson出力オプションを依頼している' do
\r
888 Panel.should_receive(:elm_json_opt).with(@sb).exactly(1)
\r
889 r = @panel.elements
\r
891 it 'コマ要素のjson出力オプションに景色素材json出力オプションを依頼している' do
\r
892 Panel.should_receive(:elm_json_opt).with(@gp).exactly(1)
\r
893 r = @panel.elements
\r
895 it 'コマ要素のjson出力オプションに景色カラーjson出力オプションを依頼している' do
\r
896 Panel.should_receive(:elm_json_opt).with(@gc).exactly(1)
\r
897 r = @panel.elements
\r
899 it 'コマ要素のjson出力オプションに景色カラーコードjson出力オプションを依頼している' do
\r
900 Panel.should_receive(:elm_json_opt).with(@pc).exactly(1)
\r
901 r = @panel.elements
\r
905 r = @panel.elements
\r
906 r.is_a?(Array).should be_true
\r
909 describe 'コマのjson出力に於いて' do
\r
912 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
913 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
914 @sb = @panel.speech_balloons.create(
\r
915 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
917 @gc = @panel.ground_colors.create(
\r
918 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
920 @gp = @panel.ground_pictures.create(
\r
921 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
923 @pc = @panel.panel_colors.create(
\r
924 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
928 context 'つつがなく終わるとき' do
\r
930 Panel.any_instance.stub(:elements).with(any_args).and_return({})
\r
932 it 'コマ要素のjson出力を依頼している' do
\r
933 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
934 r = @panel.panel_elements_as_json
\r
937 it 'json textを返している' do
\r
938 r = JSON.parse @panel.panel_elements_as_json
\r
939 r.is_a?(Hash).should be_true
\r
941 it 'author,コマ要素を含んでいる' do
\r
942 r = JSON.parse @panel.panel_elements_as_json
\r
943 r.has_key?('author').should be_true
\r
944 r.has_key?('elements').should be_true
\r
946 sb = r['elements'].first
\r
947 sb.has_key?('classname').should be_true
\r
948 sb.has_key?('balloons').should be_true
\r
949 sb.has_key?('speeches').should be_true
\r
953 describe 'コマリストのjson出力に於いて' do
\r
955 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
956 Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}')
\r
958 context 'つつがなく終わるとき' do
\r
959 it 'コマのjson出力を依頼している' do
\r
960 Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1)
\r
961 r = Panel.list_as_json_text [@panel]
\r
964 it 'json textを返している' do
\r
965 r = Panel.list_as_json_text [@panel]
\r
967 j.is_a?(Array).should be_true
\r
970 r = Panel.list_as_json_text [@panel]
\r
972 j.first.has_key?('p').should be_true
\r
976 describe 'ライセンス素材に於いて' do
\r
979 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
980 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
\r
981 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
\r
982 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
983 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id
\r
984 @sb = @panel.speech_balloons.create(
\r
985 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
987 @gc = @panel.ground_colors.create(
\r
988 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
990 @gp = @panel.ground_pictures.create(
\r
991 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id)
\r
993 @pc = @panel.panel_colors.create(
\r
994 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
998 context '事前チェック' do
\r
1000 context 'つつがなく終わるとき' do
\r
1002 it '連想配列(値は実素材、キーは実素材id)を返している' do
\r
1003 r = @panel.licensed_pictures
\r
1004 r.is_a?(Hash).should be_true
\r
1005 r.should have(2).items
\r
1006 r[@pp.picture_id].should eq @p
\r
1007 r[@gp.picture_id].should eq @p2
\r
1011 describe '検証値収集に於いて' do
\r
1012 context 'つつがなく終わるとき' do
\r
1013 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1014 elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
1015 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
1016 r = Panel.collect_element_value elements, :panel_id
\r
1017 r.should eq [1, 2, 3, 4]
\r
1019 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1020 elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}],
\r
1021 [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]]
\r
1022 r = Panel.collect_element_value elements, :t
\r
1023 r.should eq [1, 2, 3, 0]
\r
1027 describe 'シリアライズチェックに於いて' do
\r
1028 context 'つつがなく終わるとき' do
\r
1029 it '0からシリアライズされているならTrueを返す' do
\r
1030 r = Panel.validate_t [0, 1, 2]
\r
1033 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1034 r = Panel.validate_t [0, 2, 1]
\r
1037 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1038 r = Panel.validate_t [ 2, 1, 4, 3, 0]
\r
1042 context '異常なとき' do
\r
1043 it '0から始まらないならFalseを返す' do
\r
1044 r = Panel.validate_t [1, 2, 3]
\r
1047 it '連続していないならFalseを返す' do
\r
1048 r = Panel.validate_t [0, 1, 2, 4]
\r
1051 it '連続していないならFalseを返す' do
\r
1052 r = Panel.validate_t [0, 1, 2, 4, 5]
\r
1057 describe 'tチェック単体に於いて' do
\r
1060 context 'つつがなく終わるとき' do
\r
1061 it '検証値収集を依頼している' do
\r
1062 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1063 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1064 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
1065 r = Panel.validate_element_t [], :t
\r
1067 it 'シリアライズチェック依頼している' do
\r
1068 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1069 Panel.should_receive(:validate_t).with(any_args).exactly(1)
\r
1070 Panel.stub(:validate_t).with(any_args).and_return(true)
\r
1071 r = Panel.validate_element_t [], :t
\r
1075 describe '従属データの検証に於いて' do
\r
1076 context 'つつがなく終わるとき' do
\r
1077 it 'trueを返している' do
\r
1078 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1079 @panel.panel_pictures.build(
\r
1080 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
1082 @panel.panel_pictures.build(
\r
1083 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)
\r
1085 sb1 = @panel.speech_balloons.build(
\r
1086 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
1088 sb1.balloons.build(
\r
1089 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1091 sb1.speeches.build(
\r
1092 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1094 sb2 = @panel.speech_balloons.build(
\r
1095 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)
\r
1097 sb2.balloons.build(
\r
1098 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1100 sb2.speeches.build(
\r
1101 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1103 r = @panel.validate_child
\r
1107 context 'シリアライズされていないとき' do
\r
1108 it 'falseを返している' do
\r
1109 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1110 @panel.panel_pictures.build(
\r
1111 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)
\r
1113 @panel.panel_pictures.build(
\r
1114 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)
\r
1116 sb1 = @panel.speech_balloons.build(
\r
1117 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)
\r
1119 sb1.balloons.build(
\r
1120 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1122 sb1.speeches.build(
\r
1123 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1125 sb2 = @panel.speech_balloons.build(
\r
1126 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)
\r
1128 sb2.balloons.build(
\r
1129 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1131 sb2.speeches.build(
\r
1132 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1134 r = @panel.validate_child
\r
1139 describe '保存に於いて' do
\r
1141 @attr = FactoryGirl.attributes_for :panel
\r
1142 @panel = Panel.new
\r
1143 @panel.supply_default
\r
1145 context 'つつがなく終わるとき' do
\r
1147 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1148 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1150 it 'コマモデルに上書き補充を依頼している' do
\r
1151 Panel.any_instance.should_receive(:overwrite).exactly(1)
\r
1152 r = @panel.store @attr, @author
\r
1154 it '従属データの検証を依頼している' do
\r
1155 Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1)
\r
1156 r = @panel.store @attr, @author
\r
1159 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
1160 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1161 r = @panel.store @attr, @author
\r
1164 context 'つつがなく終わるとき' do
\r
1166 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1169 r = @panel.store @attr, @author
\r
1173 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1175 r = @panel.store @attr, @author
\r
1176 }.should change(Panel, :count)
\r
1179 context '不正なjsonデータのとき' do
\r
1182 it 'エラーメッセージがセットされている' do
\r
1183 r = @panel.store false, @author
\r
1184 @panel.errors[:base].should_not be_blank
\r
1187 context '従属データの検証に失敗したとき' do
\r
1189 Panel.any_instance.stub(:validate_child).with(any_args).and_return(false)
\r
1191 it 'エラーメッセージがセットされている' do
\r
1192 r = @panel.store @attr, @author
\r
1193 @panel.errors[:base].should_not be_blank
\r
1196 context 'カラム値がFalseしたとき' do
\r
1198 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1200 it 'エラーメッセージがセットされている' do
\r
1201 r = @panel.store false, @author
\r
1202 @panel.errors.should_not be_empty
\r
1207 describe '削除に於いて' do
\r
1209 @comic = FactoryGirl.create :comic, :author_id => @author.id
\r
1210 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
\r
1211 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1212 @sb = @panel.speech_balloons.create(
\r
1213 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1215 @gc = @panel.ground_colors.create(
\r
1216 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
1218 @gp = @panel.ground_pictures.create(
\r
1219 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1221 @pc = @panel.panel_colors.create(
\r
1222 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
1225 context 'つつがなく終わるとき' do
\r
1228 r = @panel.destroy_with_elements
\r
1229 }.should change(Panel, :count).by(-1)
\r
1231 r = Panel.find @panel.id
\r
1232 }.should raise_error
\r
1234 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1236 r = @panel.destroy_with_elements
\r
1237 }.should change(PanelPicture, :count).by(-1)
\r
1239 r = PanelPicture.find @pp.id
\r
1240 }.should raise_error
\r
1242 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1244 r = @panel.destroy_with_elements
\r
1245 }.should change(GroundPicture, :count).by(-1)
\r
1247 r = GroundPicture.find @gp.id
\r
1248 }.should raise_error
\r
1251 r = @panel.destroy_with_elements
\r
1255 context '削除に失敗したとき' do
\r
1257 PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
\r
1260 r = @panel.destroy_with_elements
\r
1263 it 'ロールバックしている' do
\r
1265 r = @panel.destroy_with_elements
\r
1266 }.should_not change(Panel, :count)
\r
1268 r = @panel.destroy_with_elements
\r
1269 }.should_not change(PanelPicture, :count)
\r
1274 describe 'id挿げ替え防止確認に於いて' do
\r
1277 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1278 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1279 @sb = @panel.speech_balloons.create(
\r
1280 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1282 @gc = @panel.ground_colors.create(
\r
1283 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
1285 @gp = @panel.ground_pictures.create(
\r
1286 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1288 @pc = @panel.panel_colors.create(
\r
1289 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
1293 it 'author,コマ要素を含んでいる' do
\r
1294 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
\r
1295 @panel2.panel_pictures.create(
\r
1296 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height)
\r
1301 describe 'id一致チェックに於いて' do
\r
1302 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
1303 context '親が既存(idが数値)のとき' do
\r
1304 it 'すべてid一致するときTrueを返す' do
\r
1305 r = Panel.validate_id [1, 1, 1, 1], 1
\r
1308 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
1309 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
1312 it 'すべて数値でも一致しないときFalseを返す' do
\r
1313 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
1316 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
1317 r = Panel.validate_id [1, 1, nil, 2], 1
\r
1321 context '親が新規(idがNil)のとき' do
\r
1322 it 'すべてNilはTrueを返す' do
\r
1323 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
1326 it 'すべてnilでなければFalseを返す' do
\r
1327 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
1332 describe 'idチェック単体に於いて' do
\r
1334 # @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1
\r
1336 context 'つつがなく終わるとき' do
\r
1337 it 'idを収集依頼している' do
\r
1338 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1339 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1340 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1341 r = Panel.validate_element_id [], :panel_id, nil
\r
1343 it '収集したidを一致チェック依頼している' do
\r
1344 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
1345 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1346 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1347 r = Panel.validate_element_id [], :panel_id, nil
\r
1351 #依頼チェックだけでは不安なので最低限のチェックを
\r
1352 context 'コマ新規のとき' do
\r
1353 it 'コマ絵で正常通過している' do
\r
1354 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1355 @panel.panel_pictures.build(
\r
1356 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1358 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1361 it 'フキダシで正常通過している' do
\r
1362 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1363 @panel.speech_balloons.build(
\r
1364 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1366 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1370 context 'コマ既存のとき' do
\r
1371 it 'コマ絵で正常通過している' do
\r
1372 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1373 @panel.panel_pictures.build(
\r
1374 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1376 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1379 it 'フキダシで正常通過している' do
\r
1380 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1381 @panel.speech_balloons.build(
\r
1382 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1384 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1388 context 'フキダシ新規のとき' do
\r
1389 it 'バルーンで正常通過している' do
\r
1390 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1391 @panel.speech_balloons.build(
\r
1392 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1394 @panel.speech_balloons.first.balloons.build(
\r
1395 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1397 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1400 it 'セリフで正常通過している' do
\r
1401 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1402 @panel.speech_balloons.build(
\r
1403 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1405 @panel.speech_balloons.first.speeches.build(
\r
1406 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1408 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1413 describe 'idチェックリスト生成に於いて' do
\r
1415 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1417 context 'つつがなく終わるとき' do
\r
1418 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
1419 @panel.panel_pictures.build(
\r
1420 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1422 @panel.speech_balloons.build(
\r
1423 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1425 @panel.speech_balloons.first.balloons.build(
\r
1426 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1428 @panel.speech_balloons.first.speeches.build(
\r
1429 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1431 r = @panel.validate_id_list
\r
1432 r.should have(2).items
\r
1434 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
1435 @panel.panel_pictures.build(
\r
1436 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1438 sb1 = @panel.speech_balloons.build(
\r
1439 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1441 sb1.balloons.build(
\r
1442 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1444 sb1.speeches.build(
\r
1445 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1447 sb2 = @panel.speech_balloons.build(
\r
1448 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1450 sb2.balloons.build(
\r
1451 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1453 sb2.speeches.build(
\r
1454 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1456 r = @panel.validate_id_list
\r
1457 r.should have(3).items
\r
1461 describe 'idチェック複合に於いて' do
\r
1463 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1465 context 'つつがなく終わるとき' do
\r
1466 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
1467 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
1468 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
1469 @panel.panel_pictures.build(
\r
1470 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1472 sb1 = @panel.speech_balloons.build(
\r
1473 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1475 sb1.balloons.build(
\r
1476 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1478 sb1.speeches.build(
\r
1479 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1481 r = Panel.validate_elements_id(@panel.validate_id_list)
\r