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 @writing_format = FactoryGirl.create :writing_format
\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, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
\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
179 context 'captionを検証するとき' do
\r
180 it 'Shift JISなら失敗する' do
\r
181 @panel.caption = "\x83G\x83r\x83]\x83D"
\r
183 @panel.valid_encode
\r
184 }.should raise_error(Pettanr::BadRequest)
\r
190 describe 'デフォルト値補充に於いて' do
\r
192 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
194 it 'borderは2を補充する' do
\r
195 @panel.border = nil
\r
196 @panel.supply_default
\r
197 @panel.border.should eq 2
\r
199 it 'publishは0を補充する' do
\r
200 @panel.publish = nil
\r
201 @panel.supply_default
\r
202 @panel.publish.should eq 0
\r
206 describe '上書き補充に於いて' do
\r
208 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
210 context 'author_idを補充' do
\r
211 it 'ログイン中の作家idを補充する' do
\r
212 @panel.author_id = nil
\r
213 @panel.overwrite @author
\r
214 @panel.author_id.should eq @author.id
\r
220 describe '所持判定に於いて' do
\r
222 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
224 context '事前チェックする' do
\r
225 it '自身にロールリストからの作家取得を依頼している' do
\r
226 Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
\r
227 r = @panel.own?([@author])
\r
230 context 'ロール内作家が取得できるとき' do
\r
233 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
\r
234 Panel.stub(:get_author_from_roles).with(any_args).and_return(@author)
\r
235 r = @panel.own?([@author])
\r
238 it 'ロール内作家のidが自身の作家idと一致しないならno' do
\r
239 Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
\r
240 @panel.own?(@other_author).should be_false
\r
243 context 'ロール内作家が取得できないとき' do
\r
245 Panel.stub(:get_author_from_roles).with(any_args).and_return(nil)
\r
248 r = @panel.own?([@author])
\r
254 describe '閲覧許可に於いて' do
\r
256 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
\r
257 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
258 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
\r
260 context 'オープンモードのとき' do
\r
262 MagicNumber['run_mode'] = 0
\r
264 it '自身にゲスト用ロールチェックを問い合わせしている' do
\r
265 Panel.any_instance.stub(:guest_role_check).and_return(true)
\r
266 Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
\r
267 r = @panel.visible?([@author])
\r
269 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
\r
270 Panel.any_instance.stub(:guest_role_check).and_return(false)
\r
271 r = @panel.visible?([@author])
\r
275 context 'クローズドモードのとき' do
\r
277 MagicNumber['run_mode'] = 1
\r
279 it '自身に読者用ロールチェックを問い合わせしている' do
\r
280 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
281 Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
\r
282 r = @panel.visible?([@author])
\r
284 it '読者用ロールチェックが失敗したとき、falseを返す' do
\r
285 Panel.any_instance.stub(:reader_role_check).and_return(false)
\r
286 r = @panel.visible?([@author])
\r
290 context '事前チェックする' do
\r
292 MagicNumber['run_mode'] = 1
\r
293 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
295 it '自身に所持判定を問い合わせしている' do
\r
296 Panel.any_instance.stub(:own?).and_return(true)
\r
297 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
298 r = @panel.visible?([@author])
\r
300 it '自身に閲覧許可を問い合わせしている' do
\r
301 Panel.any_instance.stub(:own?).and_return(false)
\r
302 Panel.any_instance.stub(:publish?).and_return(true)
\r
303 Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1)
\r
304 r = @panel.visible?([@author])
\r
307 context 'つつがなく終わるとき' do
\r
309 MagicNumber['run_mode'] = 1
\r
310 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
312 it '自分のコマなら許可する' do
\r
313 Panel.any_instance.stub(:own?).and_return(true)
\r
314 Panel.any_instance.stub(:publish?).and_return(false)
\r
315 r = @panel.visible?([@author])
\r
318 it '他人の非公開コマなら許可しない' do
\r
319 Panel.any_instance.stub(:own?).and_return(false)
\r
320 Panel.any_instance.stub(:publish?).and_return(false)
\r
321 r = @panel.visible?([@author])
\r
324 it '他人のコマでも公開なら許可する' do
\r
325 Panel.any_instance.stub(:own?).and_return(false)
\r
326 Panel.any_instance.stub(:publish?).and_return(true)
\r
327 r = @panel.visible?([@author])
\r
333 describe '一覧取得に於いて' do
\r
335 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
337 context 'page補正について' do
\r
338 it '文字列から数値に変換される' do
\r
339 Panel.page('8').should eq 8
\r
341 it 'nilの場合は1になる' do
\r
342 Panel.page().should eq 1
\r
344 it '0以下の場合は1になる' do
\r
345 Panel.page('0').should eq 1
\r
348 context 'page_size補正について' do
\r
349 it '文字列から数値に変換される' do
\r
350 Panel.page_size('7').should eq 7
\r
352 it 'nilの場合はPanel.default_page_sizeになる' do
\r
353 Panel.page_size().should eq Panel.default_page_size
\r
355 it '0以下の場合はPanel.default_page_sizeになる' do
\r
356 Panel.page_size('0').should eq Panel.default_page_size
\r
358 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
359 Panel.page_size('1000').should eq Panel.max_page_size
\r
364 r.should eq [@panel]
\r
367 #公開コミックは(他人のコミックであっても)含んでいる
\r
368 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
370 r.should eq [npl, @panel]
\r
372 it '非公開のコマ(自分のコマであっても)は含まない' do
\r
373 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
375 r.should eq [@panel]
\r
377 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
379 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
380 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
381 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
382 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
383 Panel.stub(:default_page_size).and_return(2)
\r
387 pl.should have(2).items
\r
389 it 'page=1なら末尾2件を返す' do
\r
392 pl.should eq [@npl5, @npl4]
\r
394 it 'page=2なら中間2件を返す' do
\r
396 pl.should eq [@npl3, @npl2]
\r
398 it 'page=3なら先頭1件を返す' do
\r
400 pl.should eq [@panel]
\r
405 describe '自分のコマ一覧取得に於いて' do
\r
407 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
410 pl = Panel.mylist @author
\r
411 pl.should eq [@panel]
\r
414 npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
415 pl = Panel.mylist @author
\r
416 pl.should eq [npl, @panel]
\r
418 it '他人のコマは公開でも含まない' do
\r
419 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
420 pl = Panel.mylist @author
\r
421 pl.should eq [@panel]
\r
423 it '自分のコマは非公開でも含んでいる' do
\r
424 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100
\r
425 pl = Panel.mylist @author
\r
426 pl.should eq [npl, @panel]
\r
428 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
430 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
431 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
432 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
433 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
436 pl = Panel.mylist @author, 1, 2
\r
437 pl.should have(2).items
\r
439 it 'page=1なら末尾2件を返す' do
\r
441 pl = Panel.mylist @author, 1, 2
\r
442 pl.should eq [@npl5, @npl4]
\r
444 it 'page=2なら中間2件を返す' do
\r
445 pl = Panel.mylist @author, 2, 2
\r
446 pl.should eq [@npl3, @npl2]
\r
448 it 'page=3なら先頭1件を返す' do
\r
449 pl = Panel.mylist @author, 3, 2
\r
450 pl.should eq [@panel]
\r
455 describe '他作家のコマ一覧取得に於いて' do
\r
457 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
458 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
461 r = Panel.himlist @other_author
\r
462 r.should eq [@other_panel]
\r
465 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
466 r = Panel.himlist @other_author
\r
467 r.should eq [npl, @other_panel]
\r
470 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
\r
471 r = Panel.himlist @other_author
\r
472 r.should eq [@other_panel]
\r
474 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
476 @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
477 @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200
\r
478 @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300
\r
479 @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400
\r
482 pl = Panel.himlist @other_author, 1, 2
\r
483 pl.should have(2).items
\r
485 it 'page=1なら末尾2件を返す' do
\r
487 pl = Panel.himlist @other_author, 1, 2
\r
488 pl.should eq [@other_panel5, @other_panel4]
\r
490 it 'page=2なら中間2件を返す' do
\r
491 pl = Panel.himlist @other_author, 2, 2
\r
492 pl.should eq [@other_panel3, @other_panel2]
\r
494 it 'page=3なら先頭1件を返す' do
\r
495 pl = Panel.himlist @other_author, 3, 2
\r
496 pl.should eq [@other_panel]
\r
501 describe 'コマ一覧ページ制御に於いて' do
\r
503 Panel.stub(:count).with(any_args).and_return(100)
\r
506 r = Panel.list_paginate
\r
507 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
509 it 'コマ一覧の取得条件を利用している' do
\r
510 Panel.stub(:list_where).with(any_args).and_return('')
\r
511 Panel.should_receive(:list_where).with(any_args).exactly(1)
\r
512 r = Panel.list_paginate
\r
514 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
515 r = Panel.list_paginate 3, 10
\r
516 r.limit_value.should eq 10
\r
517 r.offset_value.should eq 20
\r
521 describe '自分のコマ一覧ページ制御に於いて' do
\r
523 Panel.stub(:count).with(any_args).and_return(100)
\r
526 r = Panel.mylist_paginate @author
\r
527 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
529 it '自分のコマ一覧の取得条件を利用している' do
\r
530 Panel.stub(:mylist_where).with(any_args).and_return('')
\r
531 Panel.should_receive(:mylist_where).with(any_args).exactly(1)
\r
532 r = Panel.mylist_paginate @author
\r
534 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
535 r = Panel.mylist_paginate @author, 3, 10
\r
536 r.limit_value.should eq 10
\r
537 r.offset_value.should eq 20
\r
541 describe '他作家のコマ一覧ページ制御に於いて' do
\r
543 Panel.stub(:count).with(any_args).and_return(100)
\r
546 r = Panel.himlist_paginate @other_author
\r
547 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
549 it '他作家のコマ一覧の取得条件を利用している' do
\r
550 Panel.stub(:himlist_where).with(any_args).and_return('')
\r
551 Panel.should_receive(:himlist_where).with(any_args).exactly(1)
\r
552 r = Panel.himlist_paginate @other_author
\r
554 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
555 r = Panel.himlist_paginate @other_author, 3, 10
\r
556 r.limit_value.should eq 10
\r
557 r.offset_value.should eq 20
\r
561 describe '一覧取得オプションに於いて' do
\r
562 it '5つの項目を含んでいる' do
\r
564 r.should have(5).items
\r
568 r.has_key?(:panel_pictures).should be_true
\r
570 it 'コマ絵は実素材を含んでいる' do
\r
572 r[:panel_pictures].has_key?(:picture).should be_true
\r
574 it '実素材は絵師を含んでいる' do
\r
576 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
578 it '実素材はライセンスを含んでいる' do
\r
580 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
584 r.has_key?(:speech_balloons).should be_true
\r
586 it 'フキダシはフキダシ枠を含んでいる' do
\r
588 r[:speech_balloons].has_key?(:balloon).should be_true
\r
590 it 'フキダシはセリフを含んでいる' do
\r
592 r[:speech_balloons].has_key?(:speech).should be_true
\r
596 r.has_key?(:ground_pictures).should be_true
\r
598 it '絵地は実素材を含んでいる' do
\r
600 r[:ground_pictures].has_key?(:picture).should be_true
\r
602 it '実素材は絵師を含んでいる' do
\r
604 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
606 it '実素材はライセンスを含んでいる' do
\r
608 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
612 r.has_key?(:ground_colors).should be_true
\r
616 r.has_key?(:author).should be_true
\r
619 describe 'json一覧出力オプションに於いて' do
\r
622 describe '単体取得に於いて' do
\r
624 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
626 context 'つつがなく終わるとき' do
\r
627 it '単体取得オプションを利用している' do
\r
628 Panel.stub(:show_opt).with(any_args).and_return({})
\r
629 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
630 r = Panel.show @panel.id, @author
\r
632 it '閲覧許可を問い合わせている' do
\r
633 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
634 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
635 r = Panel.show @panel.id, @author
\r
639 Panel.any_instance.stub(:visible?).and_return(true)
\r
640 pl = Panel.show @panel.id, @author
\r
641 pl.should eq @panel
\r
643 context '閲覧許可が出なかったとき' do
\r
644 it '403Forbidden例外を返す' do
\r
645 Panel.any_instance.stub(:visible?).and_return(false)
\r
647 Panel.show @panel.id, @author
\r
648 }.should raise_error(ActiveRecord::Forbidden)
\r
651 context '存在しないコマを開こうとしたとき' do
\r
652 it '404RecordNotFound例外を返す' do
\r
654 Panel.show 110, @author
\r
655 }.should raise_error(ActiveRecord::RecordNotFound)
\r
659 describe '編集取得に於いて' do
\r
661 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
663 context 'つつがなく終わるとき' do
\r
664 it '単体取得オプションを利用している' do
\r
665 Panel.stub(:show_opt).with(any_args).and_return({})
\r
666 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
667 r = Panel.edit @panel.id, @author
\r
669 it '所持判定を問い合わせている' do
\r
670 Panel.any_instance.stub(:own?).with(any_args).and_return(true)
\r
671 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
672 r = Panel.edit @panel.id, @author
\r
676 Panel.any_instance.stub(:own?).and_return(true)
\r
677 pl = Panel.edit @panel.id, @author
\r
678 pl.should eq @panel
\r
680 context '他人のコマを開こうとしたとき' do
\r
681 it '403Forbidden例外を返す' do
\r
682 Panel.any_instance.stub(:own?).and_return(false)
\r
684 Panel.edit @panel.id, @author
\r
685 }.should raise_error(ActiveRecord::Forbidden)
\r
688 context '存在しないコマを開こうとしたとき' do
\r
689 it '404RecordNotFound例外を返す' do
\r
691 Panel.edit 110, @author
\r
692 }.should raise_error(ActiveRecord::RecordNotFound)
\r
696 describe '単体取得オプションに於いて' do
\r
697 it 'includeキーを含んでいる' do
\r
699 r.has_key?(:include).should be_true
\r
701 it '5つの項目を含んでいる' do
\r
702 r = Panel.show_opt[:include]
\r
703 r.should have(5).items
\r
706 r = Panel.show_opt[:include]
\r
707 r.has_key?(:panel_pictures).should be_true
\r
709 it 'コマ絵は実素材を含んでいる' do
\r
710 r = Panel.show_opt[:include]
\r
711 r[:panel_pictures].has_key?(:picture).should be_true
\r
713 it '実素材は絵師を含んでいる' do
\r
714 r = Panel.show_opt[:include]
\r
715 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
717 it '実素材はライセンスを含んでいる' do
\r
718 r = Panel.show_opt[:include]
\r
719 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
722 r = Panel.show_opt[:include]
\r
723 r.has_key?(:speech_balloons).should be_true
\r
725 it 'フキダシはフキダシ枠を含んでいる' do
\r
726 r = Panel.show_opt[:include]
\r
727 r[:speech_balloons].has_key?(:balloon).should be_true
\r
729 it 'フキダシはセリフを含んでいる' do
\r
730 r = Panel.show_opt[:include]
\r
731 r[:speech_balloons].has_key?(:speech).should be_true
\r
734 r = Panel.show_opt[:include]
\r
735 r.has_key?(:ground_pictures).should be_true
\r
737 it '絵地は実素材を含んでいる' do
\r
738 r = Panel.show_opt[:include]
\r
739 r[:ground_pictures].has_key?(:picture).should be_true
\r
741 it '実素材は絵師を含んでいる' do
\r
742 r = Panel.show_opt[:include]
\r
743 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
745 it '実素材はライセンスを含んでいる' do
\r
746 r = Panel.show_opt[:include]
\r
747 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
750 r = Panel.show_opt[:include]
\r
751 r.has_key?(:ground_colors).should be_true
\r
754 r = Panel.show_opt[:include]
\r
755 r.has_key?(:author).should be_true
\r
758 describe 'json単体出力オプションに於いて' do
\r
760 describe 'コマ部品集合に於いて' do
\r
763 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
764 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
765 @sb = @panel.speech_balloons.build(
\r
766 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
769 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
772 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
776 @gc = @panel.ground_colors.create(
\r
777 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
779 @gp = @panel.ground_pictures.create(
\r
780 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
785 r = @panel.parts_element
\r
786 r.is_a?(Array).should be_true
\r
788 it 'コマ絵とフキダシと絵地と色地を合わせている' do
\r
789 r = @panel.parts_element
\r
790 r.include?(@pp).should be_true
\r
791 r.include?(@sb).should be_true
\r
792 r.include?(@gc).should be_true
\r
793 r.include?(@gp).should be_true
\r
797 describe 'z順コマ部品に於いて' do
\r
800 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
801 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :width => @p.width, :height => @p.height
\r
802 @sb = @panel.speech_balloons.build(
\r
803 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1)
\r
806 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
809 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
813 @gc = @panel.ground_colors.create(
\r
814 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3)
\r
816 @gp = @panel.ground_pictures.create(
\r
817 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4)
\r
821 context 'つつがなく終わるとき' do
\r
822 it 'コマ部品集合を利用している' do
\r
823 Panel.any_instance.stub(:parts_element).with(any_args).and_return([])
\r
824 Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)
\r
825 r = @panel.zorderd_elements
\r
829 r = @panel.zorderd_elements
\r
830 r.is_a?(Array).should be_true
\r
833 it 'zでオフセットを0でソートしている' do
\r
834 r = @panel.zorderd_elements
\r
840 context 'さらに末尾にフキダシを追加したとき' do
\r
842 @sb2 = @panel.speech_balloons.build(
\r
843 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5)
\r
845 @sb2.build_balloon(
\r
846 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
849 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
856 r = @panel.zorderd_elements
\r
861 r[4].should eq @sb2
\r
865 describe 'コマ要素に於いて' do
\r
868 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
869 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
870 @sb = @panel.speech_balloons.build(
\r
871 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
874 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
877 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
881 @gc = @panel.ground_colors.create(
\r
882 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
884 @gp = @panel.ground_pictures.create(
\r
885 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
889 context 'つつがなく終わるとき' do
\r
890 it 'コマ部品を利用している' do
\r
891 Panel.any_instance.stub(:parts_element).with(any_args).and_return([])
\r
892 Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)
\r
893 r = @panel.panel_elements
\r
897 r = @panel.panel_elements
\r
898 r.is_a?(Array).should be_true
\r
901 r = @panel.panel_elements
\r
907 context 'さらに末尾にフキダシを追加したとき' do
\r
909 @sb2 = @panel.speech_balloons.build(
\r
910 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)
\r
912 @sb2.build_balloon(
\r
913 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
916 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
923 r = @panel.panel_elements
\r
928 r[4].should eq @sb2
\r
932 describe 'コマ要素のjson出力に於いて' do
\r
935 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
936 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
937 @sb = @panel.speech_balloons.build(
\r
938 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
941 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
944 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
948 @gc = @panel.ground_colors.create(
\r
949 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
951 @gp = @panel.ground_pictures.create(
\r
952 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
956 context 'つつがなく終わるとき' do
\r
958 PanelPicture.stub(:json_opt_for_panel).and_return({})
\r
959 SpeechBalloon.stub(:json_opt_for_panel).and_return({})
\r
960 GroundPicture.stub(:json_opt_for_panel).and_return({})
\r
961 GroundColor.stub(:json_opt_for_panel).and_return({})
\r
963 it 'コマ絵にjson出力オプションを依頼している' do
\r
964 PanelPicture.should_receive(:json_opt_for_panel).exactly(1)
\r
965 r = @panel.elements
\r
967 it 'フキダシにjson出力オプションを依頼している' do
\r
968 SpeechBalloon.should_receive(:json_opt_for_panel).exactly(1)
\r
969 r = @panel.elements
\r
971 it '絵地にjson出力オプションを依頼している' do
\r
972 GroundPicture.should_receive(:json_opt_for_panel).exactly(1)
\r
973 r = @panel.elements
\r
975 it '色地にjson出力オプションを依頼している' do
\r
976 GroundColor.should_receive(:json_opt_for_panel).exactly(1)
\r
977 r = @panel.elements
\r
981 r = @panel.elements
\r
982 r.is_a?(Array).should be_true
\r
985 describe 'コマのjson出力に於いて' do
\r
988 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
989 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
990 @sb = @panel.speech_balloons.build(
\r
991 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
994 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
997 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1001 @gc = @panel.ground_colors.create(
\r
1002 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
1004 @gp = @panel.ground_pictures.create(
\r
1005 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
1009 context 'つつがなく終わるとき' do
\r
1011 Panel.any_instance.stub(:elements).with(any_args).and_return({})
\r
1013 it 'コマ要素のjson出力を依頼している' do
\r
1014 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
1015 r = @panel.panel_elements_as_json
\r
1018 it 'json textを返している' do
\r
1019 r = JSON.parse @panel.panel_elements_as_json
\r
1020 r.is_a?(Hash).should be_true
\r
1022 it 'author,コマ要素を含んでいる' do
\r
1023 r = JSON.parse @panel.panel_elements_as_json
\r
1024 r.has_key?('author').should be_true
\r
1025 r.has_key?('elements').should be_true
\r
1027 sb = r['elements'].first
\r
1028 sb.has_key?('classname').should be_true
\r
1029 sb.has_key?('balloon').should be_true
\r
1030 sb.has_key?('speech').should be_true
\r
1034 describe 'コマリストのjson出力に於いて' do
\r
1036 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1037 Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}')
\r
1039 context 'つつがなく終わるとき' do
\r
1040 it 'コマのjson出力を依頼している' do
\r
1041 Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1)
\r
1042 r = Panel.list_as_json_text [@panel]
\r
1045 it 'json textを返している' do
\r
1046 r = Panel.list_as_json_text [@panel]
\r
1048 j.is_a?(Array).should be_true
\r
1051 r = Panel.list_as_json_text [@panel]
\r
1053 j.first.has_key?('p').should be_true
\r
1057 describe 'ライセンス素材に於いて' do
\r
1060 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
1061 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
\r
1062 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
\r
1063 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1064 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id
\r
1065 @sb = @panel.speech_balloons.build(
\r
1066 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1068 @sb.build_balloon(
\r
1069 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1072 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1076 @gc = @panel.ground_colors.create(
\r
1077 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
1079 @gp = @panel.ground_pictures.create(
\r
1080 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3)
\r
1084 context '事前チェック' do
\r
1086 context 'つつがなく終わるとき' do
\r
1088 it '連想配列(値は実素材、キーは実素材id)を返している' do
\r
1089 r = @panel.licensed_pictures
\r
1090 r.is_a?(Hash).should be_true
\r
1091 r.should have(2).items
\r
1092 r[@pp.picture_id].should eq @p
\r
1093 r[@gp.picture_id].should eq @p2
\r
1097 describe '検証値収集に於いて' do
\r
1098 context 'つつがなく終わるとき' do
\r
1099 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1100 elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
1101 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
1102 r = Panel.collect_element_value elements, :panel_id
\r
1103 r.should eq [1, 2, 3, 4]
\r
1105 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1106 elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}],
\r
1107 [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]]
\r
1108 r = Panel.collect_element_value elements, :t
\r
1109 r.should eq [1, 2, 3, 0]
\r
1113 describe 'シリアライズチェックに於いて' do
\r
1114 context 'つつがなく終わるとき' do
\r
1115 it '0からシリアライズされているならTrueを返す' do
\r
1116 r = Panel.validate_serial [0, 1, 2]
\r
1119 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1120 r = Panel.validate_serial [0, 2, 1]
\r
1123 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1124 r = Panel.validate_serial [ 2, 1, 4, 3, 0]
\r
1128 context 'オフセットが1のとき' do
\r
1129 it '0からシリアライズされているならFalseを返す' do
\r
1130 r = Panel.validate_serial [0, 1, 2], 1
\r
1133 it '1からシリアライズされているならTrueを返す' do
\r
1134 r = Panel.validate_serial [1, 2, 3], 1
\r
1138 context '異常なとき' do
\r
1139 it '0から始まらないならFalseを返す' do
\r
1140 r = Panel.validate_serial [1, 2, 3]
\r
1143 it '連続していないならFalseを返す' do
\r
1144 r = Panel.validate_serial [0, 1, 2, 4]
\r
1147 it '連続していないならFalseを返す' do
\r
1148 r = Panel.validate_serial [0, 1, 2, 4, 5]
\r
1153 describe 'シリアライズチェック単体に於いて' do
\r
1156 context 'つつがなく終わるとき' do
\r
1157 it '検証値収集を依頼している' do
\r
1158 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1159 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1160 Panel.stub(:validate_serial).with(any_args).and_return(true)
\r
1161 r = Panel.validate_element_serial [], :t
\r
1163 it 'シリアライズチェック依頼している' do
\r
1164 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1165 Panel.should_receive(:validate_serial).with(any_args).exactly(1)
\r
1166 Panel.stub(:validate_serial).with(any_args).and_return(true)
\r
1167 r = Panel.validate_element_serial [], :t
\r
1171 describe '従属データの検証に於いて' do
\r
1172 context 'つつがなく終わるとき' do
\r
1173 it 'trueを返している' do
\r
1174 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1175 @panel.panel_pictures.build(
\r
1176 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1178 @panel.panel_pictures.build(
\r
1179 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)
\r
1181 sb1 = @panel.speech_balloons.build(
\r
1182 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1184 sb1.build_balloon(
\r
1185 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1188 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1192 sb2 = @panel.speech_balloons.build(
\r
1193 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)
\r
1195 sb2.build_balloon(
\r
1196 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1199 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1203 @gc = @panel.ground_colors.build(
\r
1204 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1206 @gp = @panel.ground_pictures.build(
\r
1207 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1209 r = @panel.validate_child
\r
1213 context 'tシリアライズされていないとき' do
\r
1214 it 'falseを返している' do
\r
1215 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1216 @panel.panel_pictures.build(
\r
1217 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1219 @panel.panel_pictures.build(
\r
1220 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)
\r
1222 sb1 = @panel.speech_balloons.build(
\r
1223 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1225 sb1.build_balloon(
\r
1226 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1229 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1233 sb2 = @panel.speech_balloons.build(
\r
1234 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)
\r
1236 sb2.build_balloon(
\r
1237 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1240 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1244 @gc = @panel.ground_colors.build(
\r
1245 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1247 @gp = @panel.ground_pictures.build(
\r
1248 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1250 r = @panel.validate_child
\r
1254 context 'zシリアライズされていないとき' do
\r
1255 it 'falseを返している' do
\r
1256 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1257 @panel.panel_pictures.build(
\r
1258 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1260 @panel.panel_pictures.build(
\r
1261 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 0+1)
\r
1263 sb1 = @panel.speech_balloons.build(
\r
1264 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1266 sb1.build_balloon(
\r
1267 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1270 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1274 sb2 = @panel.speech_balloons.build(
\r
1275 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)
\r
1277 sb2.build_balloon(
\r
1278 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1281 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1285 @gc = @panel.ground_colors.build(
\r
1286 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1288 @gp = @panel.ground_pictures.build(
\r
1289 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1291 r = @panel.validate_child
\r
1296 describe '保存に於いて' do
\r
1298 @attr = FactoryGirl.attributes_for :panel
\r
1299 @panel = Panel.new
\r
1300 @panel.supply_default
\r
1302 context 'つつがなく終わるとき' do
\r
1304 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1305 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1307 it 'コマモデルに上書き補充を依頼している' do
\r
1308 Panel.any_instance.should_receive(:overwrite).exactly(1)
\r
1309 r = @panel.store @attr, @author
\r
1312 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
1313 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1314 r = @panel.store @attr, @author
\r
1316 it '従属データの検証を依頼している' do
\r
1317 Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1)
\r
1318 r = @panel.store @attr, @author
\r
1321 context 'つつがなく終わるとき' do
\r
1323 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1326 r = @panel.store @attr, @author
\r
1330 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1332 r = @panel.store @attr, @author
\r
1333 }.should change(Panel, :count)
\r
1336 context '不正なjsonデータのとき' do
\r
1339 it 'エラーメッセージがセットされている' do
\r
1340 r = @panel.store false, @author
\r
1341 @panel.errors[:base].should_not be_blank
\r
1344 context '従属データの検証に失敗したとき' do
\r
1346 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1347 Panel.any_instance.stub(:validate_child).with(any_args).and_return(false)
\r
1349 it 'エラーメッセージがセットされている' do
\r
1350 r = @panel.store @attr, @author
\r
1351 @panel.errors[:base].should_not be_blank
\r
1354 context 'カラム値がFalseしたとき' do
\r
1356 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1358 it 'エラーメッセージがセットされている' do
\r
1359 r = @panel.store false, @author
\r
1360 @panel.errors.should_not be_empty
\r
1365 describe '要素の検証に於いて' do
\r
1367 @panel = Panel.new
\r
1368 @panel.supply_default
\r
1369 @attr = FactoryGirl.attributes_for :panel
\r
1371 "speech_balloons_attributes" => {
\r
1373 "caption" => "大きな文字で","z" => "1","t" => "0",
\r
1374 "classname" => "CircleSpeechBalloon","speech_balloon_template_id" => @sbt.id,
\r
1375 "speech_attributes" => {
\r
1376 "content" => "カギッコ","x" => "20","y" => "20","width" => "-60","height" => "60",
\r
1377 "settings" => "","writing_format_id" => @writing_format.id
\r
1379 "balloon_attributes" => {
\r
1380 "r" => "247","x" => "293","y" => "-2","width" => "200","height" => "200",
\r
1381 "system_picture_id" => @sp.id,"settings" => ""
\r
1388 "panel_pictures_attributes" => {
\r
1390 "caption" => "司会","x" => "a","y" => "99","z" => "1","t" => "0",
\r
1391 "width" => "156","height" => "245","link" => "","picture_id" => @p.id
\r
1397 context 'フキダシの幅がマイナスで検証に失敗したとき' do
\r
1399 @attr.merge!(@sbattr)
\r
1401 it 'エラーメッセージがセットされている' do
\r
1402 r = @panel.store @attr, @author
\r
1404 @panel.errors.should_not be_empty
\r
1407 context 'コマ絵の横軸はアルファベットのため検証に失敗したとき' do
\r
1409 @attr.merge!(@ppattr)
\r
1411 it 'エラーメッセージがセットされている' do
\r
1412 r = @panel.store @attr, @author
\r
1414 @panel.errors.should_not be_empty
\r
1419 describe '削除に於いて' do
\r
1421 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
\r
1422 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
\r
1423 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1424 @sb = @panel.speech_balloons.build(
\r
1425 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1427 @sb.build_balloon(
\r
1428 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1431 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1435 @gc = @panel.ground_colors.create(
\r
1436 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
\r
1438 @gp = @panel.ground_pictures.create(
\r
1439 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1442 context 'つつがなく終わるとき' do
\r
1445 r = @panel.destroy_with_elements
\r
1446 }.should change(Panel, :count).by(-1)
\r
1448 r = Panel.find @panel.id
\r
1449 }.should raise_error
\r
1451 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1453 r = @panel.destroy_with_elements
\r
1454 }.should change(PanelPicture, :count).by(-1)
\r
1456 r = PanelPicture.find @pp.id
\r
1457 }.should raise_error
\r
1459 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1461 r = @panel.destroy_with_elements
\r
1462 }.should change(GroundPicture, :count).by(-1)
\r
1464 r = GroundPicture.find @gp.id
\r
1465 }.should raise_error
\r
1468 r = @panel.destroy_with_elements
\r
1472 context '削除に失敗したとき' do
\r
1474 PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
\r
1477 r = @panel.destroy_with_elements
\r
1480 it 'ロールバックしている' do
\r
1482 r = @panel.destroy_with_elements
\r
1483 }.should_not change(Panel, :count)
\r
1485 r = @panel.destroy_with_elements
\r
1486 }.should_not change(PanelPicture, :count)
\r
1491 describe 'id挿げ替え防止確認に於いて' do
\r
1494 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1495 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1496 @sb = @panel.speech_balloons.create(
\r
1497 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1499 @gc = @panel.ground_colors.create(
\r
1500 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
1502 @gp = @panel.ground_pictures.create(
\r
1503 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1505 @pc = @panel.panel_colors.create(
\r
1506 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
1510 it 'author,コマ要素を含んでいる' do
\r
1511 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
\r
1512 @panel2.panel_pictures.create(
\r
1513 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height)
\r
1518 describe 'id一致チェックに於いて' do
\r
1519 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
1520 context '親が既存(idが数値)のとき' do
\r
1521 it 'すべてid一致するときTrueを返す' do
\r
1522 r = Panel.validate_id [1, 1, 1, 1], 1
\r
1525 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
1526 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
1529 it 'すべて数値でも一致しないときFalseを返す' do
\r
1530 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
1533 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
1534 r = Panel.validate_id [1, 1, nil, 2], 1
\r
1538 context '親が新規(idがNil)のとき' do
\r
1539 it 'すべてNilはTrueを返す' do
\r
1540 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
1543 it 'すべてnilでなければFalseを返す' do
\r
1544 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
1549 describe 'idチェック単体に於いて' do
\r
1551 # @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1
\r
1553 context 'つつがなく終わるとき' do
\r
1554 it 'idを収集依頼している' do
\r
1555 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1556 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1557 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1558 r = Panel.validate_element_id [], :panel_id, nil
\r
1560 it '収集したidを一致チェック依頼している' do
\r
1561 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
1562 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1563 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1564 r = Panel.validate_element_id [], :panel_id, nil
\r
1568 #依頼チェックだけでは不安なので最低限のチェックを
\r
1569 context 'コマ新規のとき' do
\r
1570 it 'コマ絵で正常通過している' do
\r
1571 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1572 @panel.panel_pictures.build(
\r
1573 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1575 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1578 it 'フキダシで正常通過している' do
\r
1579 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1580 @panel.speech_balloons.build(
\r
1581 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1583 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1587 context 'コマ既存のとき' do
\r
1588 it 'コマ絵で正常通過している' do
\r
1589 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1590 @panel.panel_pictures.build(
\r
1591 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1593 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1596 it 'フキダシで正常通過している' do
\r
1597 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1598 @panel.speech_balloons.build(
\r
1599 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1601 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1605 context 'フキダシ新規のとき' do
\r
1606 it 'バルーンで正常通過している' do
\r
1607 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1608 @panel.speech_balloons.build(
\r
1609 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1611 @panel.speech_balloons.first.balloons.build(
\r
1612 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1614 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1617 it 'セリフで正常通過している' do
\r
1618 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1619 @panel.speech_balloons.build(
\r
1620 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1622 @panel.speech_balloons.first.speeches.build(
\r
1623 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1625 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1630 describe 'idチェックリスト生成に於いて' do
\r
1632 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1634 context 'つつがなく終わるとき' do
\r
1635 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
1636 @panel.panel_pictures.build(
\r
1637 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1639 @panel.speech_balloons.build(
\r
1640 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1642 @panel.speech_balloons.first.balloons.build(
\r
1643 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1645 @panel.speech_balloons.first.speeches.build(
\r
1646 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1648 r = @panel.validate_id_list
\r
1649 r.should have(2).items
\r
1651 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
1652 @panel.panel_pictures.build(
\r
1653 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1655 sb1 = @panel.speech_balloons.build(
\r
1656 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1658 sb1.balloons.build(
\r
1659 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1661 sb1.speeches.build(
\r
1662 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1664 sb2 = @panel.speech_balloons.build(
\r
1665 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1667 sb2.balloons.build(
\r
1668 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1670 sb2.speeches.build(
\r
1671 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1673 r = @panel.validate_id_list
\r
1674 r.should have(3).items
\r
1678 describe 'idチェック複合に於いて' do
\r
1680 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1682 context 'つつがなく終わるとき' do
\r
1683 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
1684 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
1685 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
1686 @panel.panel_pictures.build(
\r
1687 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1689 sb1 = @panel.speech_balloons.build(
\r
1690 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1692 sb1.balloons.build(
\r
1693 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1695 sb1.speeches.build(
\r
1696 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1698 r = Panel.validate_elements_id(@panel.validate_id_list)
\r