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
35 @panel.should be_valid
\r
38 @panel.width = 99999
\r
39 @panel.height = 99999
\r
40 @panel.border = 99999
\r
41 @panel.publish = 99999
\r
42 @panel.should be_valid
\r
46 context 'widthを検証するとき' do
\r
49 @panel.should_not be_valid
\r
53 @panel.should_not be_valid
\r
57 @panel.should_not be_valid
\r
61 @panel.should_not be_valid
\r
64 context 'heightを検証するとき' do
\r
67 @panel.should_not be_valid
\r
71 @panel.should_not be_valid
\r
75 @panel.should_not be_valid
\r
79 @panel.should_not be_valid
\r
82 context 'borderを検証するとき' do
\r
85 @panel.should_not be_valid
\r
89 @panel.should_not be_valid
\r
92 @panel.border = '-1'
\r
93 @panel.should_not be_valid
\r
97 @panel.should be_valid
\r
100 context 'author_idを検証するとき' do
\r
102 @panel.author_id = nil
\r
103 @panel.should_not be_valid
\r
105 it '数値でなければ失敗する' do
\r
106 @panel.author_id = 'a'
\r
107 @panel.should_not be_valid
\r
109 it '存在する作家でなければ失敗する' do
\r
110 @panel.author_id = 0
\r
111 @panel.should_not be_valid
\r
114 context '公開フラグを検証するとき' do
\r
115 it '数値でなければ失敗する' do
\r
116 @panel.publish = 'a'
\r
117 @panel.should_not be_valid
\r
120 context '全体を検証するとき' do
\r
122 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
127 describe '文字コード検証に於いて' do
\r
129 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
132 context 'captionを検証するとき' do
\r
133 it 'Shift JISなら失敗する' do
\r
134 @panel.caption = "\x83G\x83r\x83]\x83D"
\r
136 @panel.valid_encode
\r
137 }.should raise_error(Pettanr::BadRequest)
\r
143 describe 'デフォルト値補充に於いて' do
\r
145 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
147 it 'borderは2を補充する' do
\r
148 @panel.border = nil
\r
149 @panel.supply_default
\r
150 @panel.border.should eq 2
\r
152 it 'publishは0を補充する' do
\r
153 @panel.publish = nil
\r
154 @panel.supply_default
\r
155 @panel.publish.should eq 0
\r
159 describe '上書き補充に於いて' do
\r
161 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
163 context 'author_idを補充' do
\r
164 it 'ログイン中の作家idを補充する' do
\r
165 @panel.author_id = nil
\r
166 @panel.overwrite @author
\r
167 @panel.author_id.should eq @author.id
\r
173 describe '所持判定に於いて' do
\r
175 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
177 context '事前チェックする' do
\r
178 it '自身にロールリストからの作家取得を依頼している' do
\r
179 Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
\r
180 r = @panel.own?([@author])
\r
183 context 'ロール内作家が取得できるとき' do
\r
186 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
\r
187 Panel.stub(:get_author_from_roles).with(any_args).and_return(@author)
\r
188 r = @panel.own?([@author])
\r
191 it 'ロール内作家のidが自身の作家idと一致しないならno' do
\r
192 Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
\r
193 @panel.own?(@other_author).should be_false
\r
196 context 'ロール内作家が取得できないとき' do
\r
198 Panel.stub(:get_author_from_roles).with(any_args).and_return(nil)
\r
201 r = @panel.own?([@author])
\r
207 describe '閲覧許可に於いて' do
\r
209 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
\r
210 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
211 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
\r
213 context 'オープンモードのとき' do
\r
215 MagicNumber['run_mode'] = 0
\r
217 it '自身にゲスト用ロールチェックを問い合わせしている' do
\r
218 Panel.any_instance.stub(:guest_role_check).and_return(true)
\r
219 Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
\r
220 r = @panel.visible?([@author])
\r
222 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
\r
223 Panel.any_instance.stub(:guest_role_check).and_return(false)
\r
224 r = @panel.visible?([@author])
\r
228 context 'クローズドモードのとき' do
\r
230 MagicNumber['run_mode'] = 1
\r
232 it '自身に読者用ロールチェックを問い合わせしている' do
\r
233 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
234 Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
\r
235 r = @panel.visible?([@author])
\r
237 it '読者用ロールチェックが失敗したとき、falseを返す' do
\r
238 Panel.any_instance.stub(:reader_role_check).and_return(false)
\r
239 r = @panel.visible?([@author])
\r
243 context '事前チェックする' do
\r
245 MagicNumber['run_mode'] = 1
\r
246 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
248 it '自身に所持判定を問い合わせしている' do
\r
249 Panel.any_instance.stub(:own?).and_return(true)
\r
250 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
251 r = @panel.visible?([@author])
\r
253 it '自身に閲覧許可を問い合わせしている' do
\r
254 Panel.any_instance.stub(:own?).and_return(false)
\r
255 Panel.any_instance.stub(:publish?).and_return(true)
\r
256 Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1)
\r
257 r = @panel.visible?([@author])
\r
260 context 'つつがなく終わるとき' do
\r
262 MagicNumber['run_mode'] = 1
\r
263 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
265 it '自分のコマなら許可する' do
\r
266 Panel.any_instance.stub(:own?).and_return(true)
\r
267 Panel.any_instance.stub(:publish?).and_return(false)
\r
268 r = @panel.visible?([@author])
\r
271 it '他人の非公開コマなら許可しない' do
\r
272 Panel.any_instance.stub(:own?).and_return(false)
\r
273 Panel.any_instance.stub(:publish?).and_return(false)
\r
274 r = @panel.visible?([@author])
\r
277 it '他人のコマでも公開なら許可する' do
\r
278 Panel.any_instance.stub(:own?).and_return(false)
\r
279 Panel.any_instance.stub(:publish?).and_return(true)
\r
280 r = @panel.visible?([@author])
\r
286 describe '一覧取得に於いて' do
\r
288 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
290 context 'page補正について' do
\r
291 it '文字列から数値に変換される' do
\r
292 Panel.page('8').should eq 8
\r
294 it 'nilの場合は1になる' do
\r
295 Panel.page().should eq 1
\r
297 it '0以下の場合は1になる' do
\r
298 Panel.page('0').should eq 1
\r
301 context 'page_size補正について' do
\r
302 it '文字列から数値に変換される' do
\r
303 Panel.page_size('7').should eq 7
\r
305 it 'nilの場合はPanel.default_page_sizeになる' do
\r
306 Panel.page_size().should eq Panel.default_page_size
\r
308 it '0以下の場合はPanel.default_page_sizeになる' do
\r
309 Panel.page_size('0').should eq Panel.default_page_size
\r
311 it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do
\r
312 Panel.page_size('1000').should eq Panel.max_page_size
\r
317 r.should eq [@panel]
\r
320 #公開コミックは(他人のコミックであっても)含んでいる
\r
321 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
323 r.should eq [npl, @panel]
\r
325 it '非公開のコマ(自分のコマであっても)は含まない' do
\r
326 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
328 r.should eq [@panel]
\r
330 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
332 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
333 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
334 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
335 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
336 Panel.stub(:default_page_size).and_return(2)
\r
340 pl.should have(2).items
\r
342 it 'page=1なら末尾2件を返す' do
\r
345 pl.should eq [@npl5, @npl4]
\r
347 it 'page=2なら中間2件を返す' do
\r
349 pl.should eq [@npl3, @npl2]
\r
351 it 'page=3なら先頭1件を返す' do
\r
353 pl.should eq [@panel]
\r
358 describe '自分のコマ一覧取得に於いて' do
\r
360 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
363 pl = Panel.mylist @author
\r
364 pl.should eq [@panel]
\r
367 npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
368 pl = Panel.mylist @author
\r
369 pl.should eq [npl, @panel]
\r
371 it '他人のコマは公開でも含まない' do
\r
372 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
373 pl = Panel.mylist @author
\r
374 pl.should eq [@panel]
\r
376 it '自分のコマは非公開でも含んでいる' do
\r
377 npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100
\r
378 pl = Panel.mylist @author
\r
379 pl.should eq [npl, @panel]
\r
381 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
383 @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100
\r
384 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200
\r
385 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300
\r
386 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400
\r
389 pl = Panel.mylist @author, 1, 2
\r
390 pl.should have(2).items
\r
392 it 'page=1なら末尾2件を返す' do
\r
394 pl = Panel.mylist @author, 1, 2
\r
395 pl.should eq [@npl5, @npl4]
\r
397 it 'page=2なら中間2件を返す' do
\r
398 pl = Panel.mylist @author, 2, 2
\r
399 pl.should eq [@npl3, @npl2]
\r
401 it 'page=3なら先頭1件を返す' do
\r
402 pl = Panel.mylist @author, 3, 2
\r
403 pl.should eq [@panel]
\r
408 describe '他作家のコマ一覧取得に於いて' do
\r
410 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
411 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
414 r = Panel.himlist @other_author
\r
415 r.should eq [@other_panel]
\r
418 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
419 r = Panel.himlist @other_author
\r
420 r.should eq [npl, @other_panel]
\r
423 npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
\r
424 r = Panel.himlist @other_author
\r
425 r.should eq [@other_panel]
\r
427 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
429 @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
\r
430 @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200
\r
431 @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300
\r
432 @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400
\r
435 pl = Panel.himlist @other_author, 1, 2
\r
436 pl.should have(2).items
\r
438 it 'page=1なら末尾2件を返す' do
\r
440 pl = Panel.himlist @other_author, 1, 2
\r
441 pl.should eq [@other_panel5, @other_panel4]
\r
443 it 'page=2なら中間2件を返す' do
\r
444 pl = Panel.himlist @other_author, 2, 2
\r
445 pl.should eq [@other_panel3, @other_panel2]
\r
447 it 'page=3なら先頭1件を返す' do
\r
448 pl = Panel.himlist @other_author, 3, 2
\r
449 pl.should eq [@other_panel]
\r
454 describe 'コマ一覧ページ制御に於いて' do
\r
456 Panel.stub(:count).with(any_args).and_return(100)
\r
459 r = Panel.list_paginate
\r
460 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
462 it 'コマ一覧の取得条件を利用している' do
\r
463 Panel.stub(:list_where).with(any_args).and_return('')
\r
464 Panel.should_receive(:list_where).with(any_args).exactly(1)
\r
465 r = Panel.list_paginate
\r
467 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
468 r = Panel.list_paginate 3, 10
\r
469 r.limit_value.should eq 10
\r
470 r.offset_value.should eq 20
\r
474 describe '自分のコマ一覧ページ制御に於いて' do
\r
476 Panel.stub(:count).with(any_args).and_return(100)
\r
479 r = Panel.mylist_paginate @author
\r
480 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
482 it '自分のコマ一覧の取得条件を利用している' do
\r
483 Panel.stub(:mylist_where).with(any_args).and_return('')
\r
484 Panel.should_receive(:mylist_where).with(any_args).exactly(1)
\r
485 r = Panel.mylist_paginate @author
\r
487 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
488 r = Panel.mylist_paginate @author, 3, 10
\r
489 r.limit_value.should eq 10
\r
490 r.offset_value.should eq 20
\r
494 describe '他作家のコマ一覧ページ制御に於いて' do
\r
496 Panel.stub(:count).with(any_args).and_return(100)
\r
499 r = Panel.himlist_paginate @other_author
\r
500 r.is_a?(Kaminari::PaginatableArray).should be_true
\r
502 it '他作家のコマ一覧の取得条件を利用している' do
\r
503 Panel.stub(:himlist_where).with(any_args).and_return('')
\r
504 Panel.should_receive(:himlist_where).with(any_args).exactly(1)
\r
505 r = Panel.himlist_paginate @other_author
\r
507 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
\r
508 r = Panel.himlist_paginate @other_author, 3, 10
\r
509 r.limit_value.should eq 10
\r
510 r.offset_value.should eq 20
\r
514 describe '一覧取得オプションに於いて' do
\r
515 it '5つの項目を含んでいる' do
\r
517 r.should have(5).items
\r
521 r.has_key?(:panel_pictures).should be_true
\r
523 it 'コマ絵は実素材を含んでいる' do
\r
525 r[:panel_pictures].has_key?(:picture).should be_true
\r
527 it '実素材は絵師を含んでいる' do
\r
529 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
531 it '実素材はライセンスを含んでいる' do
\r
533 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
537 r.has_key?(:speech_balloons).should be_true
\r
539 it 'フキダシはフキダシ枠を含んでいる' do
\r
541 r[:speech_balloons].has_key?(:balloon).should be_true
\r
543 it 'フキダシはセリフを含んでいる' do
\r
545 r[:speech_balloons].has_key?(:speech).should be_true
\r
549 r.has_key?(:ground_pictures).should be_true
\r
551 it '絵地は実素材を含んでいる' do
\r
553 r[:ground_pictures].has_key?(:picture).should be_true
\r
555 it '実素材は絵師を含んでいる' do
\r
557 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
559 it '実素材はライセンスを含んでいる' do
\r
561 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
565 r.has_key?(:ground_colors).should be_true
\r
569 r.has_key?(:author).should be_true
\r
572 describe 'json一覧出力オプションに於いて' do
\r
575 describe '単体取得に於いて' do
\r
577 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
579 context 'つつがなく終わるとき' do
\r
580 it '単体取得オプションを利用している' do
\r
581 Panel.stub(:show_opt).with(any_args).and_return({})
\r
582 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
583 r = Panel.show @panel.id, @author
\r
585 it '閲覧許可を問い合わせている' do
\r
586 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
587 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
588 r = Panel.show @panel.id, @author
\r
592 Panel.any_instance.stub(:visible?).and_return(true)
\r
593 pl = Panel.show @panel.id, @author
\r
594 pl.should eq @panel
\r
596 context '閲覧許可が出なかったとき' do
\r
597 it '403Forbidden例外を返す' do
\r
598 Panel.any_instance.stub(:visible?).and_return(false)
\r
600 Panel.show @panel.id, @author
\r
601 }.should raise_error(ActiveRecord::Forbidden)
\r
604 context '存在しないコマを開こうとしたとき' do
\r
605 it '404RecordNotFound例外を返す' do
\r
607 Panel.show 110, @author
\r
608 }.should raise_error(ActiveRecord::RecordNotFound)
\r
612 describe '編集取得に於いて' do
\r
614 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
616 context 'つつがなく終わるとき' do
\r
617 it '単体取得オプションを利用している' do
\r
618 Panel.stub(:show_opt).with(any_args).and_return({})
\r
619 Panel.should_receive(:show_opt).with(any_args).exactly(1)
\r
620 r = Panel.edit @panel.id, @author
\r
622 it '所持判定を問い合わせている' do
\r
623 Panel.any_instance.stub(:own?).with(any_args).and_return(true)
\r
624 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
625 r = Panel.edit @panel.id, @author
\r
629 Panel.any_instance.stub(:own?).and_return(true)
\r
630 pl = Panel.edit @panel.id, @author
\r
631 pl.should eq @panel
\r
633 context '他人のコマを開こうとしたとき' do
\r
634 it '403Forbidden例外を返す' do
\r
635 Panel.any_instance.stub(:own?).and_return(false)
\r
637 Panel.edit @panel.id, @author
\r
638 }.should raise_error(ActiveRecord::Forbidden)
\r
641 context '存在しないコマを開こうとしたとき' do
\r
642 it '404RecordNotFound例外を返す' do
\r
644 Panel.edit 110, @author
\r
645 }.should raise_error(ActiveRecord::RecordNotFound)
\r
649 describe '単体取得オプションに於いて' do
\r
650 it 'includeキーを含んでいる' do
\r
652 r.has_key?(:include).should be_true
\r
654 it '5つの項目を含んでいる' do
\r
655 r = Panel.show_opt[:include]
\r
656 r.should have(5).items
\r
659 r = Panel.show_opt[:include]
\r
660 r.has_key?(:panel_pictures).should be_true
\r
662 it 'コマ絵は実素材を含んでいる' do
\r
663 r = Panel.show_opt[:include]
\r
664 r[:panel_pictures].has_key?(:picture).should be_true
\r
666 it '実素材は絵師を含んでいる' do
\r
667 r = Panel.show_opt[:include]
\r
668 r[:panel_pictures][:picture].has_key?(:artist).should be_true
\r
670 it '実素材はライセンスを含んでいる' do
\r
671 r = Panel.show_opt[:include]
\r
672 r[:panel_pictures][:picture].has_key?(:license).should be_true
\r
675 r = Panel.show_opt[:include]
\r
676 r.has_key?(:speech_balloons).should be_true
\r
678 it 'フキダシはフキダシ枠を含んでいる' do
\r
679 r = Panel.show_opt[:include]
\r
680 r[:speech_balloons].has_key?(:balloon).should be_true
\r
682 it 'フキダシはセリフを含んでいる' do
\r
683 r = Panel.show_opt[:include]
\r
684 r[:speech_balloons].has_key?(:speech).should be_true
\r
687 r = Panel.show_opt[:include]
\r
688 r.has_key?(:ground_pictures).should be_true
\r
690 it '絵地は実素材を含んでいる' do
\r
691 r = Panel.show_opt[:include]
\r
692 r[:ground_pictures].has_key?(:picture).should be_true
\r
694 it '実素材は絵師を含んでいる' do
\r
695 r = Panel.show_opt[:include]
\r
696 r[:ground_pictures][:picture].has_key?(:artist).should be_true
\r
698 it '実素材はライセンスを含んでいる' do
\r
699 r = Panel.show_opt[:include]
\r
700 r[:ground_pictures][:picture].has_key?(:license).should be_true
\r
703 r = Panel.show_opt[:include]
\r
704 r.has_key?(:ground_colors).should be_true
\r
707 r = Panel.show_opt[:include]
\r
708 r.has_key?(:author).should be_true
\r
711 describe 'json単体出力オプションに於いて' do
\r
713 describe 'コマ部品集合に於いて' do
\r
716 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
717 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
718 @sb = @panel.speech_balloons.build(
\r
719 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
722 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
725 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
729 @gc = @panel.ground_colors.create(
\r
730 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
732 @gp = @panel.ground_pictures.create(
\r
733 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
738 r = @panel.parts_element
\r
739 r.is_a?(Array).should be_true
\r
741 it 'コマ絵とフキダシと絵地と色地を合わせている' do
\r
742 r = @panel.parts_element
\r
743 r.include?(@pp).should be_true
\r
744 r.include?(@sb).should be_true
\r
745 r.include?(@gc).should be_true
\r
746 r.include?(@gp).should be_true
\r
750 describe 'z順コマ部品に於いて' do
\r
753 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
754 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :width => @p.width, :height => @p.height
\r
755 @sb = @panel.speech_balloons.build(
\r
756 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1)
\r
759 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
762 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
766 @gc = @panel.ground_colors.create(
\r
767 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3)
\r
769 @gp = @panel.ground_pictures.create(
\r
770 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4)
\r
774 context 'つつがなく終わるとき' do
\r
775 it 'コマ部品集合を利用している' do
\r
776 Panel.any_instance.stub(:parts_element).with(any_args).and_return([])
\r
777 Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)
\r
778 r = @panel.zorderd_elements
\r
782 r = @panel.zorderd_elements
\r
783 r.is_a?(Array).should be_true
\r
786 it 'zでオフセットを0でソートしている' do
\r
787 r = @panel.zorderd_elements
\r
793 context 'さらに末尾にフキダシを追加したとき' do
\r
795 @sb2 = @panel.speech_balloons.build(
\r
796 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5)
\r
798 @sb2.build_balloon(
\r
799 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
802 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
809 r = @panel.zorderd_elements
\r
814 r[4].should eq @sb2
\r
818 describe 'コマ要素に於いて' do
\r
821 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
822 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
823 @sb = @panel.speech_balloons.build(
\r
824 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
827 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
830 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
834 @gc = @panel.ground_colors.create(
\r
835 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
837 @gp = @panel.ground_pictures.create(
\r
838 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
842 context 'つつがなく終わるとき' do
\r
843 it 'コマ部品を利用している' do
\r
844 Panel.any_instance.stub(:parts_element).with(any_args).and_return([])
\r
845 Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)
\r
846 r = @panel.panel_elements
\r
850 r = @panel.panel_elements
\r
851 r.is_a?(Array).should be_true
\r
854 r = @panel.panel_elements
\r
860 context 'さらに末尾にフキダシを追加したとき' do
\r
862 @sb2 = @panel.speech_balloons.build(
\r
863 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)
\r
865 @sb2.build_balloon(
\r
866 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
869 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
876 r = @panel.panel_elements
\r
881 r[4].should eq @sb2
\r
885 describe 'コマ要素のjson出力に於いて' do
\r
888 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
889 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
890 @sb = @panel.speech_balloons.build(
\r
891 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
894 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
897 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
901 @gc = @panel.ground_colors.create(
\r
902 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
904 @gp = @panel.ground_pictures.create(
\r
905 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
909 context 'つつがなく終わるとき' do
\r
911 PanelPicture.stub(:json_opt_for_panel).and_return({})
\r
912 SpeechBalloon.stub(:json_opt_for_panel).and_return({})
\r
913 GroundPicture.stub(:json_opt_for_panel).and_return({})
\r
914 GroundColor.stub(:json_opt_for_panel).and_return({})
\r
916 it 'コマ絵にjson出力オプションを依頼している' do
\r
917 PanelPicture.should_receive(:json_opt_for_panel).exactly(1)
\r
918 r = @panel.elements
\r
920 it 'フキダシにjson出力オプションを依頼している' do
\r
921 SpeechBalloon.should_receive(:json_opt_for_panel).exactly(1)
\r
922 r = @panel.elements
\r
924 it '絵地にjson出力オプションを依頼している' do
\r
925 GroundPicture.should_receive(:json_opt_for_panel).exactly(1)
\r
926 r = @panel.elements
\r
928 it '色地にjson出力オプションを依頼している' do
\r
929 GroundColor.should_receive(:json_opt_for_panel).exactly(1)
\r
930 r = @panel.elements
\r
934 r = @panel.elements
\r
935 r.is_a?(Array).should be_true
\r
938 describe 'コマのjson出力に於いて' do
\r
941 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
942 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
943 @sb = @panel.speech_balloons.build(
\r
944 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
947 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
950 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
954 @gc = @panel.ground_colors.create(
\r
955 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
957 @gp = @panel.ground_pictures.create(
\r
958 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)
\r
962 context 'つつがなく終わるとき' do
\r
964 Panel.any_instance.stub(:elements).with(any_args).and_return({})
\r
966 it 'コマ要素のjson出力を依頼している' do
\r
967 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
968 r = @panel.panel_elements_as_json
\r
971 it 'json textを返している' do
\r
972 r = JSON.parse @panel.panel_elements_as_json
\r
973 r.is_a?(Hash).should be_true
\r
975 it 'author,コマ要素を含んでいる' do
\r
976 r = JSON.parse @panel.panel_elements_as_json
\r
977 r.has_key?('author').should be_true
\r
978 r.has_key?('elements').should be_true
\r
980 sb = r['elements'].first
\r
981 sb.has_key?('classname').should be_true
\r
982 sb.has_key?('balloon').should be_true
\r
983 sb.has_key?('speech').should be_true
\r
987 describe 'コマリストのjson出力に於いて' do
\r
989 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
990 Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}')
\r
992 context 'つつがなく終わるとき' do
\r
993 it 'コマのjson出力を依頼している' do
\r
994 Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1)
\r
995 r = Panel.list_as_json_text [@panel]
\r
998 it 'json textを返している' do
\r
999 r = Panel.list_as_json_text [@panel]
\r
1001 j.is_a?(Array).should be_true
\r
1004 r = Panel.list_as_json_text [@panel]
\r
1006 j.first.has_key?('p').should be_true
\r
1010 describe 'ライセンス素材に於いて' do
\r
1013 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
1014 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
\r
1015 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
\r
1016 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1017 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id
\r
1018 @sb = @panel.speech_balloons.build(
\r
1019 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1021 @sb.build_balloon(
\r
1022 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1025 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1029 @gc = @panel.ground_colors.create(
\r
1030 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)
\r
1032 @gp = @panel.ground_pictures.create(
\r
1033 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3)
\r
1037 context '事前チェック' do
\r
1039 context 'つつがなく終わるとき' do
\r
1041 it '連想配列(値は実素材、キーは実素材id)を返している' do
\r
1042 r = @panel.licensed_pictures
\r
1043 r.is_a?(Hash).should be_true
\r
1044 r.should have(2).items
\r
1045 r[@pp.picture_id].should eq @p
\r
1046 r[@gp.picture_id].should eq @p2
\r
1050 describe '検証値収集に於いて' do
\r
1051 context 'つつがなく終わるとき' do
\r
1052 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1053 elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}],
\r
1054 [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]
\r
1055 r = Panel.collect_element_value elements, :panel_id
\r
1056 r.should eq [1, 2, 3, 4]
\r
1058 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
\r
1059 elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}],
\r
1060 [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]]
\r
1061 r = Panel.collect_element_value elements, :t
\r
1062 r.should eq [1, 2, 3, 0]
\r
1066 describe 'シリアライズチェックに於いて' do
\r
1067 context 'つつがなく終わるとき' do
\r
1068 it '0からシリアライズされているならTrueを返す' do
\r
1069 r = Panel.validate_serial [0, 1, 2]
\r
1072 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1073 r = Panel.validate_serial [0, 2, 1]
\r
1076 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
\r
1077 r = Panel.validate_serial [ 2, 1, 4, 3, 0]
\r
1081 context 'オフセットが1のとき' do
\r
1082 it '0からシリアライズされているならFalseを返す' do
\r
1083 r = Panel.validate_serial [0, 1, 2], 1
\r
1086 it '1からシリアライズされているならTrueを返す' do
\r
1087 r = Panel.validate_serial [1, 2, 3], 1
\r
1091 context '異常なとき' do
\r
1092 it '0から始まらないならFalseを返す' do
\r
1093 r = Panel.validate_serial [1, 2, 3]
\r
1096 it '連続していないならFalseを返す' do
\r
1097 r = Panel.validate_serial [0, 1, 2, 4]
\r
1100 it '連続していないならFalseを返す' do
\r
1101 r = Panel.validate_serial [0, 1, 2, 4, 5]
\r
1106 describe 'シリアライズチェック単体に於いて' do
\r
1109 context 'つつがなく終わるとき' do
\r
1110 it '検証値収集を依頼している' do
\r
1111 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1112 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1113 Panel.stub(:validate_serial).with(any_args).and_return(true)
\r
1114 r = Panel.validate_element_serial [], :t
\r
1116 it 'シリアライズチェック依頼している' do
\r
1117 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1118 Panel.should_receive(:validate_serial).with(any_args).exactly(1)
\r
1119 Panel.stub(:validate_serial).with(any_args).and_return(true)
\r
1120 r = Panel.validate_element_serial [], :t
\r
1124 describe '従属データの検証に於いて' do
\r
1125 context 'つつがなく終わるとき' do
\r
1126 it 'trueを返している' do
\r
1127 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1128 @panel.panel_pictures.build(
\r
1129 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1131 @panel.panel_pictures.build(
\r
1132 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)
\r
1134 sb1 = @panel.speech_balloons.build(
\r
1135 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1137 sb1.build_balloon(
\r
1138 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1141 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1145 sb2 = @panel.speech_balloons.build(
\r
1146 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)
\r
1148 sb2.build_balloon(
\r
1149 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1152 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1156 @gc = @panel.ground_colors.build(
\r
1157 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1159 @gp = @panel.ground_pictures.build(
\r
1160 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1162 r = @panel.validate_child
\r
1166 context 'tシリアライズされていないとき' do
\r
1167 it 'falseを返している' do
\r
1168 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1169 @panel.panel_pictures.build(
\r
1170 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1172 @panel.panel_pictures.build(
\r
1173 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)
\r
1175 sb1 = @panel.speech_balloons.build(
\r
1176 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1178 sb1.build_balloon(
\r
1179 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1182 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1186 sb2 = @panel.speech_balloons.build(
\r
1187 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)
\r
1189 sb2.build_balloon(
\r
1190 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1193 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1197 @gc = @panel.ground_colors.build(
\r
1198 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1200 @gp = @panel.ground_pictures.build(
\r
1201 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1203 r = @panel.validate_child
\r
1207 context 'zシリアライズされていないとき' do
\r
1208 it 'falseを返している' do
\r
1209 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1210 @panel.panel_pictures.build(
\r
1211 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)
\r
1213 @panel.panel_pictures.build(
\r
1214 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 0+1)
\r
1216 sb1 = @panel.speech_balloons.build(
\r
1217 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)
\r
1219 sb1.build_balloon(
\r
1220 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1223 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1227 sb2 = @panel.speech_balloons.build(
\r
1228 FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)
\r
1230 sb2.build_balloon(
\r
1231 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1234 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1238 @gc = @panel.ground_colors.build(
\r
1239 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)
\r
1241 @gp = @panel.ground_pictures.build(
\r
1242 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)
\r
1244 r = @panel.validate_child
\r
1249 describe '保存に於いて' do
\r
1251 @attr = FactoryGirl.attributes_for :panel
\r
1252 @panel = Panel.new
\r
1253 @panel.supply_default
\r
1255 context 'つつがなく終わるとき' do
\r
1257 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1258 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1260 it 'コマモデルに上書き補充を依頼している' do
\r
1261 Panel.any_instance.should_receive(:overwrite).exactly(1)
\r
1262 r = @panel.store @attr, @author
\r
1265 Panel.any_instance.should_receive(:save).with(any_args).exactly(1)
\r
1266 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1267 r = @panel.store @attr, @author
\r
1269 it '従属データの検証を依頼している' do
\r
1270 Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1)
\r
1271 r = @panel.store @attr, @author
\r
1274 context 'つつがなく終わるとき' do
\r
1276 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1279 r = @panel.store @attr, @author
\r
1283 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1285 r = @panel.store @attr, @author
\r
1286 }.should change(Panel, :count)
\r
1289 context '不正なjsonデータのとき' do
\r
1292 it 'エラーメッセージがセットされている' do
\r
1293 r = @panel.store false, @author
\r
1294 @panel.errors[:base].should_not be_blank
\r
1297 context '従属データの検証に失敗したとき' do
\r
1299 Panel.any_instance.stub(:save).with(any_args).and_return(true)
\r
1300 Panel.any_instance.stub(:validate_child).with(any_args).and_return(false)
\r
1302 it 'エラーメッセージがセットされている' do
\r
1303 r = @panel.store @attr, @author
\r
1304 @panel.errors[:base].should_not be_blank
\r
1307 context 'カラム値がFalseしたとき' do
\r
1309 Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)
\r
1311 it 'エラーメッセージがセットされている' do
\r
1312 r = @panel.store false, @author
\r
1313 @panel.errors.should_not be_empty
\r
1318 describe '要素の検証に於いて' do
\r
1320 @panel = Panel.new
\r
1321 @panel.supply_default
\r
1322 @attr = FactoryGirl.attributes_for :panel
\r
1324 "speech_balloons_attributes" => {
\r
1326 "caption" => "大きな文字で","z" => "1","t" => "0",
\r
1327 "classname" => "CircleSpeechBalloon","speech_balloon_template_id" => @sbt.id,
\r
1328 "speech_attributes" => {
\r
1329 "content" => "カギッコ","x" => "20","y" => "20","width" => "-60","height" => "60",
\r
1330 "settings" => "","writing_format_id" => @writing_format.id
\r
1332 "balloon_attributes" => {
\r
1333 "r" => "247","x" => "293","y" => "-2","width" => "200","height" => "200",
\r
1334 "system_picture_id" => @sp.id,"settings" => ""
\r
1341 "panel_pictures_attributes" => {
\r
1343 "caption" => "司会","x" => "a","y" => "99","z" => "1","t" => "0",
\r
1344 "width" => "156","height" => "245","link" => "","picture_id" => @p.id
\r
1350 context 'フキダシの幅がマイナスで検証に失敗したとき' do
\r
1352 @attr.merge!(@sbattr)
\r
1354 it 'エラーメッセージがセットされている' do
\r
1355 r = @panel.store @attr, @author
\r
1357 @panel.errors.should_not be_empty
\r
1360 context 'コマ絵の横軸はアルファベットのため検証に失敗したとき' do
\r
1362 @attr.merge!(@ppattr)
\r
1364 it 'エラーメッセージがセットされている' do
\r
1365 r = @panel.store @attr, @author
\r
1367 @panel.errors.should_not be_empty
\r
1372 describe '削除に於いて' do
\r
1374 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
\r
1375 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
\r
1376 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1377 @sb = @panel.speech_balloons.build(
\r
1378 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1380 @sb.build_balloon(
\r
1381 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
1384 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
1388 @gc = @panel.ground_colors.create(
\r
1389 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
\r
1391 @gp = @panel.ground_pictures.create(
\r
1392 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1395 context 'つつがなく終わるとき' do
\r
1398 r = @panel.destroy_with_elements
\r
1399 }.should change(Panel, :count).by(-1)
\r
1401 r = Panel.find @panel.id
\r
1402 }.should raise_error
\r
1404 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1406 r = @panel.destroy_with_elements
\r
1407 }.should change(PanelPicture, :count).by(-1)
\r
1409 r = PanelPicture.find @pp.id
\r
1410 }.should raise_error
\r
1412 it '自身にリンクしているコマ要素をすべて削除する' do
\r
1414 r = @panel.destroy_with_elements
\r
1415 }.should change(GroundPicture, :count).by(-1)
\r
1417 r = GroundPicture.find @gp.id
\r
1418 }.should raise_error
\r
1421 r = @panel.destroy_with_elements
\r
1425 context '削除に失敗したとき' do
\r
1427 PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false)
\r
1430 r = @panel.destroy_with_elements
\r
1433 it 'ロールバックしている' do
\r
1435 r = @panel.destroy_with_elements
\r
1436 }.should_not change(Panel, :count)
\r
1438 r = @panel.destroy_with_elements
\r
1439 }.should_not change(PanelPicture, :count)
\r
1444 describe 'id挿げ替え防止確認に於いて' do
\r
1447 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1448 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
1449 @sb = @panel.speech_balloons.create(
\r
1450 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
1452 @gc = @panel.ground_colors.create(
\r
1453 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
1455 @gp = @panel.ground_pictures.create(
\r
1456 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
1458 @pc = @panel.panel_colors.create(
\r
1459 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
1463 it 'author,コマ要素を含んでいる' do
\r
1464 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
\r
1465 @panel2.panel_pictures.create(
\r
1466 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height)
\r
1471 describe 'id一致チェックに於いて' do
\r
1472 #parent.idがNilのときはすべてNil。数値のときは全一致
\r
1473 context '親が既存(idが数値)のとき' do
\r
1474 it 'すべてid一致するときTrueを返す' do
\r
1475 r = Panel.validate_id [1, 1, 1, 1], 1
\r
1478 it 'idが一致する中にNilが混じってもTrueを返す' do
\r
1479 r = Panel.validate_id [1, 1, 1, 1, nil], 1
\r
1482 it 'すべて数値でも一致しないときFalseを返す' do
\r
1483 r = Panel.validate_id [1, 1, 1, 1, 2], 1
\r
1486 it '数値とNilが混ざってもIDが一致しないときFalseを返す' do
\r
1487 r = Panel.validate_id [1, 1, nil, 2], 1
\r
1491 context '親が新規(idがNil)のとき' do
\r
1492 it 'すべてNilはTrueを返す' do
\r
1493 r = Panel.validate_id [ nil,nil,nil,nil], nil
\r
1496 it 'すべてnilでなければFalseを返す' do
\r
1497 r = Panel.validate_id [nil,nil,nil,nil, 2], nil
\r
1502 describe 'idチェック単体に於いて' do
\r
1504 # @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1
\r
1506 context 'つつがなく終わるとき' do
\r
1507 it 'idを収集依頼している' do
\r
1508 Panel.should_receive(:collect_element_value).with(any_args).exactly(1)
\r
1509 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1510 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1511 r = Panel.validate_element_id [], :panel_id, nil
\r
1513 it '収集したidを一致チェック依頼している' do
\r
1514 Panel.should_receive(:validate_id).with(any_args).exactly(1)
\r
1515 Panel.stub(:collect_element_value).with(any_args).and_return([])
\r
1516 Panel.stub(:validate_id).with(any_args).and_return(true)
\r
1517 r = Panel.validate_element_id [], :panel_id, nil
\r
1521 #依頼チェックだけでは不安なので最低限のチェックを
\r
1522 context 'コマ新規のとき' do
\r
1523 it 'コマ絵で正常通過している' do
\r
1524 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1525 @panel.panel_pictures.build(
\r
1526 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1528 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1531 it 'フキダシで正常通過している' do
\r
1532 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1533 @panel.speech_balloons.build(
\r
1534 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1536 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1540 context 'コマ既存のとき' do
\r
1541 it 'コマ絵で正常通過している' do
\r
1542 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1543 @panel.panel_pictures.build(
\r
1544 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1546 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1549 it 'フキダシで正常通過している' do
\r
1550 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
1551 @panel.speech_balloons.build(
\r
1552 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1554 r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id
\r
1558 context 'フキダシ新規のとき' do
\r
1559 it 'バルーンで正常通過している' do
\r
1560 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1561 @panel.speech_balloons.build(
\r
1562 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1564 @panel.speech_balloons.first.balloons.build(
\r
1565 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1567 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1570 it 'セリフで正常通過している' do
\r
1571 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1572 @panel.speech_balloons.build(
\r
1573 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1575 @panel.speech_balloons.first.speeches.build(
\r
1576 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1578 r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id
\r
1583 describe 'idチェックリスト生成に於いて' do
\r
1585 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1587 context 'つつがなく終わるとき' do
\r
1588 it 'コマ部品とフキダシ部品のトータル2を返す' do
\r
1589 @panel.panel_pictures.build(
\r
1590 FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)
\r
1592 @panel.speech_balloons.build(
\r
1593 FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)
\r
1595 @panel.speech_balloons.first.balloons.build(
\r
1596 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)
\r
1598 @panel.speech_balloons.first.speeches.build(
\r
1599 FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)
\r
1601 r = @panel.validate_id_list
\r
1602 r.should have(2).items
\r
1604 it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do
\r
1605 @panel.panel_pictures.build(
\r
1606 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1608 sb1 = @panel.speech_balloons.build(
\r
1609 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1611 sb1.balloons.build(
\r
1612 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1614 sb1.speeches.build(
\r
1615 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1617 sb2 = @panel.speech_balloons.build(
\r
1618 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1620 sb2.balloons.build(
\r
1621 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)
\r
1623 sb2.speeches.build(
\r
1624 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)
\r
1626 r = @panel.validate_id_list
\r
1627 r.should have(3).items
\r
1631 describe 'idチェック複合に於いて' do
\r
1633 @panel = FactoryGirl.build :panel, :author_id => @author.id
\r
1635 context 'つつがなく終わるとき' do
\r
1636 it 'コマ部品とフキダシ部品の二回チェック依頼している' do
\r
1637 Panel.should_receive(:validate_element_id).with(any_args).exactly(2)
\r
1638 Panel.stub(:validate_element_id).with(any_args).and_return(true)
\r
1639 @panel.panel_pictures.build(
\r
1640 FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)
\r
1642 sb1 = @panel.speech_balloons.build(
\r
1643 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)
\r
1645 sb1.balloons.build(
\r
1646 FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)
\r
1648 sb1.speeches.build(
\r
1649 FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)
\r
1651 r = Panel.validate_elements_id(@panel.validate_id_list)
\r