1 # -*- encoding: utf-8 -*-
9 SpeechBalloonTemplate.delete_all
10 @admin = FactoryGirl.create :admin
11 @demand_user = FactoryGirl.create :demand_user
12 @sp = FactoryGirl.create :system_picture
13 @lg = FactoryGirl.create :license_group
14 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
15 @user = FactoryGirl.create( :user_yas)
16 @author = FactoryGirl.create :author, :user_id => @user.id
17 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
18 @other_user = FactoryGirl.create( :user_yas)
19 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
20 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
23 describe 'ペタナイズに於いて' do
24 it 'スクコマを閉じるためのバインダーである' do
25 expect(@item.is_a?(Peta::Binder)).to be true
27 it 'ブースト特筆すべき注意事項はない' do
28 expect(self.class.my_peta.boost.keys).to be true
41 describe 'マニフェストに於いて' do
42 context 'オーソドックスなデータのとき' do
43 it 'スクコマを閉じるためのバインダーである' do
44 expect(@item.is_a?(Peta::Binder)).to be true
46 it 'ブースト特筆すべき注意事項はない' do
47 expect(self.class.my_peta.boost.keys).to be true
53 describe 'ローカルマニフェストに於いて' do
55 it 'スクコマを閉じるためのバインダーである' do
56 expect(@item.is_a?(Peta::Binder)).to be true
58 it 'ブースト特筆すべき注意事項はない' do
59 expect(self.class.my_peta.boost.keys).to be true
67 @scroll = FactoryGirl.build :scroll, :author_id => @author.id
70 context 'オーソドックスなデータのとき' do
74 @scroll.should be_valid
77 @scroll.title = 'a'*100
79 @scroll.should be_valid
83 context 'titleを検証するとき' do
86 @scroll.should_not be_valid
89 @scroll.title = 'a'*101
90 @scroll.should_not be_valid
93 context 'visibleを検証するとき' do
96 @scroll.should_not be_valid
100 @scroll.should_not be_valid
104 @scroll.should_not be_valid
108 context 'author_idを検証するとき' do
110 @scroll.author_id = nil
111 @scroll.should_not be_valid
114 @scroll.author_id = 'a'
115 @scroll.should_not be_valid
117 it '存在する作家でなければ失敗する' do
118 @scroll.author_id = 0
119 @scroll.should_not be_valid
124 describe '文字コード検証に於いて' do
126 @scroll = FactoryGirl.build :scroll, :author_id => @author.id
129 context 'titleを検証するとき' do
130 it 'Shift JISなら失敗する' do
131 @scroll.title = "\x83G\x83r\x83]\x83D"
134 }.should raise_error(Pettanr::BadRequest)
138 context 'descriptionを検証するとき' do
139 it 'Shift JISなら失敗する' do
140 @scroll.description = "\x83G\x83r\x83]\x83D"
143 }.should raise_error(Pettanr::BadRequest)
148 describe 'デフォルト値補充に於いて' do
149 it 'visibleが0になっている' do
150 @scroll = FactoryGirl.build :scroll, :visible => nil
151 @scroll.supply_default
152 @scroll.visible.should eq 0
156 describe '上書き補充に於いて' do
158 @scroll = FactoryGirl.build :scroll, :author_id => nil
159 @scroll.overwrite @author
160 @scroll.author_id.should eq @author.id
164 describe 'ロールリストからの作家取得に於いて' do
165 context 'ロールがユーザのとき' do
166 it 'ユーザから作家を取得して、それを返す' do
167 r = Scroll.get_author_from_roles([@user])
171 context 'ロールが作家のとき' do
173 r = Scroll.get_author_from_roles([@author])
177 context 'ロールが絵師のとき' do
178 it '絵師から作家を取得できれば、それをを返す' do
179 r = Scroll.get_author_from_roles([@artist])
182 it '絵師から作家を取得できないときnilを返す' do
183 @artist.author_id = nil
185 r = Scroll.get_author_from_roles([@artist])
189 context 'ロールが管理者のとき' do
191 r = Scroll.get_author_from_roles([@admin])
197 describe 'ロールリストからの絵師取得に於いて' do
198 context 'ロールがユーザのとき' do
199 it 'ユーザから作家を取得して、そこから絵師を取得できれば、それを返す' do
200 r = Scroll.get_artist_from_roles([@user])
203 it '作家から絵師を取得できないときnilを返す' do
204 @artist.author_id = nil
206 r = Scroll.get_artist_from_roles([@user])
210 context 'ロールが作家のとき' do
211 it 'そこから絵師を取得できれば、それを返す' do
212 r = Scroll.get_artist_from_roles([@author])
215 it '作家から絵師を取得できないときnilを返す' do
216 @artist.author_id = nil
218 r = Scroll.get_artist_from_roles([@author])
222 context 'ロールが絵師のとき' do
224 r = Scroll.get_artist_from_roles([@artist])
228 context 'ロールが管理者のとき' do
230 r = Scroll.get_artist_from_roles([@admin])
236 describe '所持判定に於いて' do
238 @scroll = FactoryGirl.build :scroll, :author_id => @author.id
240 context '事前チェックする' do
241 it '自身にロールリストからの作家取得を依頼している' do
242 Scroll.should_receive(:get_author_from_roles).with(any_args).exactly(1)
243 r = @scroll.own?([@author])
246 context 'ロール内作家が取得できるとき' do
249 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
250 Scroll.stub(:get_author_from_roles).with(any_args).and_return(@author)
251 r = @scroll.own?([@author])
254 it 'ロール内作家のidが自身の作家idと一致しないならno' do
255 Scroll.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
256 @scroll.own?(@other_author).should be_false
259 context 'ロール内作家が取得できないとき' do
261 Scroll.stub(:get_author_from_roles).with(any_args).and_return(nil)
264 r = @scroll.own?([@author])
270 describe '読者用ロールチェックに於いて' do
272 @scroll = FactoryGirl.build :scroll, :author_id => @author.id
274 context 'ロールリストに作家が含まれるとき' do
275 it 'ロールリストがリストではないとき、リストにする trueを返す' do
276 r = @scroll.reader_role_check(@author)
280 r = @scroll.reader_role_check([@author])
284 context 'ロールリストに絵師が含まれるとき' do
286 r = @scroll.reader_role_check([@artist])
290 context 'ロールリストにユーザが含まれるとき' do
292 r = @scroll.reader_role_check([@user])
296 context 'ロールリストに管理者が含まれるとき' do
298 r = @scroll.reader_role_check([@admin])
302 context 'ロールリストにユーザ、管理者、作家、絵師が含まれないとき' do
304 r = @scroll.reader_role_check([nil])
310 describe '素材読者用ロールチェックに於いて' do
312 @scroll = FactoryGirl.build :scroll, :author_id => @author.id
314 context 'ロールリストに作家が含まれるとき' do
315 it 'ロールリストがリストではないとき、リストにする trueを返す' do
316 r = @scroll.resource_reader_role_check(@author)
320 r = @scroll.resource_reader_role_check([@author])
324 context 'ロールリストに絵師が含まれるとき' do
326 r = @scroll.resource_reader_role_check([@artist])
330 context 'ロールリストにユーザが含まれるとき' do
332 r = @scroll.resource_reader_role_check([@user])
336 context 'ロールリストに管理者が含まれるとき' do
338 r = @scroll.resource_reader_role_check([@admin])
342 context 'ロールリストに借手が含まれるとき' do
344 r = @scroll.resource_reader_role_check([@demand_user])
348 context 'ロールリストにユーザ、管理者、作家、絵師、借手が含まれないとき' do
350 r = @scroll.resource_reader_role_check([nil])
356 describe '閲覧許可に於いて' do
358 @scroll = FactoryGirl.build :scroll, :author_id => @author.id
360 context 'オープンモードのとき' do
362 MagicNumber['run_mode'] = 0
364 it '自身にゲスト用ロールチェックを問い合わせしている' do
365 Scroll.any_instance.stub(:guest_role_check).and_return(true)
366 Scroll.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
367 r = @scroll.visible?([@author])
369 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
370 Scroll.any_instance.stub(:guest_role_check).and_return(false)
371 r = @scroll.visible?([@author])
375 context 'クローズドモードのとき' do
377 MagicNumber['run_mode'] = 1
379 it '自身に読者用ロールチェックを問い合わせしている' do
380 Scroll.any_instance.stub(:reader_role_check).and_return(true)
381 Scroll.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
382 r = @scroll.visible?([@author])
384 it '読者用ロールチェックが失敗したとき、falseを返す' do
385 Scroll.any_instance.stub(:reader_role_check).and_return(false)
386 r = @scroll.visible?([@author])
390 context '事前チェックする' do
392 MagicNumber['run_mode'] = 1
393 Scroll.any_instance.stub(:reader_role_check).and_return(true)
394 Scroll.any_instance.stub(:own?).and_return(true)
396 it '自身に所持判定を問い合わせしている' do
397 Scroll.any_instance.should_receive(:own?).with(any_args).exactly(1)
398 r = @scroll.visible?([@author])
401 context 'つつがなく終わるとき' do
403 MagicNumber['run_mode'] = 1
404 Scroll.any_instance.stub(:reader_role_check).and_return(true)
406 it '自分のスクロールなら許可する' do
407 Scroll.any_instance.stub(:own?).and_return(true)
408 Scroll.any_instance.stub(:visible).and_return(0)
409 r = @scroll.visible?([@author])
412 it '他人の非公開スクロールなら許可しない' do
413 Scroll.any_instance.stub(:own?).and_return(false)
414 Scroll.any_instance.stub(:visible).and_return(0)
415 r = @scroll.visible?([@author])
418 it '他人のスクロールでも公開なら許可する' do
419 Scroll.any_instance.stub(:own?).and_return(false)
420 Scroll.any_instance.stub(:visible).and_return(1)
421 r = @scroll.visible?([@author])
427 describe '一覧取得に於いて' do
429 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
431 context 'page補正について' do
432 it '文字列から数値に変換される' do
433 Scroll.page('8').should eq 8
436 Scroll.page().should eq 1
439 Scroll.page('0').should eq 1
442 context 'page_size補正について' do
443 it '文字列から数値に変換される' do
444 Scroll.page_size('7').should eq 7
446 it 'nilの場合はScroll.default_page_sizeになる' do
447 Scroll.page_size().should eq Scroll.default_page_size
449 it '0以下の場合はScroll.default_page_sizeになる' do
450 Scroll.page_size('0').should eq Scroll.default_page_size
452 it 'Scroll.max_page_sizeを超えた場合はScroll.max_page_sizeになる' do
453 Scroll.page_size('1000').should eq Scroll.max_page_size
456 context 'つつがなく終わるとき' do
457 it '一覧取得オプションを利用している' do
458 Scroll.stub(:list_opt).with(any_args).and_return({})
459 Scroll.should_receive(:list_opt).with(any_args).exactly(1)
465 c.should eq [@scroll]
467 it '非公開スクロールは(自分のスクロールであっても)含んでいない' do
468 FactoryGirl.create :scroll, :author_id => @author.id, :visible => 0
470 c.should eq [@scroll]
473 #公開スクロールは(他人のスクロールであっても)含んでいる
474 v = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 100
476 c.should eq [v, @scroll]
478 context 'DBに5件あって1ページの件数を2件に変えたとして' do
480 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 100
481 @scroll3 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 200
482 @scroll4 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 300
483 @scroll5 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 400
484 Scroll.stub(:default_page_size).and_return(2)
488 c.should have(2).items
490 it 'page=1なら末尾2件を返す' do
493 c.should eq [@scroll5, @scroll4]
495 it 'page=2なら中間2件を返す' do
497 c.should eq [@scroll3, @scroll2]
499 it 'page=3なら先頭1件を返す' do
501 c.should eq [@scroll]
506 describe '自分のスクロール一覧取得に於いて' do
508 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
510 context 'つつがなく終わるとき' do
511 it '一覧取得オプションを利用している' do
512 Scroll.stub(:list_opt).with(any_args).and_return({})
513 Scroll.should_receive(:list_opt).with(any_args).exactly(1)
514 r = Scroll.mylist @author
518 c = Scroll.mylist @author
519 c.should eq [@scroll]
522 nc = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 100
523 cl = Scroll.mylist @author
524 cl.should eq [nc, @scroll]
526 it '他人のスクロールは公開でも含まない' do
527 nc = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
528 cl = Scroll.mylist @author
529 cl.should eq [@scroll]
531 it '自分のスクロールは非公開でも含んでいる' do
532 nc = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
533 cl = Scroll.mylist @author
534 cl.should eq [nc, @scroll]
536 context 'DBに5件あって1ページの件数を2件に変えたとして' do
538 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 100
539 @scroll3 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 200
540 @scroll4 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 300
541 @scroll5 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 400
544 c = Scroll.mylist @author, 1, 2
545 c.should have(2).items
547 it 'page=1なら末尾2件を返す' do
549 c = Scroll.mylist(@author, 1, 2)
550 c.should eq [@scroll5, @scroll4]
552 it 'page=2なら中間2件を返す' do
553 c = Scroll.mylist(@author, 2, 2)
554 c.should eq [@scroll3, @scroll2]
556 it 'page=3なら先頭1件を返す' do
557 c = Scroll.mylist(@author, 3, 2)
558 c.should eq [@scroll]
563 describe '他作家のスクロール一覧取得に於いて' do
565 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
566 @other_scroll = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
568 context 'つつがなく終わるとき' do
569 it '一覧取得オプションを利用している' do
570 Scroll.stub(:list_opt).with(any_args).and_return({})
571 Scroll.should_receive(:list_opt).with(any_args).exactly(1)
572 r = Scroll.himlist @other_author
575 it '指定した作家のリストを返す' do
576 r = Scroll.himlist @other_author
577 r.should eq [@other_scroll]
580 nc = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 100
581 r = Scroll.himlist @other_author
582 r.should eq [nc, @other_scroll]
585 hidden = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 0
586 r = Scroll.himlist @other_author
587 r.should eq [@other_scroll]
589 context 'DBに5件あって1ページの件数を2件に変えたとして' do
591 @other_scroll2 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 100
592 @other_scroll3 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 200
593 @other_scroll4 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 300
594 @other_scroll5 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 400
597 c = Scroll.himlist @other_author, 1, 2
598 c.should have(2).items
600 it 'page=1なら末尾2件を返す' do
602 c = Scroll.himlist(@other_author, 1, 2)
603 c.should eq [@other_scroll5, @other_scroll4]
605 it 'page=2なら中間2件を返す' do
606 c = Scroll.himlist(@other_author, 2, 2)
607 c.should eq [@other_scroll3, @other_scroll2]
609 it 'page=3なら先頭1件を返す' do
610 c = Scroll.himlist(@other_author, 3, 2)
611 c.should eq [@other_scroll]
616 describe 'スクロール一覧ページ制御に於いて' do
618 Scroll.stub(:count).with(any_args).and_return(100)
621 r = Scroll.list_paginate
622 r.is_a?(Kaminari::PaginatableArray).should be_true
624 it 'スクロール一覧の取得条件を利用している' do
625 Scroll.stub(:list_where).with(any_args).and_return('')
626 Scroll.should_receive(:list_where).with(any_args).exactly(1)
627 r = Scroll.list_paginate
629 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
630 r = Scroll.list_paginate 3, 10
631 r.limit_value.should eq 10
632 r.offset_value.should eq 20
636 describe '自分のスクロール一覧ページ制御に於いて' do
638 Scroll.stub(:count).with(any_args).and_return(100)
641 r = Scroll.mylist_paginate @author
642 r.is_a?(Kaminari::PaginatableArray).should be_true
644 it '自分のスクロール一覧の取得条件を利用している' do
645 Scroll.stub(:mylist_where).with(any_args).and_return('')
646 Scroll.should_receive(:mylist_where).with(any_args).exactly(1)
647 r = Scroll.mylist_paginate @author
649 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
650 r = Scroll.mylist_paginate @author, 3, 10
651 r.limit_value.should eq 10
652 r.offset_value.should eq 20
656 describe '他作家のスクロール一覧ページ制御に於いて' do
658 Scroll.stub(:count).with(any_args).and_return(100)
661 r = Scroll.himlist_paginate @other_author
662 r.is_a?(Kaminari::PaginatableArray).should be_true
664 it '他作家のスクロール一覧の取得条件を利用している' do
665 Scroll.stub(:himlist_where).with(any_args).and_return('')
666 Scroll.should_receive(:himlist_where).with(any_args).exactly(1)
667 r = Scroll.himlist_paginate @other_author
669 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
670 r = Scroll.himlist_paginate @other_author, 3, 10
671 r.limit_value.should eq 10
672 r.offset_value.should eq 20
676 describe '一覧取得オプションに於いて' do
679 r.should have(2).items
683 r.has_key?(:scroll_panels).should be_true
685 it 'スクコマはコマを含んでいる' do
687 r[:scroll_panels].has_key?(:panel).should be_true
691 r.has_key?(:author).should be_true
694 describe 'json一覧出力オプションに於いて' do
696 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
697 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
698 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
699 @sbt = FactoryGirl.create :speech_balloon_template
700 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
701 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
702 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
705 r = Scroll.list.to_json Scroll.list_json_opt
708 i.has_key?('scroll_panels').should be_true
710 it 'スクコマはコマを含んでいる' do
711 r = Scroll.list.to_json Scroll.list_json_opt
714 s = i['scroll_panels'].first
715 s.has_key?('panel').should be_true
718 r = Scroll.list.to_json Scroll.list_json_opt
721 i.has_key?('author').should be_true
725 describe '単体取得に於いて' do
727 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
729 context 'つつがなく終わるとき' do
730 it '単体取得オプションを利用している' do
731 Scroll.stub(:show_opt).with(any_args).and_return({})
732 Scroll.should_receive(:show_opt).with(any_args).exactly(1)
733 r = Scroll.show @scroll.id, @author
735 it '閲覧許可を問い合わせている' do
736 Scroll.any_instance.stub(:visible?).with(any_args).and_return(true)
737 Scroll.any_instance.should_receive(:visible?).with(any_args).exactly(1)
738 r = Scroll.show @scroll.id, @author
742 c = Scroll.show @scroll.id, @author
745 context '閲覧許可が出なかったとき' do
746 it '403Forbidden例外を返す' do
747 Scroll.any_instance.stub(:visible?).and_return(false)
749 Scroll.show @scroll.id, @author
750 }.should raise_error(ActiveRecord::Forbidden)
753 context '存在しないスクロールを開こうとしたとき' do
754 it '404RecordNotFound例外を返す' do
756 Scroll.show 110, @author
757 }.should raise_error(ActiveRecord::RecordNotFound)
762 describe '編集取得に於いて' do
764 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
766 context 'つつがなく終わるとき' do
767 it '単体取得オプションを利用している' do
768 Scroll.stub(:show_opt).with(any_args).and_return({})
769 Scroll.should_receive(:show_opt).with(any_args).exactly(1)
770 r = Scroll.edit @scroll.id, @author
772 it '所持判定を問い合わせている' do
773 Scroll.any_instance.stub(:own?).with(any_args).and_return(true)
774 Scroll.any_instance.should_receive(:own?).with(any_args).exactly(1)
775 r = Scroll.edit @scroll.id, @author
779 Scroll.any_instance.stub(:own?).and_return(true)
780 c = Scroll.edit @scroll.id, @author.id
783 context '他人のスクロールを開こうとしたとき' do
784 it '403Forbidden例外を返す' do
785 Scroll.any_instance.stub(:own?).and_return(false)
787 Scroll.edit @scroll.id, @author
788 }.should raise_error(ActiveRecord::Forbidden)
791 context '存在しないスクロールを開こうとしたとき' do
792 it '404RecordNotFound例外を返す' do
794 Scroll.edit 110, @author
795 }.should raise_error(ActiveRecord::RecordNotFound)
799 describe '単体取得オプションに於いて' do
800 it 'includeキーを含んでいる' do
802 r.has_key?(:include).should be_true
805 r = Scroll.show_opt[:include]
806 r.should have(2).items
809 r = Scroll.show_opt[:include]
810 r.has_key?(:author).should be_true
813 r = Scroll.show_opt[:include]
814 r.has_key?(:scroll_panels).should be_true
816 it 'スクコマはコマを含んでいる' do
817 r = Scroll.show_opt[:include]
818 r[:scroll_panels].has_key?(:panel).should be_true
821 describe 'json単体出力オプションに於いて' do
823 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
824 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
825 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
826 @sbt = FactoryGirl.create :speech_balloon_template
827 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
828 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
829 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
832 r = Scroll.show(@scroll.id, @author).to_json Scroll.show_json_opt
835 i.has_key?('scroll_panels').should be_true
837 it 'スクコマはコマを含んでいる' do
838 r = Scroll.show(@scroll.id, @author).to_json Scroll.show_json_opt
841 s = i['scroll_panels'].first
842 s.has_key?('panel').should be_true
845 r = Scroll.show(@scroll.id, @author).to_json Scroll.show_json_opt
848 i.has_key?('author').should be_true
854 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
855 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
856 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
857 @other_scroll = FactoryGirl.create :scroll, :author_id => @author.id
858 @other_scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @other_scroll.id, :panel_id => @panel.id
860 context 'つつがなく終わるとき' do
863 r = @scroll.destroy_with_scroll_panel
864 }.should change(Scroll, :count).by(-1)
866 r = Scroll.find @scroll.id
869 it '自身にリンクしているスクコマをすべて削除する' do
871 r = @scroll.destroy_with_scroll_panel
872 }.should change(ScrollPanel, :count).by(-1)
874 r = ScrollPanel.find @scroll_panel.id
878 r = @scroll.destroy_with_scroll_panel
882 context '削除に失敗したとき' do
884 ScrollPanel.any_instance.stub(:destroy).with(any_args).and_return(false)
887 r = @scroll.destroy_with_scroll_panel
892 r = @scroll.destroy_with_scroll_panel
893 }.should_not change(Scroll, :count)
895 r = @scroll.destroy_with_scroll_panel
896 }.should_not change(ScrollPanel, :count)