1 # -*- encoding: utf-8 -*-
\r
2 require 'spec_helper'
\r
6 SpeechBalloonTemplate.delete_all
\r
7 @admin = FactoryGirl.create :admin
\r
8 @sp = FactoryGirl.create :system_picture
\r
9 @lg = FactoryGirl.create :license_group
\r
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
\r
11 @writing_format = FactoryGirl.create :writing_format
\r
12 @user = FactoryGirl.create( :user_yas)
\r
13 @author = FactoryGirl.create :author, :user_id => @user.id
\r
14 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
\r
15 @other_user = FactoryGirl.create( :user_yas)
\r
16 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
\r
17 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
\r
18 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
19 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
20 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
21 @sbt = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
\r
24 describe '検証に於いて' do
\r
26 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
29 context 'オーソドックスなデータのとき' do
\r
38 @panel.should be_valid
\r
41 @panel.width = 99999
\r
42 @panel.height = 99999
\r
43 @panel.border = 99999
\r
47 @panel.publish = 99999
\r
48 @panel.should be_valid
\r
52 context 'widthを検証するとき' do
\r
55 @panel.should_not be_valid
\r
59 @panel.should_not be_valid
\r
63 @panel.should_not be_valid
\r
67 @panel.should_not be_valid
\r
70 context 'heightを検証するとき' do
\r
73 @panel.should_not be_valid
\r
77 @panel.should_not be_valid
\r
81 @panel.should_not be_valid
\r
85 @panel.should_not be_valid
\r
88 context 'borderを検証するとき' do
\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
107 it '数値でなければ失敗する' do
\r
109 @panel.should_not be_valid
\r
113 @panel.should be_valid
\r
117 @panel.should be_valid
\r
120 context 'yを検証するとき' do
\r
121 it '数値でなければ失敗する' do
\r
123 @panel.should_not be_valid
\r
127 @panel.should be_valid
\r
131 @panel.should be_valid
\r
134 context 'zを検証するとき' do
\r
135 it '数値でなければ失敗する' do
\r
137 @panel.should_not be_valid
\r
141 @panel.should_not be_valid
\r
145 @panel.should_not be_valid
\r
148 context 'author_idを検証するとき' do
\r
150 @panel.author_id = nil
\r
151 @panel.should_not be_valid
\r
153 it '数値でなければ失敗する' do
\r
154 @panel.author_id = 'a'
\r
155 @panel.should_not be_valid
\r
157 it '存在する作家でなければ失敗する' do
\r
158 @panel.author_id = 0
\r
159 @panel.should_not be_valid
\r
162 context '公開フラグを検証するとき' do
\r
163 it '数値でなければ失敗する' do
\r
164 @panel.publish = 'a'
\r
165 @panel.should_not be_valid
\r
168 context '全体を検証するとき' do
\r
170 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
175 describe '文字コード検証に於いて' do
\r
177 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
180 context 'captionを検証するとき' do
\r
181 it 'Shift JISなら失敗する' do
\r
182 @panel.caption = "\x83G\x83r\x83]\x83D"
\r
184 @panel.valid_encode
\r
185 }.should raise_error(Pettanr::BadRequest)
\r
191 describe 'デフォルト値補充に於いて' do
\r
193 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
195 it 'borderは2を補充する' do
\r
196 @panel.border = nil
\r
197 @panel.supply_default
\r
198 @panel.border.should eq 2
\r
200 it 'publishは0を補充する' do
\r
201 @panel.publish = nil
\r
202 @panel.supply_default
\r
203 @panel.publish.should eq 0
\r
207 describe '上書き補充に於いて' do
\r
209 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
211 context 'author_idを補充' do
\r
212 it 'ログイン中の作家idを補充する' do
\r
213 @panel.author_id = nil
\r
214 @panel.overwrite @author
\r
215 @panel.author_id.should eq @author.id
\r
221 describe '所持判定に於いて' do
\r
223 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
225 context '事前チェックする' do
\r
226 it '自身にロールリストからの作家取得を依頼している' do
\r
227 Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
\r
228 r = @panel.own?([@author])
\r
231 context 'ロール内作家が取得できるとき' do
\r
234 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
\r
235 Panel.stub(:get_author_from_roles).with(any_args).and_return(@author)
\r
236 r = @panel.own?([@author])
\r
239 it 'ロール内作家のidが自身の作家idと一致しないならno' do
\r
240 Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
\r
241 @panel.own?(@other_author).should be_false
\r
244 context 'ロール内作家が取得できないとき' do
\r
246 Panel.stub(:get_author_from_roles).with(any_args).and_return(nil)
\r
249 r = @panel.own?([@author])
\r
255 describe '閲覧許可に於いて' do
\r
257 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
\r
258 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
259 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
\r
261 context 'オープンモードのとき' do
\r
263 MagicNumber['run_mode'] = 0
\r
265 it '自身にゲスト用ロールチェックを問い合わせしている' do
\r
266 Panel.any_instance.stub(:guest_role_check).and_return(true)
\r
267 Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
\r
268 r = @panel.visible?([@author])
\r
270 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
\r
271 Panel.any_instance.stub(:guest_role_check).and_return(false)
\r
272 r = @panel.visible?([@author])
\r
276 context 'クローズドモードのとき' do
\r
278 MagicNumber['run_mode'] = 1
\r
280 it '自身に読者用ロールチェックを問い合わせしている' do
\r
281 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
282 Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
\r
283 r = @panel.visible?([@author])
\r
285 it '読者用ロールチェックが失敗したとき、falseを返す' do
\r
286 Panel.any_instance.stub(:reader_role_check).and_return(false)
\r
287 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.should_receive(:own?).with(any_args).exactly(1)
\r
299 r = @panel.visible?([@author])
\r
301 it '自身に閲覧許可を問い合わせしている' do
\r
302 Panel.any_instance.stub(:own?).and_return(false)
\r
303 Panel.any_instance.stub(:publish?).and_return(true)
\r
304 Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1)
\r
305 r = @panel.visible?([@author])
\r
308 context 'つつがなく終わるとき' do
\r
310 MagicNumber['run_mode'] = 1
\r
311 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
313 it '自分のコマなら許可する' do
\r
314 Panel.any_instance.stub(:own?).and_return(true)
\r
315 Panel.any_instance.stub(:publish?).and_return(false)
\r
316 r = @panel.visible?([@author])
\r
319 it '他人の非公開コマなら許可しない' do
\r
320 Panel.any_instance.stub(:own?).and_return(false)
\r
321 Panel.any_instance.stub(:publish?).and_return(false)
\r
322 r = @panel.visible?([@author])
\r
325 it '他人のコマでも公開なら許可する' do
\r
326 Panel.any_instance.stub(:own?).and_return(false)
\r
327 Panel.any_instance.stub(:publish?).and_return(true)
\r
328 r = @panel.visible?([@author])
\r
334 describe '一覧取得に於いて' do
\r
336 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
338 context 'page補正について' do
\r
339 it '文字列から数値に変換される' do
\r
340 Panel.page('8').should eq 8
\r
342 it 'nilの場合は1になる' do
\r
343 Panel.page().should eq 1
\r
345 it '0以下の場合は1になる' do
\r
346 Panel.page('0').should eq 1
\r
349 context 'page_size補正について' do
\r
350 it '文字列から数値に変換される' do
\r
351 Panel.page_size('7').should eq 7
\r
353 it 'nilの場合はPanel.default_page_sizeになる' do
\r
354 Panel.page_size().should eq Panel.default_page_size
\r
356 it '0以下の場合はPanel.default_page_sizeになる' do
\r
357 Panel.page_size('0').should eq Panel.default_page_size
\r
359 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
360 Panel.page_size('1000').should eq Panel.max_page_size
\r
365 r.should eq [@panel]
\r
368 #公開コミックは(他人のコミックであっても)含んでいる
\r
369 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
371 r.should eq [npl, @panel]
\r
373 it '非公開のコマ(自分のコマであっても)は含まない' do
\r
374 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
376 r.should eq [@panel]
\r
378 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
380 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
381 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
382 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
383 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
384 Panel.stub(:default_page_size).and_return(2)
\r
388 pl.should have(2).items
\r
390 it 'page=1なら末尾2件を返す' do
\r
393 pl.should eq [@npl5, @npl4]
\r
395 it 'page=2なら中間2件を返す' do
\r
397 pl.should eq [@npl3, @npl2]
\r
399 it 'page=3なら先頭1件を返す' do
\r
401 pl.should eq [@panel]
\r
406 describe '自分のコマ一覧取得に於いて' do
\r
408 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
411 pl = Panel.mylist @author
\r
412 pl.should eq [@panel]
\r
415 npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
416 pl = Panel.mylist @author
\r
417 pl.should eq [npl, @panel]
\r
419 it '他人のコマは公開でも含まない' do
\r
420 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
421 pl = Panel.mylist @author
\r
422 pl.should eq [@panel]
\r
424 it '自分のコマは非公開でも含んでいる' do
\r
425 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100
\r
426 pl = Panel.mylist @author
\r
427 pl.should eq [npl, @panel]
\r
429 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
431 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
432 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
433 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
434 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
437 pl = Panel.mylist @author, 1, 2
\r
438 pl.should have(2).items
\r
440 it 'page=1なら末尾2件を返す' do
\r
442 pl = Panel.mylist @author, 1, 2
\r
443 pl.should eq [@npl5, @npl4]
\r
445 it 'page=2なら中間2件を返す' do
\r
446 pl = Panel.mylist @author, 2, 2
\r
447 pl.should eq [@npl3, @npl2]
\r
449 it 'page=3なら先頭1件を返す' do
\r
450 pl = Panel.mylist @author, 3, 2
\r
451 pl.should eq [@panel]
\r
456 describe '他作家のコマ一覧取得に於いて' do
\r
458 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
459 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
462 r = Panel.himlist @other_author
\r
463 r.should eq [@other_panel]
\r
466 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
467 r = Panel.himlist @other_author
\r
468 r.should eq [npl, @other_panel]
\r
471 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
\r
472 r = Panel.himlist @other_author
\r
473 r.should eq [@other_panel]
\r
475 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
477 @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
478 @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200
\r
479 @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300
\r
480 @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400
\r
483 pl = Panel.himlist @other_author, 1, 2
\r
484 pl.should have(2).items
\r
486 it 'page=1なら末尾2件を返す' do
\r
488 pl = Panel.himlist @other_author, 1, 2
\r
489 pl.should eq [@other_panel5, @other_panel4]
\r
491 it 'page=2なら中間2件を返す' do
\r
492 pl = Panel.himlist @other_author, 2, 2
\r
493 pl.should eq [@other_panel3, @other_panel2]
\r
495 it 'page=3なら先頭1件を返す' do
\r
496 pl = Panel.himlist @other_author, 3, 2
\r
497 pl.should eq [@other_panel]
\r
502 describe 'コマ一覧ページ制御に於いて' do
\r
504 Panel.stub(:count).with(any_args).and_return(100)
\r
507 r = Panel.list_paginate
\r
508 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
510 it 'コマ一覧の取得条件を利用している' do
\r
511 Panel.stub(:list_where).with(any_args).and_return('')
\r
512 Panel.should_receive(:list_where).with(any_args).exactly(1)
\r
513 r = Panel.list_paginate
\r
515 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
516 r = Panel.list_paginate 3, 10
\r
517 r.limit_value.should eq 10
\r
518 r.offset_value.should eq 20
\r
522 describe '自分のコマ一覧ページ制御に於いて' do
\r
524 Panel.stub(:count).with(any_args).and_return(100)
\r
527 r = Panel.mylist_paginate @author
\r
528 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
530 it '自分のコマ一覧の取得条件を利用している' do
\r
531 Panel.stub(:mylist_where).with(any_args).and_return('')
\r
532 Panel.should_receive(:mylist_where).with(any_args).exactly(1)
\r
533 r = Panel.mylist_paginate @author
\r
535 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
536 r = Panel.mylist_paginate @author, 3, 10
\r
537 r.limit_value.should eq 10
\r
538 r.offset_value.should eq 20
\r
542 describe '他作家のコマ一覧ページ制御に於いて' do
\r
544 Panel.stub(:count).with(any_args).and_return(100)
\r
547 r = Panel.himlist_paginate @other_author
\r
548 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
550 it '他作家のコマ一覧の取得条件を利用している' do
\r
551 Panel.stub(:himlist_where).with(any_args).and_return('')
\r
552 Panel.should_receive(:himlist_where).with(any_args).exactly(1)
\r
553 r = Panel.himlist_paginate @other_author
\r
555 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
556 r = Panel.himlist_paginate @other_author, 3, 10
\r
557 r.limit_value.should eq 10
\r
558 r.offset_value.should eq 20
\r
562 describe '一覧取得オプションに於いて' do
\r
563 it '5つの項目を含んでいる' do
\r
565 r.should have(5).items
\r
569 r.has_key?(:panel_pictures).should be_true
\r
571 it 'コマ絵は実素材を含んでいる' do
\r
573 r[:panel_pictures].has_key?(:picture).should be_true
\r
575 it '実素材は絵師を含んでいる' do
\r
577 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
579 it '実素材はライセンスを含んでいる' do
\r
581 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
585 r.has_key?(:speech_balloons).should be_true
\r
587 it 'フキダシはフキダシ枠を含んでいる' do
\r
589 r[:speech_balloons].has_key?(:balloon).should be_true
\r
591 it 'フキダシはセリフを含んでいる' do
\r
593 r[:speech_balloons].has_key?(:speech).should be_true
\r
597 r.has_key?(:ground_pictures).should be_true
\r
599 it '絵地は実素材を含んでいる' do
\r
601 r[:ground_pictures].has_key?(:picture).should be_true
\r
603 it '実素材は絵師を含んでいる' do
\r
605 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
607 it '実素材はライセンスを含んでいる' do
\r
609 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
613 r.has_key?(:ground_colors).should be_true
\r
617 r.has_key?(:author).should be_true
\r
620 describe 'json一覧出力オプションに於いて' do
\r
623 describe '単体取得に於いて' do
\r
625 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
627 context 'つつがなく終わるとき' do
\r
628 it '単体取得オプションを利用している' do
\r
629 Panel.stub(:show_opt).with(any_args).and_return({})
\r
630 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
631 r = Panel.show @panel.id, @author
\r
633 it '閲覧許可を問い合わせている' do
\r
634 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
635 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
636 r = Panel.show @panel.id, @author
\r
640 Panel.any_instance.stub(:visible?).and_return(true)
\r
641 pl = Panel.show @panel.id, @author
\r
642 pl.should eq @panel
\r
644 context '閲覧許可が出なかったとき' do
\r
645 it '403Forbidden例外を返す' do
\r
646 Panel.any_instance.stub(:visible?).and_return(false)
\r
648 Panel.show @panel.id, @author
\r
649 }.should raise_error(ActiveRecord::Forbidden)
\r
652 context '存在しないコマを開こうとしたとき' do
\r
653 it '404RecordNotFound例外を返す' do
\r
655 Panel.show 110, @author
\r
656 }.should raise_error(ActiveRecord::RecordNotFound)
\r
660 describe '編集取得に於いて' do
\r
662 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
664 context 'つつがなく終わるとき' do
\r
665 it '単体取得オプションを利用している' do
\r
666 Panel.stub(:show_opt).with(any_args).and_return({})
\r
667 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
668 r = Panel.edit @panel.id, @author
\r
670 it '所持判定を問い合わせている' do
\r
671 Panel.any_instance.stub(:own?).with(any_args).and_return(true)
\r
672 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
673 r = Panel.edit @panel.id, @author
\r
677 Panel.any_instance.stub(:own?).and_return(true)
\r
678 pl = Panel.edit @panel.id, @author
\r
679 pl.should eq @panel
\r
681 context '他人のコマを開こうとしたとき' do
\r
682 it '403Forbidden例外を返す' do
\r
683 Panel.any_instance.stub(:own?).and_return(false)
\r
685 Panel.edit @panel.id, @author
\r
686 }.should raise_error(ActiveRecord::Forbidden)
\r
689 context '存在しないコマを開こうとしたとき' do
\r
690 it '404RecordNotFound例外を返す' do
\r
692 Panel.edit 110, @author
\r
693 }.should raise_error(ActiveRecord::RecordNotFound)
\r
697 describe '単体取得オプションに於いて' do
\r
698 it 'includeキーを含んでいる' do
\r
700 r.has_key?(:include).should be_true
\r
702 it '5つの項目を含んでいる' do
\r
703 r = Panel.show_opt[:include]
\r
704 r.should have(5).items
\r
707 r = Panel.show_opt[:include]
\r
708 r.has_key?(:panel_pictures).should be_true
\r
710 it 'コマ絵は実素材を含んでいる' do
\r
711 r = Panel.show_opt[:include]
\r
712 r[:panel_pictures].has_key?(:picture).should be_true
\r
714 it '実素材は絵師を含んでいる' do
\r
715 r = Panel.show_opt[:include]
\r
716 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
718 it '実素材はライセンスを含んでいる' do
\r
719 r = Panel.show_opt[:include]
\r
720 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
723 r = Panel.show_opt[:include]
\r
724 r.has_key?(:speech_balloons).should be_true
\r
726 it 'フキダシはフキダシ枠を含んでいる' do
\r
727 r = Panel.show_opt[:include]
\r
728 r[:speech_balloons].has_key?(:balloon).should be_true
\r
730 it 'フキダシはセリフを含んでいる' do
\r
731 r = Panel.show_opt[:include]
\r
732 r[:speech_balloons].has_key?(:speech).should be_true
\r
735 r = Panel.show_opt[:include]
\r
736 r.has_key?(:ground_pictures).should be_true
\r
738 it '絵地は実素材を含んでいる' do
\r
739 r = Panel.show_opt[:include]
\r
740 r[:ground_pictures].has_key?(:picture).should be_true
\r
742 it '実素材は絵師を含んでいる' do
\r
743 r = Panel.show_opt[:include]
\r
744 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
746 it '実素材はライセンスを含んでいる' do
\r
747 r = Panel.show_opt[:include]
\r
748 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
751 r = Panel.show_opt[:include]
\r
752 r.has_key?(:ground_colors).should be_true
\r
755 r = Panel.show_opt[:include]
\r
756 r.has_key?(:author).should be_true
\r
759 describe 'json単体出力オプションに於いて' do
\r
761 describe 'コマ部品集合に於いて' do
\r
764 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
765 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
766 @sb = @panel.speech_balloons.build(
\r
767 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
770 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
773 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
777 @gc = @panel.ground_colors.create(
\r
778 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
780 @gp = @panel.ground_pictures.create(
\r
781 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
786 r = @panel.parts_element
\r
787 r.is_a?(Array).should be_true
\r
789 it 'コマ絵とフキダシと絵地と色地を合わせている' do
\r
790 r = @panel.parts_element
\r
791 r.include?(@pp).should be_true
\r
792 r.include?(@sb).should be_true
\r
793 r.include?(@gc).should be_true
\r
794 r.include?(@gp).should be_true
\r
798 describe 'z順コマ部品に於いて' do
\r
801 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
802 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :width => @p.width, :height => @p.height
\r
803 @sb = @panel.speech_balloons.build(
\r
804 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1)
\r
807 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
810 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
814 @gc = @panel.ground_colors.create(
\r
815 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3)
\r
817 @gp = @panel.ground_pictures.create(
\r
818 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4)
\r
822 context 'つつがなく終わるとき' do
\r
823 it 'コマ部品集合を利用している' do
\r
824 Panel.any_instance.stub(:parts_element).with(any_args).and_return([])
\r
825 Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)
\r
826 r = @panel.zorderd_elements
\r
830 r = @panel.zorderd_elements
\r
831 r.is_a?(Array).should be_true
\r
834 it 'zでオフセットを0でソートしている' do
\r
835 r = @panel.zorderd_elements
\r
841 context 'さらに末尾にフキダシを追加したとき' do
\r
843 @sb2 = @panel.speech_balloons.build(
\r
844 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5)
\r
846 @sb2.build_balloon(
\r
847 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
850 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
857 r = @panel.zorderd_elements
\r
862 r[4].should eq @sb2
\r
866 describe 'コマ要素に於いて' do
\r
869 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
870 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
871 @sb = @panel.speech_balloons.build(
\r
872 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
875 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
878 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
882 @gc = @panel.ground_colors.create(
\r
883 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
885 @gp = @panel.ground_pictures.create(
\r
886 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
890 context 'つつがなく終わるとき' do
\r
891 it 'コマ部品を利用している' do
\r
892 Panel.any_instance.stub(:parts_element).with(any_args).and_return([])
\r
893 Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)
\r
894 r = @panel.panel_elements
\r
898 r = @panel.panel_elements
\r
899 r.is_a?(Array).should be_true
\r
902 r = @panel.panel_elements
\r
908 context 'さらに末尾にフキダシを追加したとき' do
\r
910 @sb2 = @panel.speech_balloons.build(
\r
911 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)
\r
913 @sb2.build_balloon(
\r
914 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
917 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
924 r = @panel.panel_elements
\r
929 r[4].should eq @sb2
\r
933 describe 'コマ要素のjson出力に於いて' do
\r
936 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
937 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
938 @sb = @panel.speech_balloons.build(
\r
939 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
942 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
945 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
949 @gc = @panel.ground_colors.create(
\r
950 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
952 @gp = @panel.ground_pictures.create(
\r
953 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
957 context 'つつがなく終わるとき' do
\r
959 PanelPicture.stub(:json_opt_for_panel).and_return({})
\r
960 SpeechBalloon.stub(:json_opt_for_panel).and_return({})
\r
961 GroundPicture.stub(:json_opt_for_panel).and_return({})
\r
962 GroundColor.stub(:json_opt_for_panel).and_return({})
\r
964 it 'コマ絵にjson出力オプションを依頼している' do
\r
965 PanelPicture.should_receive(:json_opt_for_panel).exactly(1)
\r
966 r = @panel.elements
\r
968 it 'フキダシにjson出力オプションを依頼している' do
\r
969 SpeechBalloon.should_receive(:json_opt_for_panel).exactly(1)
\r
970 r = @panel.elements
\r
972 it '絵地にjson出力オプションを依頼している' do
\r
973 GroundPicture.should_receive(:json_opt_for_panel).exactly(1)
\r
974 r = @panel.elements
\r
976 it '色地にjson出力オプションを依頼している' do
\r
977 GroundColor.should_receive(:json_opt_for_panel).exactly(1)
\r
978 r = @panel.elements
\r
982 r = @panel.elements
\r
983 r.is_a?(Array).should be_true
\r
986 describe 'コマのjson出力に於いて' do
\r
989 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
990 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
991 @sb = @panel.speech_balloons.build(
\r
992 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
995 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
998 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1002 @gc = @panel.ground_colors.create(
\r
1003 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
1005 @gp = @panel.ground_pictures.create(
\r
1006 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
1010 context 'つつがなく終わるとき' do
\r
1012 Panel.any_instance.stub(:elements).with(any_args).and_return({})
\r
1014 it 'コマ要素のjson出力を依頼している' do
\r
1015 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
1016 r = @panel.panel_elements_as_json
\r
1019 it 'json textを返している' do
\r
1020 r = JSON.parse @panel.panel_elements_as_json
\r
1021 r.is_a?(Hash).should be_true
\r
1023 it 'author,コマ要素を含んでいる' do
\r
1024 r = JSON.parse @panel.panel_elements_as_json
\r
1025 r.has_key?('author').should be_true
\r
1026 r.has_key?('elements').should be_true
\r
1028 sb = r['elements'].first
\r
1029 sb.has_key?('classname').should be_true
\r
1030 sb.has_key?('balloon').should be_true
\r
1031 sb.has_key?('speech').should be_true
\r
1035 describe 'コマリストのjson出力に於いて' do
\r
1037 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1038 Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}')
\r
1040 context 'つつがなく終わるとき' do
\r
1041 it 'コマのjson出力を依頼している' do
\r
1042 Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1)
\r
1043 r = Panel.list_as_json_text [@panel]
\r
1046 it 'json textを返している' do
\r
1047 r = Panel.list_as_json_text [@panel]
\r
1049 j.is_a?(Array).should be_true
\r
1052 r = Panel.list_as_json_text [@panel]
\r
1054 j.first.has_key?('p').should be_true
\r
1058 describe 'ライセンス素材に於いて' do
\r
1061 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
1062 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
\r
1063 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
\r
1064 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1065 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id
\r
1066 @sb = @panel.speech_balloons.build(
\r
1067 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1069 @sb.build_balloon(
\r
1070 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1073 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1077 @gc = @panel.ground_colors.create(
\r
1078 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
1080 @gp = @panel.ground_pictures.create(
\r
1081 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3)
\r
1085 context '事前チェック' do
\r
1087 context 'つつがなく終わるとき' do
\r
1089 it '連想配列(値は実素材、キーは実素材id)を返している' do
\r
1090 r = @panel.licensed_pictures
\r
1091 r.is_a?(Hash).should be_true
\r
1092 r.should have(2).items
\r
1093 r[@pp.picture_id].should eq @p
\r
1094 r[@gp.picture_id].should eq @p2
\r
1098 describe '検証値収集に於いて' do
\r
1099 context 'つつがなく終わるとき' do
\r
1100 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1101 elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
1102 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
1103 r = Panel.collect_element_value elements, :panel_id
\r
1104 r.should eq [1, 2, 3, 4]
\r
1106 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1107 elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}],
\r
1108 [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]]
\r
1109 r = Panel.collect_element_value elements, :t
\r
1110 r.should eq [1, 2, 3, 0]
\r
1114 describe 'シリアライズチェックに於いて' do
\r
1115 context 'つつがなく終わるとき' do
\r
1116 it '0からシリアライズされているならTrueを返す' do
\r
1117 r = Panel.validate_serial [0, 1, 2]
\r
1120 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1121 r = Panel.validate_serial [0, 2, 1]
\r
1124 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1125 r = Panel.validate_serial [ 2, 1, 4, 3, 0]
\r
1129 context 'オフセットが1のとき' do
\r
1130 it '0からシリアライズされているならFalseを返す' do
\r
1131 r = Panel.validate_serial [0, 1, 2], 1
\r
1134 it '1からシリアライズされているならTrueを返す' do
\r
1135 r = Panel.validate_serial [1, 2, 3], 1
\r
1139 context '異常なとき' do
\r
1140 it '0から始まらないならFalseを返す' do
\r
1141 r = Panel.validate_serial [1, 2, 3]
\r
1144 it '連続していないならFalseを返す' do
\r
1145 r = Panel.validate_serial [0, 1, 2, 4]
\r
1148 it '連続していないならFalseを返す' do
\r
1149 r = Panel.validate_serial [0, 1, 2, 4, 5]
\r
1154 describe 'シリアライズチェック単体に於いて' do
\r
1157 context 'つつがなく終わるとき' do
\r
1158 it '検証値収集を依頼している' do
\r
1159 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1160 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1161 Panel.stub(:validate_serial).with(any_args).and_return(true)
\r
1162 r = Panel.validate_element_serial [], :t
\r
1164 it 'シリアライズチェック依頼している' do
\r
1165 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1166 Panel.should_receive(:validate_serial).with(any_args).exactly(1)
\r
1167 Panel.stub(:validate_serial).with(any_args).and_return(true)
\r
1168 r = Panel.validate_element_serial [], :t
\r
1172 describe '従属データの検証に於いて' do
\r
1173 context 'つつがなく終わるとき' do
\r
1174 it 'trueを返している' do
\r
1175 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1176 @panel.panel_pictures.build(
\r
1177 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1179 @panel.panel_pictures.build(
\r
1180 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)
\r
1182 sb1 = @panel.speech_balloons.build(
\r
1183 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1185 sb1.build_balloon(
\r
1186 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1189 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1193 sb2 = @panel.speech_balloons.build(
\r
1194 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)
\r
1196 sb2.build_balloon(
\r
1197 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1200 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1204 @gc = @panel.ground_colors.build(
\r
1205 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1207 @gp = @panel.ground_pictures.build(
\r
1208 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1210 r = @panel.validate_child
\r
1214 context 'tシリアライズされていないとき' do
\r
1215 it 'falseを返している' do
\r
1216 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1217 @panel.panel_pictures.build(
\r
1218 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1220 @panel.panel_pictures.build(
\r
1221 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)
\r
1223 sb1 = @panel.speech_balloons.build(
\r
1224 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1226 sb1.build_balloon(
\r
1227 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1230 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1234 sb2 = @panel.speech_balloons.build(
\r
1235 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)
\r
1237 sb2.build_balloon(
\r
1238 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1241 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1245 @gc = @panel.ground_colors.build(
\r
1246 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1248 @gp = @panel.ground_pictures.build(
\r
1249 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1251 r = @panel.validate_child
\r
1255 context 'zシリアライズされていないとき' do
\r
1256 it 'falseを返している' do
\r
1257 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1258 @panel.panel_pictures.build(
\r
1259 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1261 @panel.panel_pictures.build(
\r
1262 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 0+1)
\r
1264 sb1 = @panel.speech_balloons.build(
\r
1265 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1267 sb1.build_balloon(
\r
1268 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1271 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1275 sb2 = @panel.speech_balloons.build(
\r
1276 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)
\r
1278 sb2.build_balloon(
\r
1279 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1282 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1286 @gc = @panel.ground_colors.build(
\r
1287 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1289 @gp = @panel.ground_pictures.build(
\r
1290 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1292 r = @panel.validate_child
\r
1297 describe '保存に於いて' do
\r
1299 @attr = FactoryGirl.attributes_for :panel
\r
1300 @panel = Panel.new
\r
1301 @panel.supply_default
\r
1303 context 'つつがなく終わるとき' do
\r
1305 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1306 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1308 it 'コマモデルに上書き補充を依頼している' do
\r
1309 Panel.any_instance.should_receive(:overwrite).exactly(1)
\r
1310 r = @panel.store @attr, @author
\r
1313 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
1314 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1315 r = @panel.store @attr, @author
\r
1317 it '従属データの検証を依頼している' do
\r
1318 Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1)
\r
1319 r = @panel.store @attr, @author
\r
1322 context 'つつがなく終わるとき' do
\r
1324 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1327 r = @panel.store @attr, @author
\r
1331 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1333 r = @panel.store @attr, @author
\r
1334 }.should change(Panel, :count)
\r
1337 context '不正なjsonデータのとき' do
\r
1340 it 'エラーメッセージがセットされている' do
\r
1341 r = @panel.store false, @author
\r
1342 @panel.errors[:base].should_not be_blank
\r
1345 context '従属データの検証に失敗したとき' do
\r
1347 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1348 Panel.any_instance.stub(:validate_child).with(any_args).and_return(false)
\r
1350 it 'エラーメッセージがセットされている' do
\r
1351 r = @panel.store @attr, @author
\r
1352 @panel.errors[:base].should_not be_blank
\r
1355 context 'カラム値がFalseしたとき' do
\r
1357 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1359 it 'エラーメッセージがセットされている' do
\r
1360 r = @panel.store false, @author
\r
1361 @panel.errors.should_not be_empty
\r
1366 describe '要素の検証に於いて' do
\r
1368 @panel = Panel.new
\r
1369 @panel.supply_default
\r
1370 @attr = FactoryGirl.attributes_for :panel
\r
1372 "speech_balloons_attributes" => {
\r
1374 "caption" => "大きな文字で","z" => "1","t" => "0",
\r
1375 "classname" => "CircleSpeechBalloon","speech_balloon_template_id" => @sbt.id,
\r
1376 "speech_attributes" => {
\r
1377 "content" => "カギッコ","x" => "20","y" => "20","width" => "-60","height" => "60",
\r
1378 "settings" => "","writing_format_id" => @writing_format.id
\r
1380 "balloon_attributes" => {
\r
1381 "r" => "247","x" => "293","y" => "-2","width" => "200","height" => "200",
\r
1382 "system_picture_id" => @sp.id,"settings" => ""
\r
1389 "panel_pictures_attributes" => {
\r
1391 "caption" => "司会","x" => "a","y" => "99","z" => "1","t" => "0",
\r
1392 "width" => "156","height" => "245","link" => "","picture_id" => @p.id
\r
1398 context 'フキダシの幅がマイナスで検証に失敗したとき' do
\r
1400 @attr.merge!(@sbattr)
\r
1402 it 'エラーメッセージがセットされている' do
\r
1403 r = @panel.store @attr, @author
\r
1405 @panel.errors.should_not be_empty
\r
1408 context 'コマ絵の横軸はアルファベットのため検証に失敗したとき' do
\r
1410 @attr.merge!(@ppattr)
\r
1412 it 'エラーメッセージがセットされている' do
\r
1413 r = @panel.store @attr, @author
\r
1415 @panel.errors.should_not be_empty
\r
1420 describe '削除に於いて' do
\r
1422 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
\r
1423 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
\r
1424 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1425 @sb = @panel.speech_balloons.build(
\r
1426 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1428 @sb.build_balloon(
\r
1429 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1432 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1436 @gc = @panel.ground_colors.create(
\r
1437 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
\r
1439 @gp = @panel.ground_pictures.create(
\r
1440 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1443 context 'つつがなく終わるとき' do
\r
1446 r = @panel.destroy_with_elements
\r
1447 }.should change(Panel, :count).by(-1)
\r
1449 r = Panel.find @panel.id
\r
1450 }.should raise_error
\r
1452 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1454 r = @panel.destroy_with_elements
\r
1455 }.should change(PanelPicture, :count).by(-1)
\r
1457 r = PanelPicture.find @pp.id
\r
1458 }.should raise_error
\r
1460 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1462 r = @panel.destroy_with_elements
\r
1463 }.should change(GroundPicture, :count).by(-1)
\r
1465 r = GroundPicture.find @gp.id
\r
1466 }.should raise_error
\r
1469 r = @panel.destroy_with_elements
\r
1473 context '削除に失敗したとき' do
\r
1475 PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
\r
1478 r = @panel.destroy_with_elements
\r
1481 it 'ロールバックしている' do
\r
1483 r = @panel.destroy_with_elements
\r
1484 }.should_not change(Panel, :count)
\r
1486 r = @panel.destroy_with_elements
\r
1487 }.should_not change(PanelPicture, :count)
\r
1492 describe 'id挿げ替え防止確認に於いて' do
\r
1495 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1496 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1497 @sb = @panel.speech_balloons.create(
\r
1498 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1500 @gc = @panel.ground_colors.create(
\r
1501 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
1503 @gp = @panel.ground_pictures.create(
\r
1504 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1506 @pc = @panel.panel_colors.create(
\r
1507 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
1511 it 'author,コマ要素を含んでいる' do
\r
1512 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
\r
1513 @panel2.panel_pictures.create(
\r
1514 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height)
\r
1519 describe 'id一致チェックに於いて' do
\r
1520 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
1521 context '親が既存(idが数値)のとき' do
\r
1522 it 'すべてid一致するときTrueを返す' do
\r
1523 r = Panel.validate_id [1, 1, 1, 1], 1
\r
1526 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
1527 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
1530 it 'すべて数値でも一致しないときFalseを返す' do
\r
1531 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
1534 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
1535 r = Panel.validate_id [1, 1, nil, 2], 1
\r
1539 context '親が新規(idがNil)のとき' do
\r
1540 it 'すべてNilはTrueを返す' do
\r
1541 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
1544 it 'すべてnilでなければFalseを返す' do
\r
1545 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
1550 describe 'idチェック単体に於いて' do
\r
1552 # @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1
\r
1554 context 'つつがなく終わるとき' do
\r
1555 it 'idを収集依頼している' do
\r
1556 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1557 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1558 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1559 r = Panel.validate_element_id [], :panel_id, nil
\r
1561 it '収集したidを一致チェック依頼している' do
\r
1562 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
1563 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1564 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1565 r = Panel.validate_element_id [], :panel_id, nil
\r
1569 #依頼チェックだけでは不安なので最低限のチェックを
\r
1570 context 'コマ新規のとき' do
\r
1571 it 'コマ絵で正常通過している' do
\r
1572 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1573 @panel.panel_pictures.build(
\r
1574 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1576 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1579 it 'フキダシで正常通過している' do
\r
1580 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1581 @panel.speech_balloons.build(
\r
1582 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1584 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1588 context 'コマ既存のとき' do
\r
1589 it 'コマ絵で正常通過している' do
\r
1590 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1591 @panel.panel_pictures.build(
\r
1592 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1594 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1597 it 'フキダシで正常通過している' do
\r
1598 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1599 @panel.speech_balloons.build(
\r
1600 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1602 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1606 context 'フキダシ新規のとき' do
\r
1607 it 'バルーンで正常通過している' do
\r
1608 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1609 @panel.speech_balloons.build(
\r
1610 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1612 @panel.speech_balloons.first.balloons.build(
\r
1613 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1615 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1618 it 'セリフで正常通過している' do
\r
1619 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1620 @panel.speech_balloons.build(
\r
1621 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1623 @panel.speech_balloons.first.speeches.build(
\r
1624 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1626 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1631 describe 'idチェックリスト生成に於いて' do
\r
1633 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1635 context 'つつがなく終わるとき' do
\r
1636 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
1637 @panel.panel_pictures.build(
\r
1638 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1640 @panel.speech_balloons.build(
\r
1641 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1643 @panel.speech_balloons.first.balloons.build(
\r
1644 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1646 @panel.speech_balloons.first.speeches.build(
\r
1647 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1649 r = @panel.validate_id_list
\r
1650 r.should have(2).items
\r
1652 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
1653 @panel.panel_pictures.build(
\r
1654 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1656 sb1 = @panel.speech_balloons.build(
\r
1657 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1659 sb1.balloons.build(
\r
1660 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1662 sb1.speeches.build(
\r
1663 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1665 sb2 = @panel.speech_balloons.build(
\r
1666 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1668 sb2.balloons.build(
\r
1669 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1671 sb2.speeches.build(
\r
1672 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1674 r = @panel.validate_id_list
\r
1675 r.should have(3).items
\r
1679 describe 'idチェック複合に於いて' do
\r
1681 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1683 context 'つつがなく終わるとき' do
\r
1684 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
1685 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
1686 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
1687 @panel.panel_pictures.build(
\r
1688 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1690 sb1 = @panel.speech_balloons.build(
\r
1691 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1693 sb1.balloons.build(
\r
1694 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1696 sb1.speeches.build(
\r
1697 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1699 r = Panel.validate_elements_id(@panel.validate_id_list)
\r