1 # -*- encoding: utf-8 -*-
5 describe ScrollPanel do
8 @admin =FactoryGirl.create :admin
9 @user_yas = FactoryGirl.create :user_yas_with_owner
10 @user_rom = FactoryGirl.create :user_rom
11 @author_yas = @user_yas.author
14 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
15 @panel = FactoryGirl.create :panel_hello, author: @author_yas
16 @item = FactoryGirl.create :scroll_panel_plain, scroll: @scroll, panel: @panel
19 describe '生成メソッドに於いて' do
23 it '親モデルであるバインダーを取得している' do
24 expect(@model.parent_model).to eq Scroll
26 it '差し込むコンテンツのモデルを取得している' do
27 expect(@model.destination_model).to eq Panel
30 it 'バインダーを取得するためのIDのカラムを返している' do
31 expect(@model.binder_key).to eq 'scroll_id'
34 it '差し込むコンテンツを取得するためのIDのカラムを返している' do
35 expect(@model.destination_key).to eq 'panel_id'
40 describe '便利機能に於いて' do
44 it 'バインダーのIDを返している' do
45 expect(@item.binder_id).to eq @scroll.id
48 it '差し込むコンテンツのIDを返している' do
49 expect(@item.destination_id).to eq @panel.id
53 describe 'クラスメソッドへのショートカットに於いて' do
54 it 'binder_keyメソッドを呼び出せる' do
55 expect(@item.binder_key).to eq @model.binder_key
58 it 'destination_keyメソッドを呼び出せる' do
59 expect(@item.destination_key).to eq @model.destination_key
64 describe 'playに於いて' do
65 it '時系列でソートできるようなSQLを返している' do
66 expect(@model.play_list_order).to eq 'scroll_panels.t'
71 describe 'めんどいからチェックしない機能に於いて' do
72 it 'とりあえず呼び出すところまでは確認しておく' do
79 # new_t, collect_t, serial?, validate_t
80 # store, destroy_and_shorten,
81 # insert_shift, lesser_shift, higher_shift, update_shift, rotate
84 describe SheetPanel do
87 @admin =FactoryGirl.create :admin
88 @user_yas = FactoryGirl.create :user_yas_with_owner
89 @user_rom = FactoryGirl.create :user_rom
90 @author_yas = @user_yas.author
93 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
94 @panel = FactoryGirl.create :panel_hello, author: @author_yas
95 @item = FactoryGirl.create :scroll_panel_plain, scroll: @scroll, panel: @panel
98 describe '生成メソッドに於いて' do
102 it 'ぶら下がるそれぞれのリーフを取得できる' do
103 expect(@model.parent_model).to eq Scroll
105 it 'すべてのリーフを取得できる' do
106 expect(@model.destination_model).to eq Panel
109 it 'ぶら下がるそれぞれのリーフを取得できる' do
110 expect(@model.binder_key).to eq 'scroll_id'
113 it 'ぶら下がるそれぞれのリーフを取得できる' do
114 expect(@model.destination_key).to eq 'panel_id'
124 expect(@item.binder_id).to eq @scroll.id
128 expect(@item.destination_id).to eq @panel.id
132 describe 'cutに於いて' do
134 expect(@item.binder_key).to eq @model.binder_key
138 expect(@item.destination_key).to eq @model.destination_key
143 describe 'playに於いて' do
145 expect(@model.play_list_order).to eq 'scroll_panels.t'
150 describe 'めんどいからチェックしない機能に於いて' do
151 it 'とりあえず呼び出すところまでは確認しておく' do
158 # new_t, collect_t, serial?, validate_t
159 # store, destroy_and_shorten,
160 # insert_shift, lesser_shift, higher_shift, update_shift, rotate
163 describe ComicStory do
166 @admin = FactoryGirl.create :admin
167 @user_yas = FactoryGirl.create :user_yas_with_owner
168 @user_rom = FactoryGirl.create :user_rom
169 @author_yas = @user_yas.author
172 @comic = FactoryGirl.create :comic_doc, author: @author_yas
173 @story = FactoryGirl.create :story_install, author: @author_yas
174 @item = FactoryGirl.create :comic_story_plain, comic: @comic, story: @story
177 describe '生成メソッドに於いて' do
181 it 'ぶら下がるそれぞれのリーフを取得できる' do
182 expect(@model.parent_model).to eq Comic
184 it 'すべてのリーフを取得できる' do
185 expect(@model.destination_model).to eq Story
188 it 'ぶら下がるそれぞれのリーフを取得できる' do
189 expect(@model.binder_key).to eq 'comic_id'
192 it 'ぶら下がるそれぞれのリーフを取得できる' do
193 expect(@model.destination_key).to eq 'story_id'
203 expect(@item.binder_id).to eq @comic.id
207 expect(@item.destination_id).to eq @story.id
211 describe 'cutに於いて' do
213 expect(@item.binder_key).to eq @model.binder_key
217 expect(@item.destination_key).to eq @model.destination_key
222 describe 'playに於いて' do
224 expect(@model.play_list_order).to eq 'comic_stories.t'
229 describe 'めんどいからチェックしない機能に於いて' do
230 it 'とりあえず呼び出すところまでは確認しておく' do
237 # new_t, collect_t, serial?, validate_t
238 # store, destroy_and_shorten,
239 # insert_shift, lesser_shift, higher_shift, update_shift, rotate
242 describe StorySheet do
245 @admin = FactoryGirl.create :admin
246 @user_yas = FactoryGirl.create :user_yas_with_owner
247 @user_rom = FactoryGirl.create :user_rom
248 @author_yas = @user_yas.author
251 @story = FactoryGirl.create :story_install, author: @author_yas
252 @sheet = FactoryGirl.create :sheet_install_a, author: @author_yas
253 @item = FactoryGirl.create :story_sheet_plain, story: @story, sheet: @sheet
256 describe '生成メソッドに於いて' do
260 it 'ぶら下がるそれぞれのリーフを取得できる' do
261 expect(@model.parent_model).to eq Story
263 it 'すべてのリーフを取得できる' do
264 expect(@model.destination_model).to eq Sheet
267 it 'ぶら下がるそれぞれのリーフを取得できる' do
268 expect(@model.binder_key).to eq 'story_id'
271 it 'ぶら下がるそれぞれのリーフを取得できる' do
272 expect(@model.destination_key).to eq 'sheet_id'
282 expect(@item.binder_id).to eq @story.id
286 expect(@item.destination_id).to eq @sheet.id
290 describe 'cutに於いて' do
292 expect(@item.binder_key).to eq @model.binder_key
296 expect(@item.destination_key).to eq @model.destination_key
301 describe 'playに於いて' do
303 expect(@model.play_list_order).to eq 'story_sheets.t'
308 describe 'めんどいからチェックしない機能に於いて' do
309 it 'とりあえず呼び出すところまでは確認しておく' do
316 # new_t, collect_t, serial?, validate_t
317 # store, destroy_and_shorten,
318 # insert_shift, lesser_shift, higher_shift, update_shift, rotate
321 # I/O処理については、マニフェストで動作が変わることがないのでスクロールとスクコマでのみテストしておく
322 describe ScrollPanel do
325 @admin = FactoryGirl.create :admin
326 @user_yas = FactoryGirl.create :user_yas_with_owner
327 @user_rom = FactoryGirl.create :user_rom
328 @author_yas = @user_yas.author
333 describe 't補充値new_tに於いて' do
335 @dummy = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
336 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
337 @panel = FactoryGirl.create :panel_hello, author: @author_yas
340 context 'スクロール初のコマなら' do
342 expect(@model.new_t(@scroll.id)).to eq 0
347 context 'スクロールにコマがあるとき' do
349 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
350 expect(@model.new_t(@scroll.id)).to eq 1
354 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
355 @item = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
356 @item = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
357 expect(@model.new_t(@scroll.id)).to eq 3
364 describe 't収集collect_tに於いて' do
366 @dummy = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
367 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
368 @panel = FactoryGirl.create :panel_hello, author: @author_yas
371 context '空っぽのスクロールのとき' do
372 it '当然リストは空っぽになっている' do
373 expect(@model.collect_t(@scroll.id)).to be_empty
378 context 'オーソドックスなデータのとき' do
379 it 'スクコマから同一スクロールのtだけを収集している' do
380 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
381 expect(@model.collect_t(@scroll.id)).to eq [0]
384 it 'スクコマから同一スクロールのtだけを収集している' do
385 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
386 @item = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
387 @item = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
388 expect(@model.collect_t(@scroll.id)).to eq [0, 1, 2]
395 describe 'tチェックに於いて' do
397 @dummy = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
398 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
399 @panel = FactoryGirl.create :panel_hello, author: @author_yas
403 it '一件だけで正常通過している' do
404 @item = FactoryGirl.build :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
405 r = ScrollPanel.validate_t @item
410 it '2件目を作っても正常通過している' do
411 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
412 @item2 = FactoryGirl.build :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
413 r = ScrollPanel.validate_t @item2
418 describe '挿入シフトに於いて' do
420 @dummy_scroll = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
421 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
422 @panel = FactoryGirl.create :panel_hello, author: @author_yas
424 context 'テーブルに1件(t:0)で0に挿入したとき' do
426 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
427 @item2 = FactoryGirl.build :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
429 it '既存の行を1にシフトしている' do
432 expect(@item.t).to eq 1
434 it 'これから挿入するt(0)が欠番になっている' do
437 expect(@item2.t).to eq 0
440 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
442 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
443 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
444 @item3 = FactoryGirl.build :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
446 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
450 expect(@item.t).to eq 0
451 expect(@item2.t).to eq 2
454 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
456 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
457 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
458 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
459 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
460 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
461 @item6 = FactoryGirl.build :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
463 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
470 expect(@item.t).to eq 0
471 expect(@item2.t).to eq 1
472 expect(@item3.t).to eq 3
473 expect(@item4.t).to eq 4
474 expect(@item5.t).to eq 5
478 describe '少ない方に移動に於いて' do
480 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
481 @panel = FactoryGirl.create :panel_hello, author: @author_yas
483 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
485 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
486 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
490 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
492 @item2.lesser_shift @ot
495 expect(@item.t).to eq 1
496 expect(@item2.t).to eq 1
498 it '既存のt0を1にシフトしている' do
499 @item2.lesser_shift @ot
501 expect(@item.t).to eq 1
504 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
506 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
507 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
508 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
512 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
514 @item3.lesser_shift @ot
518 expect(@item.t).to eq 0
519 expect(@item2.t).to eq 2
520 expect(@item3.t).to eq 2
522 it '既存のt1を2にシフトしている' do
523 @item3.lesser_shift @ot
525 expect(@item2.t).to eq 2
528 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
530 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
531 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
532 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
533 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
534 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
538 it 'これから挿入するt(1)が欠番になっている' do
540 @item4.lesser_shift @ot
541 l = ScrollPanel.find(:all).map {|s| s.t }
542 l.sort.should eq [0, 2, 3, 3, 4]
545 @item4.lesser_shift @ot
550 @item4.lesser_shift @ot
554 it '既存のt1を2にシフトしている' do
555 @item4.lesser_shift @ot
559 it '既存のt2を3にシフトしている' do
560 @item4.lesser_shift @ot
565 context '先ほどのケース+他のスクロール1件で挿入したとき' do
567 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
568 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
569 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
570 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
571 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
575 it 'これから挿入するt(1)が欠番になっている' do
576 @item4.lesser_shift @ot
577 l = ScrollPanel.find(:all).map {|s| s.t }
578 l.sort.should eq [0, 0, 2, 3, 3, 4]
581 @item4.lesser_shift @ot
586 @item4.lesser_shift @ot
590 it '既存のt1を2にシフトしている' do
591 @item4.lesser_shift @ot
595 it '既存のt2を3にシフトしている' do
596 @item4.lesser_shift @ot
600 it '他のスクロールに影響がない' do
601 @item4.lesser_shift @ot
603 @itemc2.t.should eq 0
608 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
610 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
611 @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
612 @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
616 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
618 @item2.lesser_shift @ot
619 l = ScrollPanel.find(:all).map {|s| s.t }
620 l.sort.should eq [1, 1]
622 it '既存のt0を1にシフトしている' do
623 @item2.lesser_shift @ot
627 it '既存のt1は0に補正されている' do
628 @item2.lesser_shift @ot
633 describe '大きい方に移動に於いて' do
635 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
636 @panel = FactoryGirl.create :panel_hello, author: @author_yas
639 it 'Updateを依頼している' do
640 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
641 @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
642 @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
643 ScrollPanel.stub(:update_all).with(any_args)
644 ScrollPanel.should_receive(:update_all).with(any_args).exactly(1)
647 @item.higher_shift ot
650 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
652 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
653 @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
654 @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
658 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
660 @item.higher_shift @ot
661 l = ScrollPanel.find(:all).map {|s| s.t }
662 l.sort.should eq [0, 0]
664 it '既存のt1を0にシフトしている' do
665 @item.higher_shift @ot
670 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
672 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
673 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
674 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
678 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
680 @item.higher_shift @ot
681 l = ScrollPanel.find(:all).map {|s| s.t }
682 l.sort.should eq [0, 0, 2]
684 it '既存のt1を0にシフトしている' do
685 @item.higher_shift @ot
690 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
692 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
693 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
694 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
695 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
696 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
700 it 'これから挿入するt(3)が欠番になっている' do
702 @item2.higher_shift @ot
703 l = ScrollPanel.find(:all).map {|s| s.t }
704 l.sort.should eq [0, 1, 1, 2, 4]
707 @item2.higher_shift @ot
712 @item2.higher_shift @ot
716 it '既存のt2を1にシフトしている' do
717 @item2.higher_shift @ot
721 it '既存のt3を2にシフトしている' do
722 @item2.higher_shift @ot
727 context '先ほどのケース+他のスクロール1件で挿入したとき' do
729 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
730 @itemc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
731 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
732 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
733 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
734 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
735 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
739 it 'これから挿入するt(3)が欠番になっている' do
741 @item2.higher_shift @ot
742 l = ScrollPanel.find(:all).map {|s| s.t }
743 l.sort.should eq [0, 0, 1, 1, 2, 4]
746 @item2.higher_shift @ot
751 @item2.higher_shift @ot
755 it '既存のt2を1にシフトしている' do
756 @item2.higher_shift @ot
760 it '既存のt3を2にシフトしている' do
761 @item2.higher_shift @ot
765 it '他のスクロールに影響がない' do
766 @item2.higher_shift @ot
768 @itemc2.t.should eq 0
773 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
775 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
776 @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
777 @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
781 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
783 @item.higher_shift @ot
784 l = ScrollPanel.find(:all).map {|s| s.t }
785 l.sort.should eq [0, 0]
787 it '既存のt1を0にシフトしている' do
788 @item.higher_shift @ot
792 it '既存のt0は1に補正されている' do
793 @item.higher_shift @ot
798 describe '入れ替えに於いて' do
800 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
801 @panel = FactoryGirl.create :panel_hello, author: @author_yas
802 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
803 @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
804 @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
806 context '新tが旧tより小さいとき' do
807 it '少ない方に移動を依頼している' do
808 ScrollPanel.any_instance.stub(:lesser_shift).with(any_args)
809 ScrollPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
812 @item2.update_shift ot
815 context '新tが旧tより大きいとき' do
816 it '大きい方に移動を依頼している' do
817 ScrollPanel.any_instance.stub(:higher_shift).with(any_args)
818 ScrollPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
821 @item.update_shift ot
825 describe '順序入れ替えに於いて' do
827 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
828 @panel = FactoryGirl.create :panel_hello, author: @author_yas
830 context 'オブジェクトが新規でtが空のとき' do
831 it '末尾追加としてtを補充依頼している' do
832 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
833 @item = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
834 ScrollPanel.stub(:new_t).with(any_args).and_return(0)
835 ScrollPanel.should_receive(:new_t).with(any_args).exactly(1)
840 context 'オブジェクトが新規でtが設定されているとき' do
841 it '挿入追加として挿入シフトを依頼している' do
842 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
843 @item = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
844 ScrollPanel.any_instance.stub(:insert_shift).with(any_args)
845 ScrollPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
850 context 'オブジェクトが新規でなくtが設定されているとき' do
851 it 'コマ移動として入れ替えを依頼している' do
852 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
853 @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
854 @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
855 ScrollPanel.any_instance.stub(:update_shift).with(any_args)
856 ScrollPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
861 context 'オブジェクトが新規でなくtが空のとき' do
862 it '入れ替えもシフトもせず、tを空のままにしている' do
863 #結果、tに欠番が生じてシリアライズチェックでひっかかる
869 @dummy_scroll = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
870 @dummy_scroll_panels = @dummy_scroll.scroll_panels
871 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
872 @panel = FactoryGirl.create :panel_hello, author: @author_yas
874 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
875 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したとき' do
877 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
878 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
879 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
880 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
881 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
882 @item6 = FactoryGirl.build :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
887 expect(@item.t).to eq 0
892 expect(@item2.t).to eq 1
894 it '既存のt2を3にシフトしている' do
897 expect(@item3.t).to eq 3
899 it '既存のt3を4にシフトしている' do
902 expect(@item4.t).to eq 4
904 it '既存のt5を5にシフトしている' do
907 expect(@item5.t).to eq 5
909 it '新規のt2が作成されている' do
912 expect(@item6.t).to eq 2
914 it '他のスクロールに影響がない' do
915 @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
917 @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
918 expect(@after_status).to eq @ot
921 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したとき' do
923 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
924 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
925 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
926 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
927 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
934 expect(@item.t).to eq 0
939 expect(@item5.t).to eq 4
941 it '既存のt1を2にシフトしている' do
944 expect(@item2.t).to eq 2
946 it '既存のt2を3にシフトしている' do
949 expect(@item3.t).to eq 3
951 it '既存のt3を1にシフトしている' do
954 expect(@item4.t).to eq 1
956 it '他のスクロールに影響がない' do
957 @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
959 @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
960 expect(@after_status).to eq @ot
963 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で1を3に移動したとき' do
965 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
966 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
967 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
968 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
969 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
976 expect(@item.t).to eq 0
981 expect(@item5.t).to eq 4
983 it '既存のt1を3にシフトしている' do
986 expect(@item2.t).to eq 3
988 it '既存のt2を1にシフトしている' do
991 expect(@item3.t).to eq 1
993 it '既存のt3を2にシフトしている' do
996 expect(@item4.t).to eq 2
998 it '他のスクロールに影響がない' do
999 @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
1001 @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
1002 expect(@after_status).to eq @ot
1005 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1006 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したが保存に失敗したとき' do
1008 ScrollPanel.any_instance.stub(:save).with(any_args).and_return(false)
1009 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
1010 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
1011 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
1012 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
1013 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
1014 @item6 = FactoryGirl.build :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1023 expect(@item.t).to eq 0
1024 expect(@item2.t).to eq 1
1025 expect(@item3.t).to eq 2
1026 expect(@item4.t).to eq 3
1027 expect(@item5.t).to eq 4
1028 expect(@item.t).to eq 5
1030 @itemc2.t.should eq 0
1034 expect(r).to be_false
1037 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したがシリアルチェックに失敗したとき' do
1039 ScrollPanel.stub(:validate_t).with(any_args).and_return(false)
1040 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
1041 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
1042 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
1043 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
1044 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
1053 @item2.t.should eq 1
1055 @item3.t.should eq 2
1057 @item4.t.should eq 3
1059 @item5.t.should eq 4
1061 @itemc2.t.should eq 0
1062 expect(@item.t).to eq 0
1063 expect(@item.t).to eq 0
1064 expect(@item.t).to eq 0
1065 expect(@item.t).to eq 0
1066 expect(@item.t).to eq 0
1067 expect(@item.t).to eq 0
1070 r = @item4.store @ot
1071 expect(r).to be_false
1073 it 'tにエラーメッセージが入っている' do
1075 expect(@item4.errors[:t]).to be_empty
1076 expect(@item4.valid?).to be_true
1080 describe '切り詰め処理つき削除に於いて' do
1082 @dummy = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
1083 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
1084 @panel = FactoryGirl.create :panel_hello, author: @author_yas
1085 @item = FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
1087 context 'つつがなく終わるとき' do
1090 @item.destroy_and_shorten
1091 }.to change(ScrollPanel, :count ).by(-1)
1094 r = @item.destroy_and_shorten
1095 expect(r).to be_true
1098 context '削除に失敗したとき' do
1100 ScrollPanel.any_instance.stub(:destroy).and_return(false)
1104 @item.destroy_and_shorten
1105 }.to change(ScrollPanel, :count )
1108 r = @item.destroy_and_shorten
1109 expect(r).to be_false
1112 #連携テスト。切り詰めが直接DBをいじる
1113 context '2件で先頭を削除したとき' do
1115 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
1119 @item.destroy_and_shorten
1120 }.to change(ScrollPanel, :count ).by(-1)
1123 @item.destroy_and_shorten
1125 ScrollPanel.find @item.id
1126 }.to raise_error(ActiveRecord::RecordNotFound)
1129 @item.destroy_and_shorten
1131 expect(@item2.t).to eq 0
1134 context '3件で先頭を削除したとき' do
1136 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
1137 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
1141 @item.destroy_and_shorten
1142 }.to change(ScrollPanel, :count ).by(-1)
1145 @item.destroy_and_shorten
1147 ScrollPanel.find @item.id
1148 }.to raise_error(ActiveRecord::RecordNotFound)
1151 @item.destroy_and_shorten
1153 expect(@item2.t).to eq 0
1156 @item.destroy_and_shorten
1158 expect(@item3.t).to eq 1
1161 context '5件で3件目を削除したとき' do
1163 @item2 = FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
1164 @item3 = FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
1165 @item4 = FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
1166 @item5 = FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
1170 @item3.destroy_and_shorten
1171 }.to change(ScrollPanel, :count ).by(-1)
1174 @item3.destroy_and_shorten
1176 expect(@item.t).to eq 0
1179 @item3.destroy_and_shorten
1181 expect(@item2.t).to eq 1
1184 @item3.destroy_and_shorten
1186 ScrollPanel.find @item3.id
1187 }.to raise_error(ActiveRecord::RecordNotFound)
1190 @item3.destroy_and_shorten
1192 expect(@item4.t).to eq 2
1195 @item3.destroy_and_shorten
1197 expect(@item5.t).to eq 3
1200 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する