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
27 expect(@model.destination_model).to eq Panel
30 it 'ぶら下がるそれぞれのリーフを取得できる' do
31 expect(@model.binder_key).to eq 'scroll_id'
34 it 'ぶら下がるそれぞれのリーフを取得できる' do
35 expect(@model.destination_key).to eq 'panel_id'
45 expect(@item.binder_id).to eq @scroll.id
49 expect(@item.destination_id).to eq @panel.id
55 expect(@item.binder_key).to eq @model.binder_key
59 expect(@item.destination_key).to eq @model.destination_key
64 describe 'playに於いて' 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
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 'new_tに於いて' do
335 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
338 context 'オーソドックスなデータのとき' do
340 expect(@model.new_t(@scroll.id)).to eq 0
345 context 'オーソドックスなデータのとき' do
347 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
348 expect(@model.new_t(@scroll.id)).to eq 1
352 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
353 @item = FactoryGirl.create :scroll_panel_plain, z: 2, t: 1, scroll: @scroll, panel: @panel
354 @item = FactoryGirl.create :scroll_panel_plain, z: 3, t: 2, scroll: @scroll, panel: @panel
355 expect(@model.new_t(@scroll.id)).to eq 3
362 describe 'collect_tに於いて' do
364 @dummy = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
365 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
368 context 'オーソドックスなデータのとき' do
370 expect(@model.collect_t(@scroll.id)).to be_empty
375 context 'オーソドックスなデータのとき' do
377 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
378 expect(@model.collect_t(@scroll.id)).to eq [0]
382 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
383 @item = FactoryGirl.create :scroll_panel_plain, z: 2, t: 1, scroll: @scroll, panel: @panel
384 @item = FactoryGirl.create :scroll_panel_plain, z: 3, t: 2, scroll: @scroll, panel: @panel
385 expect(@model.collect_t(@scroll.id)).to eq [0, 1, 2]
392 describe 'tチェックに於いて' do
394 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
395 @panel = FactoryGirl.create :panel, :author_id => @author.id
396 @item = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
398 context 'つつがなく終わるとき' do
400 SheetPanel.should_receive(:collect_t).with(any_args).exactly(1)
401 SheetPanel.stub(:collect_t).with(any_args).and_return([])
402 SheetPanel.stub(:serial?).with(any_args).and_return(true)
403 r = SheetPanel.validate_t @item
405 it '収集したtをシリアライズチェック依頼している' do
406 SheetPanel.stub(:collect_t).with(any_args).and_return([])
407 SheetPanel.should_receive(:serial?).with(any_args).exactly(1)
408 SheetPanel.stub(:serial?).with(any_args).and_return(true)
409 r = SheetPanel.validate_t @item
413 #依頼チェックだけでは不安なので最低限のチェックを
415 it '一件だけで正常通過している' do
416 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
417 r = SheetPanel.validate_t @item
422 it '2件目を作っても正常通過している' do
423 @item = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
424 @item2 = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
425 r = SheetPanel.validate_t @item2
430 describe '挿入シフトに於いて' do
432 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
433 @panel = FactoryGirl.create :panel, :author_id => @author.id
437 it 'Updateを依頼している' do
438 SheetPanel.stub(:update_all).with(any_args)
439 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
440 @item = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
444 context 'テーブルに1件(t:0)で0に挿入したとき' do
446 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
447 @item2 = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
449 it '既存の行を1にシフトしている' do
451 l = SheetPanel.find :all
452 l.first.t.should eq 1
454 it 'これから挿入するt(0)が欠番になっている' do
456 l = SheetPanel.find(:all).map {|s| s.t }
457 l.include?(0).should_not be_true
460 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
462 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
463 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
464 @item3 = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
466 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
468 l = SheetPanel.find(:all).map {|s| s.t }
469 l.sort.should eq [0, 2]
472 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
474 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
475 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
476 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
477 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
478 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
479 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
481 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
483 l = SheetPanel.find(:all).map {|s| s.t }
484 l.sort.should eq [0, 1, 3, 4, 5]
487 context '先ほどのケース+他の用紙1件で挿入したとき' do
489 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
490 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
491 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
492 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
493 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
494 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
495 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
496 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
498 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
500 l = SheetPanel.find(:all, :conditions => ['sheet_id = ?', @sheet.id]).map {|s| s.t }
501 l.sort.should eq [0, 1, 3, 4, 5]
507 @itemc2.t.should eq ot
511 describe '少ない方に移動に於いて' do
513 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
514 @panel = FactoryGirl.create :panel, :author_id => @author.id
517 it 'Updateを依頼している' do
518 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
519 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
520 SheetPanel.stub(:update_all).with(any_args)
521 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
524 @item2.lesser_shift ot
527 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
529 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
530 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
534 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
536 @item2.lesser_shift @ot
537 l = SheetPanel.find(:all).map {|s| s.t }
538 l.sort.should eq [1, 1]
540 it '既存のt0を1にシフトしている' do
541 @item2.lesser_shift @ot
546 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
548 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
549 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
550 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
554 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
556 @item3.lesser_shift @ot
557 l = SheetPanel.find(:all).map {|s| s.t }
558 l.sort.should eq [0, 2, 2]
560 it '既存のt1を2にシフトしている' do
561 @item3.lesser_shift @ot
566 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
568 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
569 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
570 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
571 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
572 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
576 it 'これから挿入するt(1)が欠番になっている' do
578 @item4.lesser_shift @ot
579 l = SheetPanel.find(:all).map {|s| s.t }
580 l.sort.should eq [0, 2, 3, 3, 4]
583 @item4.lesser_shift @ot
588 @item4.lesser_shift @ot
592 it '既存のt1を2にシフトしている' do
593 @item4.lesser_shift @ot
597 it '既存のt2を3にシフトしている' do
598 @item4.lesser_shift @ot
603 context '先ほどのケース+他の用紙1件で挿入したとき' do
605 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
606 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
607 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
608 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
609 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
610 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
611 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
615 it 'これから挿入するt(1)が欠番になっている' do
616 @item4.lesser_shift @ot
617 l = SheetPanel.find(:all).map {|s| s.t }
618 l.sort.should eq [0, 0, 2, 3, 3, 4]
621 @item4.lesser_shift @ot
626 @item4.lesser_shift @ot
630 it '既存のt1を2にシフトしている' do
631 @item4.lesser_shift @ot
635 it '既存のt2を3にシフトしている' do
636 @item4.lesser_shift @ot
641 @item4.lesser_shift @ot
643 @itemc2.t.should eq 0
648 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
650 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
651 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
655 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
657 @item2.lesser_shift @ot
658 l = SheetPanel.find(:all).map {|s| s.t }
659 l.sort.should eq [1, 1]
661 it '既存のt0を1にシフトしている' do
662 @item2.lesser_shift @ot
666 it '既存のt1は0に補正されている' do
667 @item2.lesser_shift @ot
672 describe '大きい方に移動に於いて' do
674 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
675 @panel = FactoryGirl.create :panel, :author_id => @author.id
678 it 'Updateを依頼している' do
679 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
680 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
681 SheetPanel.stub(:update_all).with(any_args)
682 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
685 @item.higher_shift ot
688 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
690 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
691 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
695 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
697 @item.higher_shift @ot
698 l = SheetPanel.find(:all).map {|s| s.t }
699 l.sort.should eq [0, 0]
701 it '既存のt1を0にシフトしている' do
702 @item.higher_shift @ot
707 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
709 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
710 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
711 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
715 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
717 @item.higher_shift @ot
718 l = SheetPanel.find(:all).map {|s| s.t }
719 l.sort.should eq [0, 0, 2]
721 it '既存のt1を0にシフトしている' do
722 @item.higher_shift @ot
727 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
729 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
730 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
731 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
732 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
733 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
737 it 'これから挿入するt(3)が欠番になっている' do
739 @item2.higher_shift @ot
740 l = SheetPanel.find(:all).map {|s| s.t }
741 l.sort.should eq [0, 1, 1, 2, 4]
744 @item2.higher_shift @ot
749 @item2.higher_shift @ot
753 it '既存のt2を1にシフトしている' do
754 @item2.higher_shift @ot
758 it '既存のt3を2にシフトしている' do
759 @item2.higher_shift @ot
764 context '先ほどのケース+他の用紙1件で挿入したとき' do
766 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
767 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
768 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
769 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
770 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
771 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
772 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
776 it 'これから挿入するt(3)が欠番になっている' do
778 @item2.higher_shift @ot
779 l = SheetPanel.find(:all).map {|s| s.t }
780 l.sort.should eq [0, 0, 1, 1, 2, 4]
783 @item2.higher_shift @ot
788 @item2.higher_shift @ot
792 it '既存のt2を1にシフトしている' do
793 @item2.higher_shift @ot
797 it '既存のt3を2にシフトしている' do
798 @item2.higher_shift @ot
803 @item2.higher_shift @ot
805 @itemc2.t.should eq 0
810 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
812 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
813 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
817 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
819 @item.higher_shift @ot
820 l = SheetPanel.find(:all).map {|s| s.t }
821 l.sort.should eq [0, 0]
823 it '既存のt1を0にシフトしている' do
824 @item.higher_shift @ot
828 it '既存のt0は1に補正されている' do
829 @item.higher_shift @ot
834 describe '入れ替えに於いて' do
836 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
837 @panel = FactoryGirl.create :panel, :author_id => @author.id
838 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
839 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
841 context '新tが旧tより小さいとき' do
842 it '少ない方に移動を依頼している' do
843 SheetPanel.any_instance.stub(:lesser_shift).with(any_args)
844 SheetPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
847 @item2.update_shift ot
850 context '新tが旧tより大きいとき' do
851 it '大きい方に移動を依頼している' do
852 SheetPanel.any_instance.stub(:higher_shift).with(any_args)
853 SheetPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
856 @item.update_shift ot
860 describe '順序入れ替えに於いて' do
862 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
863 @panel = FactoryGirl.create :panel, :author_id => @author.id
865 context 'オブジェクトが新規でtが空のとき' do
866 it '末尾追加としてtを補充依頼している' do
867 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
868 SheetPanel.stub(:new_t).with(any_args).and_return(0)
869 SheetPanel.should_receive(:new_t).with(any_args).exactly(1)
874 context 'オブジェクトが新規でtが設定されているとき' do
875 it '挿入追加として挿入シフトを依頼している' do
876 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
877 SheetPanel.any_instance.stub(:insert_shift).with(any_args)
878 SheetPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
883 context 'オブジェクトが新規でなくtが設定されているとき' do
884 it 'コマ移動として入れ替えを依頼している' do
885 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
886 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
887 SheetPanel.any_instance.stub(:update_shift).with(any_args)
888 SheetPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
893 context 'オブジェクトが新規でなくtが空のとき' do
894 it '入れ替えもシフトもせず、tを空のままにしている' do
895 #結果、tに欠番が生じてシリアライズチェックでひっかかる
901 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
902 @panel = FactoryGirl.create :panel, :author_id => @author.id
903 @item = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
905 context 'つつがなく終わるとき' do
906 it '編集許可チェックを依頼している' do
907 SheetPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
908 SheetPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
911 it '順序入れ替えを依頼している' do
912 SheetPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
913 SheetPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
914 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
915 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
919 SheetPanel.stub(:new_t).with(any_args).and_return(0)
920 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
921 SheetPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
922 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
925 it 'tのシリアライズチェックを依頼している' do
926 SheetPanel.stub(:new_t).with(any_args).and_return(0)
927 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
928 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
929 SheetPanel.should_receive(:validate_t).with(any_args).exactly(1)
933 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
934 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したとき' do
936 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
937 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
938 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
939 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
940 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
941 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
942 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
943 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
955 it '既存のt2を3にシフトしている' do
960 it '既存のt3を4にシフトしている' do
965 it '既存のt5を5にシフトしている' do
970 it '新規のt2が作成されている' do
979 @itemc2.t.should eq @ot
982 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したとき' do
984 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
985 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
986 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
987 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
988 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
989 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
990 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1002 @item5.t.should eq 4
1004 it '既存のt1を2にシフトしている' do
1007 @item2.t.should eq 2
1009 it '既存のt2を3にシフトしている' do
1012 @item3.t.should eq 3
1014 it '既存のt3を1にシフトしている' do
1017 @item4.t.should eq 1
1022 @itemc2.t.should eq 0
1025 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で1を3に移動したとき' do
1027 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1028 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1029 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1030 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1031 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1032 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1033 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1037 it '既存のt0には変化がない' do
1042 it '既存のt4には変化がない' do
1045 @item5.t.should eq 4
1047 it '既存のt1を3にシフトしている' do
1050 @item2.t.should eq 3
1052 it '既存のt2を1にシフトしている' do
1055 @item3.t.should eq 1
1057 it '既存のt3を2にシフトしている' do
1060 @item4.t.should eq 2
1065 @itemc2.t.should eq 0
1068 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1069 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したが保存に失敗したとき' do
1071 SheetPanel.any_instance.stub(:save).with(any_args).and_return(false)
1072 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1073 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1074 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1075 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1076 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1077 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1078 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1079 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1086 @item2.t.should eq 1
1088 @item3.t.should eq 2
1090 @item4.t.should eq 3
1092 @item5.t.should eq 4
1094 @itemc2.t.should eq 0
1101 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したがシリアルチェックに失敗したとき' do
1103 SheetPanel.stub(:validate_t).with(any_args).and_return(false)
1104 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1105 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1106 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1107 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1108 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1109 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1110 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1119 @item2.t.should eq 1
1121 @item3.t.should eq 2
1123 @item4.t.should eq 3
1125 @item5.t.should eq 4
1127 @itemc2.t.should eq 0
1130 r = @item4.store @ot
1133 it 'tにエラーメッセージが入っている' do
1135 @item4.errors[:t].should_not be_empty
1136 @item4.valid?.should be_true
1139 context '編集不可だったとき' do
1141 @item = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1142 SheetPanel.any_instance.stub(:allow?).and_return(false)
1144 it '403Forbidden例外を返す' do
1147 }.should raise_error(ActiveRecord::Forbidden)
1151 describe '切り詰め処理つき削除に於いて' do
1153 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1154 @panel = FactoryGirl.create :panel, :author_id => @author.id
1155 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1157 context 'つつがなく終わるとき' do
1160 @item.destroy_and_shorten
1161 }.should change(SheetPanel, :count ).by(-1)
1164 r = @item.destroy_and_shorten
1168 context '削除に失敗したとき' do
1170 SheetPanel.any_instance.stub(:destroy).and_return(false)
1174 @item.destroy_and_shorten
1175 }.should_not change(SheetPanel, :count )
1178 r = @item.destroy_and_shorten
1182 #連携テスト。切り詰めが直接DBをいじる
1183 context '2件で先頭を削除したとき' do
1185 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1189 @item.destroy_and_shorten
1190 }.should change(SheetPanel, :count ).by(-1)
1193 @item.destroy_and_shorten
1195 SheetPanel.find @item.id
1196 }.should raise_error(ActiveRecord::RecordNotFound)
1199 @item.destroy_and_shorten
1201 @item2.t.should eq 0
1204 context '3件で先頭を削除したとき' do
1206 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1207 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1211 @item.destroy_and_shorten
1212 }.should change(SheetPanel, :count ).by(-1)
1215 @item.destroy_and_shorten
1217 SheetPanel.find @item.id
1218 }.should raise_error(ActiveRecord::RecordNotFound)
1221 @item.destroy_and_shorten
1223 @item2.t.should eq 0
1226 @item.destroy_and_shorten
1228 @item3.t.should eq 1
1231 context '5件で3件目を削除したとき' do
1233 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1234 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1235 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1236 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1240 @item3.destroy_and_shorten
1241 }.should change(SheetPanel, :count ).by(-1)
1244 @item3.destroy_and_shorten
1249 @item3.destroy_and_shorten
1251 @item2.t.should eq 1
1254 @item3.destroy_and_shorten
1256 SheetPanel.find @item3.id
1257 }.should raise_error(ActiveRecord::RecordNotFound)
1260 @item3.destroy_and_shorten
1262 @item4.t.should eq 2
1265 @item3.destroy_and_shorten
1267 @item5.t.should eq 3
1270 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する