OSDN Git Service

fix js filer
[pettanr/pettanr.git] / spec / peta / leaf_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #スクロール
4
5 describe ScrollPanel do
6   include LeafMacros
7   before 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
12     
13     @model = ScrollPanel
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
17   end
18   
19   describe '生成メソッドに於いて' do
20     before do
21     end
22     
23     it '親モデルであるバインダーを取得している' do
24       expect(@model.parent_model).to eq Scroll
25     end
26     it '差し込むコンテンツのモデルを取得している' do
27       expect(@model.destination_model).to eq Panel
28     end
29     
30     it 'バインダーを取得するためのIDのカラムを返している' do
31       expect(@model.binder_key).to eq 'scroll_id'
32     end
33     
34     it '差し込むコンテンツを取得するためのIDのカラムを返している' do
35       expect(@model.destination_key).to eq 'panel_id'
36     end
37     
38   end
39   
40   describe '便利機能に於いて' do
41     before do
42     end
43     
44     it 'バインダーのIDを返している' do
45       expect(@item.binder_id).to eq @scroll.id
46     end
47     
48     it '差し込むコンテンツのIDを返している' do
49       expect(@item.destination_id).to eq @panel.id
50     end
51   end
52   
53   describe 'クラスメソッドへのショートカットに於いて' do
54     it 'binder_keyメソッドを呼び出せる' do
55       expect(@item.binder_key).to eq @model.binder_key
56     end
57     
58     it 'destination_keyメソッドを呼び出せる' do
59       expect(@item.destination_key).to eq @model.destination_key
60     end
61     
62   end
63   
64   describe 'playに於いて' do
65     it '時系列でソートできるようなSQLを返している' do
66       expect(@model.play_list_order).to eq 'scroll_panels.t'
67     end
68     
69   end
70   
71   describe 'めんどいからチェックしない機能に於いて' do
72     it 'とりあえず呼び出すところまでは確認しておく' do
73       define_test @model
74     end
75     # max_t, find_t, 
76     # own?, visible?
77   end
78   
79     # new_t, collect_t, serial?, validate_t
80     # store, destroy_and_shorten, 
81     # insert_shift, lesser_shift, higher_shift, update_shift, rotate
82 end
83
84 describe SheetPanel do
85   include LeafMacros
86   before 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
91     
92     @model = ScrollPanel
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
96   end
97   
98   describe '生成メソッドに於いて' do
99     before do
100     end
101     
102     it 'ぶら下がるそれぞれのリーフを取得できる' do
103       expect(@model.parent_model).to eq Scroll
104     end
105     it 'すべてのリーフを取得できる' do
106       expect(@model.destination_model).to eq Panel
107     end
108     
109     it 'ぶら下がるそれぞれのリーフを取得できる' do
110       expect(@model.binder_key).to eq 'scroll_id'
111     end
112     
113     it 'ぶら下がるそれぞれのリーフを取得できる' do
114       expect(@model.destination_key).to eq 'panel_id'
115     end
116     
117   end
118   
119   describe 'myに於いて' do
120     before do
121     end
122     
123     it '名前の活用に於いて' do
124       expect(@item.binder_id).to eq @scroll.id
125     end
126     
127     it '名前の活用に於いて' do
128       expect(@item.destination_id).to eq @panel.id
129     end
130   end
131   
132   describe 'cutに於いて' do
133     it 'cut' do
134       expect(@item.binder_key).to eq @model.binder_key
135     end
136     
137     it 'cut' do
138       expect(@item.destination_key).to eq @model.destination_key
139     end
140     
141   end
142   
143   describe 'playに於いて' do
144     it 'cut' do
145       expect(@model.play_list_order).to eq 'scroll_panels.t'
146     end
147     
148   end
149   
150   describe 'めんどいからチェックしない機能に於いて' do
151     it 'とりあえず呼び出すところまでは確認しておく' do
152       define_test @model
153     end
154     # max_t, find_t, 
155     # own?, visible?
156   end
157   
158     # new_t, collect_t, serial?, validate_t
159     # store, destroy_and_shorten, 
160     # insert_shift, lesser_shift, higher_shift, update_shift, rotate
161 end
162
163 describe ComicStory do
164   include LeafMacros
165   before 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
170     
171     @model = ComicStory
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
175   end
176   
177   describe '生成メソッドに於いて' do
178     before do
179     end
180     
181     it 'ぶら下がるそれぞれのリーフを取得できる' do
182       expect(@model.parent_model).to eq Comic
183     end
184     it 'すべてのリーフを取得できる' do
185       expect(@model.destination_model).to eq Story
186     end
187     
188     it 'ぶら下がるそれぞれのリーフを取得できる' do
189       expect(@model.binder_key).to eq 'comic_id'
190     end
191     
192     it 'ぶら下がるそれぞれのリーフを取得できる' do
193       expect(@model.destination_key).to eq 'story_id'
194     end
195     
196   end
197   
198   describe 'myに於いて' do
199     before do
200     end
201     
202     it '名前の活用に於いて' do
203       expect(@item.binder_id).to eq @comic.id
204     end
205     
206     it '名前の活用に於いて' do
207       expect(@item.destination_id).to eq @story.id
208     end
209   end
210   
211   describe 'cutに於いて' do
212     it 'cut' do
213       expect(@item.binder_key).to eq @model.binder_key
214     end
215     
216     it 'cut' do
217       expect(@item.destination_key).to eq @model.destination_key
218     end
219     
220   end
221   
222   describe 'playに於いて' do
223     it 'cut' do
224       expect(@model.play_list_order).to eq 'comic_stories.t'
225     end
226     
227   end
228   
229   describe 'めんどいからチェックしない機能に於いて' do
230     it 'とりあえず呼び出すところまでは確認しておく' do
231       define_test @model
232     end
233     # max_t, find_t, 
234     # own?, visible?
235   end
236   
237     # new_t, collect_t, serial?, validate_t
238     # store, destroy_and_shorten, 
239     # insert_shift, lesser_shift, higher_shift, update_shift, rotate
240 end
241
242 describe StorySheet do
243   include LeafMacros
244   before 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
249     
250     @model = StorySheet
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
254   end
255   
256   describe '生成メソッドに於いて' do
257     before do
258     end
259     
260     it 'ぶら下がるそれぞれのリーフを取得できる' do
261       expect(@model.parent_model).to eq Story
262     end
263     it 'すべてのリーフを取得できる' do
264       expect(@model.destination_model).to eq Sheet
265     end
266     
267     it 'ぶら下がるそれぞれのリーフを取得できる' do
268       expect(@model.binder_key).to eq 'story_id'
269     end
270     
271     it 'ぶら下がるそれぞれのリーフを取得できる' do
272       expect(@model.destination_key).to eq 'sheet_id'
273     end
274     
275   end
276   
277   describe 'myに於いて' do
278     before do
279     end
280     
281     it '名前の活用に於いて' do
282       expect(@item.binder_id).to eq @story.id
283     end
284     
285     it '名前の活用に於いて' do
286       expect(@item.destination_id).to eq @sheet.id
287     end
288   end
289   
290   describe 'cutに於いて' do
291     it 'cut' do
292       expect(@item.binder_key).to eq @model.binder_key
293     end
294     
295     it 'cut' do
296       expect(@item.destination_key).to eq @model.destination_key
297     end
298     
299   end
300   
301   describe 'playに於いて' do
302     it 'cut' do
303       expect(@model.play_list_order).to eq 'story_sheets.t'
304     end
305     
306   end
307   
308   describe 'めんどいからチェックしない機能に於いて' do
309     it 'とりあえず呼び出すところまでは確認しておく' do
310       define_test @model
311     end
312     # max_t, find_t, 
313     # own?, visible?
314   end
315   
316     # new_t, collect_t, serial?, validate_t
317     # store, destroy_and_shorten, 
318     # insert_shift, lesser_shift, higher_shift, update_shift, rotate
319 end
320
321 # I/O処理については、マニフェストで動作が変わることがないのでスクロールとスクコマでのみテストしておく
322 describe ScrollPanel do
323   include LeafMacros
324   before 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
329     
330     @model = ScrollPanel
331   end
332   
333   describe 't補充値new_tに於いて' do
334     before 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
338     end
339     
340     context 'スクロール初のコマなら' do
341       it '0を補充値とする' do
342         expect(@model.new_t(@scroll.id)).to eq 0
343       end
344       
345     end
346     
347     context 'スクロールにコマがあるとき' do
348       it '一個なら1を補充値とする' do
349         @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
350         expect(@model.new_t(@scroll.id)).to eq 1
351       end
352       
353       it '3個なら3を補充値とする' do
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
358       end
359       
360     end
361     
362   end
363   
364   describe 't収集collect_tに於いて' do
365     before 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
369     end
370     
371     context '空っぽのスクロールのとき' do
372       it '当然リストは空っぽになっている' do
373         expect(@model.collect_t(@scroll.id)).to be_empty
374       end
375       
376     end
377     
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]
382       end
383       
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]
389       end
390       
391     end
392     
393   end
394   
395   describe 'tチェックに於いて' do
396     before 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
400     end
401     #実データで最低限のチェックを
402     context '新規のとき' do
403       it '一件だけで正常通過している' do
404         @item =  FactoryGirl.build :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
405         r = ScrollPanel.validate_t @item
406         expect(r).to be_true 
407       end
408     end
409     context '既存のとき' do
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
414         expect(r).to be_true 
415       end
416     end
417   end
418   describe '挿入シフトに於いて' do
419     before 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
423     end
424     context 'テーブルに1件(t:0)で0に挿入したとき' do
425       before 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
428       end
429       it '既存の行を1にシフトしている' do
430         @item2.insert_shift
431         @item.reload
432         expect(@item.t).to eq 1
433       end
434       it 'これから挿入するt(0)が欠番になっている' do
435         @item2.insert_shift
436         @item.reload
437         expect(@item2.t).to eq 0
438       end
439     end
440     context 'テーブルに2件(t:0,1)で1に挿入したとき' do
441       before 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
445       end
446       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
447         @item3.insert_shift
448         @item.reload
449         @item2.reload
450         expect(@item.t).to eq 0
451         expect(@item2.t).to eq 2
452       end
453     end
454     context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
455       before 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
462       end
463       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
464         @item6.insert_shift
465         @item.reload
466         @item2.reload
467         @item3.reload
468         @item4.reload
469         @item5.reload
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
475       end
476     end
477   end
478   describe '少ない方に移動に於いて' do
479     before do
480       @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
481       @panel = FactoryGirl.create :panel_hello, author: @author_yas
482     end
483     context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
484       before 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
487         @ot = @item2.t
488         @item2.t = 0
489       end
490       it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
491         #移動させたい行はそのまま残る
492         @item2.lesser_shift @ot
493         @item.reload
494         @item2.reload
495         expect(@item.t).to eq 1
496         expect(@item2.t).to eq 1
497       end
498       it '既存のt0を1にシフトしている' do
499         @item2.lesser_shift @ot
500         @item.reload
501         expect(@item.t).to eq 1
502       end
503     end
504     context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
505       before 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
509         @ot = @item3.t
510         @item3.t = 1
511       end
512       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
513         #移動させたい行はそのまま残る
514         @item3.lesser_shift @ot
515         @item.reload
516         @item2.reload
517         @item3.reload
518         expect(@item.t).to eq 0
519         expect(@item2.t).to eq 2
520         expect(@item3.t).to eq 2
521       end
522       it '既存のt1を2にシフトしている' do
523         @item3.lesser_shift @ot
524         @item2.reload
525         expect(@item2.t).to eq 2
526       end
527     end
528     context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
529       before 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
535         @ot = @item4.t
536         @item4.t = 1
537       end
538       it 'これから挿入するt(1)が欠番になっている' do
539         #移動させたい行はそのまま残る
540         @item4.lesser_shift @ot
541         l = ScrollPanel.find(:all).map {|s| s.t }
542         l.sort.should eq [0, 2, 3, 3, 4]
543       end
544       it '既存のt0には変化がない' do
545         @item4.lesser_shift @ot
546         @item.reload
547         @item.t.should eq 0
548       end
549       it '既存のt4には変化がない' do
550         @item4.lesser_shift @ot
551         @item5.reload
552         @item5.t.should eq 4
553       end
554       it '既存のt1を2にシフトしている' do
555         @item4.lesser_shift @ot
556         @item2.reload
557         @item2.t.should eq 2
558       end
559       it '既存のt2を3にシフトしている' do
560         @item4.lesser_shift @ot
561         @item3.reload
562         @item3.t.should eq 3
563       end
564     end
565     context '先ほどのケース+他のスクロール1件で挿入したとき' do
566       before 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
572         @ot = @item4.t
573         @item4.t = 1
574       end
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]
579       end
580       it '既存のt0には変化がない' do
581         @item4.lesser_shift @ot
582         @item.reload
583         @item.t.should eq 0
584       end
585       it '既存のt4には変化がない' do
586         @item4.lesser_shift @ot
587         @item5.reload
588         @item5.t.should eq 4
589       end
590       it '既存のt1を2にシフトしている' do
591         @item4.lesser_shift @ot
592         @item2.reload
593         @item2.t.should eq 2
594       end
595       it '既存のt2を3にシフトしている' do
596         @item4.lesser_shift @ot
597         @item3.reload
598         @item3.t.should eq 3
599       end
600       it '他のスクロールに影響がない' do
601         @item4.lesser_shift @ot
602         @itemc2.reload
603         @itemc2.t.should eq 0
604       end
605     end
606     #例外ケース。
607     #負のときは0として正常扱い
608     context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
609       before 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
613         @ot = @item2.t
614         @item2.t = -1
615       end
616       it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
617         #移動させたい行はそのまま残る
618         @item2.lesser_shift @ot
619         l = ScrollPanel.find(:all).map {|s| s.t }
620         l.sort.should eq [1, 1]
621       end
622       it '既存のt0を1にシフトしている' do
623         @item2.lesser_shift @ot
624         @item.reload
625         @item.t.should eq 1
626       end
627       it '既存のt1は0に補正されている' do
628         @item2.lesser_shift @ot
629         @item2.t.should eq 0
630       end
631     end
632   end
633   describe '大きい方に移動に於いて' do
634     before do
635       @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
636       @panel = FactoryGirl.create :panel_hello, author: @author_yas
637     end
638     context '依頼チェック' do
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)
645         ot = @item.t
646         @item.t = 1
647         @item.higher_shift ot
648       end
649     end
650     context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
651       before 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
655         @ot = @item.t
656         @item.t = 1
657       end
658       it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
659         #移動させたい行はそのまま残る
660         @item.higher_shift @ot
661         l = ScrollPanel.find(:all).map {|s| s.t }
662         l.sort.should eq [0, 0]
663       end
664       it '既存のt1を0にシフトしている' do
665         @item.higher_shift @ot
666         @item2.reload
667         @item2.t.should eq 0
668       end
669     end
670     context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
671       before 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
675         @ot = @item.t
676         @item.t = 1
677       end
678       it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
679         #移動させたい行はそのまま残る
680         @item.higher_shift @ot
681         l = ScrollPanel.find(:all).map {|s| s.t }
682         l.sort.should eq [0, 0, 2]
683       end
684       it '既存のt1を0にシフトしている' do
685         @item.higher_shift @ot
686         @item2.reload
687         @item2.t.should eq 0
688       end
689     end
690     context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
691       before 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
697         @ot = @item2.t
698         @item2.t = 3
699       end
700       it 'これから挿入するt(3)が欠番になっている' do
701         #移動させたい行はそのまま残る
702         @item2.higher_shift @ot
703         l = ScrollPanel.find(:all).map {|s| s.t }
704         l.sort.should eq [0, 1, 1, 2, 4]
705       end
706       it '既存のt0には変化がない' do
707         @item2.higher_shift @ot
708         @item.reload
709         @item.t.should eq 0
710       end
711       it '既存のt4には変化がない' do
712         @item2.higher_shift @ot
713         @item5.reload
714         @item5.t.should eq 4
715       end
716       it '既存のt2を1にシフトしている' do
717         @item2.higher_shift @ot
718         @item3.reload
719         @item3.t.should eq 1
720       end
721       it '既存のt3を2にシフトしている' do
722         @item2.higher_shift @ot
723         @item4.reload
724         @item4.t.should eq 2
725       end
726     end
727     context '先ほどのケース+他のスクロール1件で挿入したとき' do
728       before 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
736         @ot = @item2.t
737         @item2.t = 3
738       end
739       it 'これから挿入するt(3)が欠番になっている' do
740         #移動させたい行はそのまま残る
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]
744       end
745       it '既存のt0には変化がない' do
746         @item2.higher_shift @ot
747         @item.reload
748         @item.t.should eq 0
749       end
750       it '既存のt4には変化がない' do
751         @item2.higher_shift @ot
752         @item5.reload
753         @item5.t.should eq 4
754       end
755       it '既存のt2を1にシフトしている' do
756         @item2.higher_shift @ot
757         @item3.reload
758         @item3.t.should eq 1
759       end
760       it '既存のt3を2にシフトしている' do
761         @item2.higher_shift @ot
762         @item4.reload
763         @item4.t.should eq 2
764       end
765       it '他のスクロールに影響がない' do
766         @item2.higher_shift @ot
767         @itemc2.reload
768         @itemc2.t.should eq 0
769       end
770     end
771     #例外ケース。
772     #max超えたときはmaxとして正常扱い
773     context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
774       before 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
778         @ot = @item.t
779         @item.t = 2
780       end
781       it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
782         #移動させたい行はそのまま残る
783         @item.higher_shift @ot
784         l = ScrollPanel.find(:all).map {|s| s.t }
785         l.sort.should eq [0, 0]
786       end
787       it '既存のt1を0にシフトしている' do
788         @item.higher_shift @ot
789         @item2.reload
790         @item2.t.should eq 0
791       end
792       it '既存のt0は1に補正されている' do
793         @item.higher_shift @ot
794         @item.t.should eq 1
795       end
796     end
797   end
798   describe '入れ替えに於いて' do
799     before 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
805     end
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)
810         ot = @item2.t
811         @item2.t = 0
812         @item2.update_shift ot
813       end
814     end
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)
819         ot = @item.t
820         @item.t = 1
821         @item.update_shift ot
822       end
823     end
824   end
825   describe '順序入れ替えに於いて' do
826     before do
827       @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
828       @panel = FactoryGirl.create :panel_hello, author: @author_yas
829     end
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)
836         @item.t = nil
837         r = @item.rotate
838       end
839     end
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)
846         @item.t = 0
847         r = @item.rotate
848       end
849     end
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)
857         @item2.t = 0
858         r = @item.rotate 1
859       end
860     end
861     context 'オブジェクトが新規でなくtが空のとき' do
862       it '入れ替えもシフトもせず、tを空のままにしている' do
863         #結果、tに欠番が生じてシリアライズチェックでひっかかる
864       end
865     end
866   end
867   describe '保存に於いて' do
868     before do
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
873     end
874     #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
875     context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したとき' do
876       before 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
883       end
884       it '既存のt0には変化がない' do
885         @item6.store
886         @item.reload
887         expect(@item.t).to eq 0
888       end
889       it '既存のt1には変化がない' do
890         @item6.store
891         @item2.reload
892         expect(@item2.t).to eq 1
893       end
894       it '既存のt2を3にシフトしている' do
895         @item6.store
896         @item3.reload
897         expect(@item3.t).to eq 3
898       end
899       it '既存のt3を4にシフトしている' do
900         @item6.store
901         @item4.reload
902         expect(@item4.t).to eq 4
903       end
904       it '既存のt5を5にシフトしている' do
905         @item6.store
906         @item5.reload
907         expect(@item5.t).to eq 5
908       end
909       it '新規のt2が作成されている' do
910         @item6.store
911         @item6.reload
912         expect(@item6.t).to eq 2
913       end
914       it '他のスクロールに影響がない' do
915         @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
916         @item6.store
917         @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
918         expect(@after_status).to eq @ot
919       end
920     end
921     context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したとき' do
922       before 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
928         @ot = @item4.t
929         @item4.t = 1
930       end
931       it '既存のt0には変化がない' do
932         @item4.store @ot
933         @item.reload
934         expect(@item.t).to eq 0
935       end
936       it '既存のt4には変化がない' do
937         @item4.store @ot
938         @item5.reload
939         expect(@item5.t).to eq 4
940       end
941       it '既存のt1を2にシフトしている' do
942         @item4.store @ot
943         @item2.reload
944         expect(@item2.t).to eq 2
945       end
946       it '既存のt2を3にシフトしている' do
947         @item4.store @ot
948         @item3.reload
949         expect(@item3.t).to eq 3
950       end
951       it '既存のt3を1にシフトしている' do
952         @item4.store @ot
953         @item4.reload
954         expect(@item4.t).to eq 1
955       end
956       it '他のスクロールに影響がない' do
957         @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
958         @item4.store @ot
959         @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
960         expect(@after_status).to eq @ot
961       end
962     end
963     context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で1を3に移動したとき' do
964       before 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
970         @ot = @item2.t
971         @item2.t = 3
972       end
973       it '既存のt0には変化がない' do
974         @item2.store @ot
975         @item.reload
976         expect(@item.t).to eq 0
977       end
978       it '既存のt4には変化がない' do
979         @item2.store @ot
980         @item5.reload
981         expect(@item5.t).to eq 4
982       end
983       it '既存のt1を3にシフトしている' do
984         @item2.store @ot
985         @item2.reload
986         expect(@item2.t).to eq 3
987       end
988       it '既存のt2を1にシフトしている' do
989         @item2.store @ot
990         @item3.reload
991         expect(@item3.t).to eq 1
992       end
993       it '既存のt3を2にシフトしている' do
994         @item2.store @ot
995         @item4.reload
996         expect(@item4.t).to eq 2
997       end
998       it '他のスクロールに影響がない' do
999         @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
1000         @item2.store @ot
1001         @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
1002         expect(@after_status).to eq @ot
1003       end
1004     end
1005     #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1006     context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したが保存に失敗したとき' do
1007       before 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
1015       end
1016       it '既存のtに変化がない' do
1017         @item6.store
1018         @item.reload
1019         @item2.reload
1020         @item3.reload
1021         @item4.reload
1022         @item5.reload
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
1029         @itemc2.reload
1030         @itemc2.t.should eq 0
1031       end
1032       it 'falseを返す' do
1033         r = @item6.store
1034         expect(r).to be_false
1035       end
1036     end
1037     context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したがシリアルチェックに失敗したとき' do
1038       before 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
1045         @ot = @item4.t
1046         @item4.t = 1
1047       end
1048       it '既存のtに変化がない' do
1049         @item4.store @ot
1050         @item.reload
1051         @item.t.should eq 0
1052         @item2.reload
1053         @item2.t.should eq 1
1054         @item3.reload
1055         @item3.t.should eq 2
1056         @item4.reload
1057         @item4.t.should eq 3
1058         @item5.reload
1059         @item5.t.should eq 4
1060         @itemc2.reload
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
1068       end
1069       it 'falseを返す' do
1070         r = @item4.store @ot
1071         expect(r).to be_false
1072       end
1073       it 'tにエラーメッセージが入っている' do
1074         @item4.store @ot
1075         expect(@item4.errors[:t]).to be_empty
1076         expect(@item4.valid?).to be_true
1077       end
1078     end
1079   end
1080   describe '切り詰め処理つき削除に於いて' do
1081     before 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
1086     end
1087     context 'つつがなく終わるとき' do
1088       it '削除される' do
1089         expect {
1090           @item.destroy_and_shorten
1091         }.to change(ScrollPanel, :count ).by(-1)
1092       end
1093       it 'Trueを返す' do
1094         r = @item.destroy_and_shorten
1095         expect(r).to be_true 
1096       end
1097     end
1098     context '削除に失敗したとき' do
1099       before do
1100         ScrollPanel.any_instance.stub(:destroy).and_return(false)
1101       end
1102       it 'ロールバックされる' do
1103         expect {
1104           @item.destroy_and_shorten
1105         }.to change(ScrollPanel, :count )
1106       end
1107       it 'Falseを返す' do
1108         r = @item.destroy_and_shorten
1109         expect(r).to be_false
1110       end
1111     end
1112     #連携テスト。切り詰めが直接DBをいじる
1113     context '2件で先頭を削除したとき' do
1114       before do
1115         @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
1116       end
1117       it '行が削除される' do
1118         expect {
1119           @item.destroy_and_shorten
1120         }.to change(ScrollPanel, :count ).by(-1)
1121       end
1122       it '先頭は削除される' do
1123         @item.destroy_and_shorten
1124         expect {
1125           ScrollPanel.find @item.id
1126         }.to raise_error(ActiveRecord::RecordNotFound)
1127       end
1128       it '2件目は前に詰められる' do
1129         @item.destroy_and_shorten
1130         @item2.reload
1131         expect(@item2.t).to eq 0
1132       end
1133     end
1134     context '3件で先頭を削除したとき' do
1135       before 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
1138       end
1139       it '行が削除される' do
1140         expect {
1141           @item.destroy_and_shorten
1142         }.to change(ScrollPanel, :count ).by(-1)
1143       end
1144       it '先頭は削除される' do
1145         @item.destroy_and_shorten
1146         expect {
1147           ScrollPanel.find @item.id
1148         }.to raise_error(ActiveRecord::RecordNotFound)
1149       end
1150       it '2件目は前に詰められる' do
1151         @item.destroy_and_shorten
1152         @item2.reload
1153         expect(@item2.t).to eq 0
1154       end
1155       it '3件目は前に詰められる' do
1156         @item.destroy_and_shorten
1157         @item3.reload
1158         expect(@item3.t).to eq 1
1159       end
1160     end
1161     context '5件で3件目を削除したとき' do
1162       before 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
1167       end
1168       it '行が削除される' do
1169         expect {
1170           @item3.destroy_and_shorten
1171         }.to change(ScrollPanel, :count ).by(-1)
1172       end
1173       it '1件目は変化がない' do
1174         @item3.destroy_and_shorten
1175         @item.reload
1176         expect(@item.t).to eq 0
1177       end
1178       it '2件目は変化がない' do
1179         @item3.destroy_and_shorten
1180         @item2.reload
1181         expect(@item2.t).to eq 1
1182       end
1183       it '3件目は削除される' do
1184         @item3.destroy_and_shorten
1185         expect {
1186           ScrollPanel.find @item3.id
1187         }.to raise_error(ActiveRecord::RecordNotFound)
1188       end
1189       it '4件目は前に詰められる' do
1190         @item3.destroy_and_shorten
1191         @item4.reload
1192         expect(@item4.t).to eq 2
1193       end
1194       it '5件目は前に詰められる' do
1195         @item3.destroy_and_shorten
1196         @item5.reload
1197         expect(@item5.t).to eq 3
1198       end
1199     end
1200     #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1201   end
1202 end