1 # -*- encoding: utf-8 -*-
6 FactoryGirl.create :admin
7 @sp = FactoryGirl.create :system_picture
8 @lg = FactoryGirl.create :license_group
9 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @user = FactoryGirl.create( :user_yas)
11 @author = @user.author
12 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
13 @other_user = FactoryGirl.create( :user_yas)
14 @other_author = @other_user.author
19 @comic = FactoryGirl.create :comic, :author_id => @author.id
20 @panel = FactoryGirl.create :panel, :author_id => @author.id
21 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
24 it 'オーソドックスなデータなら通る' do
25 @story.should be_valid
28 context 'comic_idを検証するとき' do
30 @story.comic_id = @comic.id
31 @story.should be_valid
35 @story.should_not be_valid
39 @story.should_not be_valid
41 it '存在するコミックでなければ失敗する' do
43 @story.should_not be_valid
47 context 'panel_idを検証するとき' do
49 @story.panel_id = @panel.id
50 @story.should be_valid
54 @story.should_not be_valid
58 @story.should_not be_valid
60 it '存在するコマでなければ失敗する' do
62 @story.should_not be_valid
71 @story.should be_valid
75 @story.should_not be_valid
79 @story.should_not be_valid
83 @story.should_not be_valid
87 context 'author_idを検証するとき' do
89 @story.author_id = @author.id
90 @story.should be_valid
93 @story.author_id = nil
94 @story.should_not be_valid
97 @story.author_id = 'a'
98 @story.should_not be_valid
100 it '存在する作家でなければ失敗する' do
102 @story.should_not be_valid
105 context '全体を検証するとき' do
107 @story = FactoryGirl.create :story, :author_id => @author.id
112 describe 'デフォルト値補充に於いて' do
114 @comic = FactoryGirl.create :comic, :author_id => @author.id
115 @panel = FactoryGirl.create :panel, :author_id => @author.id
118 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
120 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
121 @story.supply_default
122 @story.t.should be_nil
127 describe '上書き補充に於いて' do
129 @comic = FactoryGirl.create :comic, :author_id => @author.id
130 @panel = FactoryGirl.create :panel, :author_id => @author.id
133 context 'author_idを補充' do
134 it '問答無用でauthor_idを補充する' do
135 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
136 @story.author_id = nil
137 @story.overwrite @author
138 @story.author_id.should eq @author.id
144 describe '作者判定に於いて' do
146 @comic = FactoryGirl.create :comic, :author_id => @author.id
147 @panel = FactoryGirl.create :panel, :author_id => @author.id
148 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
149 @comico = FactoryGirl.create :comic, :author_id => @other_author.id
150 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
151 @storyo = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id
153 it '自分のストーリーならyes' do
154 @story.own?(@author).should == true
157 @storyo.own?(@author).should == false
160 @story.own?(nil).should == false
163 describe '編集取得に於いて' do
165 @comic = FactoryGirl.create :comic, :author_id => @author.id
166 @panel = FactoryGirl.create :panel, :author_id => @author.id
167 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
170 l = Story.edit @story.id, @author
173 context '他人のストーリーを開こうとしたとき' do
174 it '403Forbidden例外を返す' do
175 Story.any_instance.stub(:own?).and_return(false)
177 Story.edit @story.id, @author
178 }.should raise_error(ActiveRecord::Forbidden)
181 context '存在しないストーリーを開こうとしたとき' do
182 it '404RecordNotFound例外を返す' do
184 Story.edit 110, @author
185 }.should raise_error(ActiveRecord::RecordNotFound)
190 describe '一覧取得に於いて' do
192 @comic = FactoryGirl.create :comic, :author_id => @author.id
193 @panel = FactoryGirl.create :panel, :author_id => @author.id
194 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
195 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
197 context 'offset補正について' do
198 it '文字列から数値に変換される' do
199 Story.offset(100, '8').should eq 8
202 Story.offset(100).should eq 0
204 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
206 it '1件のときオフセット1なら0になる' do
207 Story.offset(1, '1').should eq 0
209 it '5件のときオフセット5なら4になる' do
210 Story.offset(5, '5').should eq 4
212 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
213 #-4のときは、最後から4つのコマを表示する。
214 it '2件のときオフセット-1なら1になる' do
215 Story.offset(2, '-1').should eq 1
217 it '5件のときオフセット-2なら3になる' do
218 Story.offset(5, '-2').should eq 3
220 # 最終的なが負になるなど、不正な値が入ったときは0となる。
221 it '2件のときオフセット-5なら0になる' do
222 Story.offset(2, '-5').should eq 0
225 context 'panel_count補正について' do
226 it '文字列から数値に変換される' do
227 Story.panel_count(100, '7').should eq 7
229 it 'nilの場合はStory.default_panel_sizeになる' do
230 Story.panel_count(100).should eq Story.default_panel_size
232 it '0以下の場合はStory.default_panel_sizeになる' do
233 Story.panel_count(100, '0').should eq Story.default_panel_size
235 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
236 Story.panel_count(100, '1000').should eq Story.max_panel_size
240 c = Story.list @comic, @author
244 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
245 c = Story.list @comic, @author
246 c.should eq [ @story, v]
249 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
250 c = Story.list @comic, @author
251 c.should eq [ @story]
253 context 'DBに5件あって1ページの件数を2件に変えたとして' do
255 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
256 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
257 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
258 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
260 it 'offset=0なら末尾2件を返す' do
262 c = Story.list( @comic, @author, 0, 2)
263 c.should eq [@story, @story2]
265 it 'offset=2なら中間2件を返す' do
266 c = Story.list(@comic, @author, 2, 2)
267 c.should eq [@story3, @story4]
269 it 'offset=4なら先頭1件を返す' do
270 c = Story.list(@comic, @author, 4, 2)
271 c.should eq [@story5]
275 describe 'list関連テーブルプションに於いて' do
276 it 'includeキーを含んでいる' do
278 r.has_key?(:include).should be_true
281 r = Story.list_opt[:include]
282 r.should have(3).items
285 r = Story.list_opt[:include]
286 r.has_key?(:comic).should be_true
288 it 'コミックは作家を含んでいる' do
289 r = Story.list_opt[:include]
290 r[:comic].has_key?(:author).should be_true
293 r = Story.list_opt[:include]
294 r.has_key?(:author).should be_true
297 r = Story.list_opt[:include]
298 r.has_key?(:panel).should be_true
301 r = Story.list_opt[:include]
302 r[:panel].has_key?(:author).should be_true
305 r = Story.list_opt[:include]
306 r[:panel].has_key?(:panel_pictures).should be_true
308 it 'コマ絵は実素材を含んでいる' do
309 r = Story.list_opt[:include]
310 r[:panel][:panel_pictures].has_key?(:picture).should be_true
313 r = Story.list_opt[:include]
314 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
316 it '実素材はライセンスを含んでいる' do
317 r = Story.list_opt[:include]
318 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
320 it 'コマはフキダシを含んでいる' do
321 r = Story.list_opt[:include]
322 r[:panel].has_key?(:speech_balloons).should be_true
324 it 'フキダシはフキダシ枠を含んでいる' do
325 r = Story.list_opt[:include]
326 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
328 it 'フキダシはセリフを含んでいる' do
329 r = Story.list_opt[:include]
330 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
333 describe 'json一覧出力オプションに於いて' do
334 it 'includeキーを含んでいる' do
335 r = Story.list_json_opt
336 r.has_key?(:include).should be_true
339 r = Story.list_json_opt[:include]
340 r.should have(3).items
343 r = Story.list_json_opt[:include]
344 r.has_key?(:comic).should be_true
346 it 'コミックは作家を含んでいる' do
347 r = Story.list_json_opt[:include]
348 r[:comic].has_key?(:author).should be_true
351 r = Story.list_json_opt[:include]
352 r.has_key?(:author).should be_true
355 r = Story.list_json_opt[:include]
356 r.has_key?(:panel).should be_true
359 r = Story.list_json_opt[:include]
360 r[:panel].has_key?(:author).should be_true
363 r = Story.list_json_opt[:include]
364 r[:panel].has_key?(:panel_pictures).should be_true
366 it 'コマ絵は実素材を含んでいる' do
367 r = Story.list_json_opt[:include]
368 r[:panel][:panel_pictures].has_key?(:picture).should be_true
371 r = Story.list_json_opt[:include]
372 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
374 it '実素材はライセンスを含んでいる' do
375 r = Story.list_json_opt[:include]
376 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
378 it 'コマはフキダシを含んでいる' do
379 r = Story.list_json_opt[:include]
380 r[:panel].has_key?(:speech_balloons).should be_true
382 it 'フキダシはフキダシ枠を含んでいる' do
383 r = Story.list_json_opt[:include]
384 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
386 it 'フキダシはセリフを含んでいる' do
387 r = Story.list_json_opt[:include]
388 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
392 describe '自分のストーリー一覧取得に於いて' do
394 @comic = FactoryGirl.create :comic, :author_id => @author.id
395 @panel = FactoryGirl.create :panel, :author_id => @author.id
396 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
399 s = Story.mylist @author
403 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
404 sl = Story.mylist @author
405 sl.should eq [ns, @story]
407 it '他人のストーリーは含まない' do
408 cc = FactoryGirl.create :comic, :author_id => @other_author.id
409 pl = FactoryGirl.create :panel, :author_id => @other_author.id
410 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => cc.id, :panel_id => pl.id
411 sl = Story.mylist @author
412 sl.should eq [@story]
416 describe 't補充値に於いて' do
418 @comic = FactoryGirl.create :comic, :author_id => @author.id
419 @panel = FactoryGirl.create :panel, :author_id => @author.id
422 context 'コミック初のコマなら' do
424 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
426 r = Story.new_t @story.comic_id
430 context 'コミックに一個コマがあるとき' do
432 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
433 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
435 r = Story.new_t @story.comic_id
439 context 'コミックに2個コマがあるとき' do
441 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
442 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
443 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
445 r = Story.new_t @story.comic_id
450 describe 'シリアライズチェックに於いて' do
451 context 'つつがなく終わるとき' do
452 it '0からシリアライズされているならTrueを返す' do
453 r = Story.serial? [0, 1, 2]
456 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
457 r = Story.serial? [0, 2, 1]
460 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
461 r = Story.serial? [ 2, 1, 4, 3, 0]
466 it '0から始まらないならFalseを返す' do
467 r = Story.serial? [1, 2, 3]
470 it '連続していないならFalseを返す' do
471 r = Story.serial? [0, 1, 2, 4]
474 it '連続していないならFalseを返す' do
475 r = Story.serial? [0, 1, 2, 4, 5]
480 describe 't収集に於いて' do
482 @comic = FactoryGirl.create :comic, :author_id => @author.id
483 @panel = FactoryGirl.create :panel, :author_id => @author.id
484 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
485 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
486 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
488 context 'つつがなく終わるとき' do
489 it 'ストーリーから同一コミックのtだけを収集している' do
490 r = Story.collect_t @story
495 it 'ストーリーから同一コミックのtだけを収集している' do
496 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
497 r = Story.collect_t @story
498 r.sort.should eq [0, 1]
501 context '複数コマでヨソのコミックも混じっているとき' do
502 it 'ストーリーから同一コミックのtだけを収集している' do
503 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
504 r = Story.collect_t @story
505 r.sort.should eq [0, 1]
509 describe 'tチェックに於いて' do
511 @comic = FactoryGirl.create :comic, :author_id => @author.id
512 @panel = FactoryGirl.create :panel, :author_id => @author.id
513 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
515 context 'つつがなく終わるとき' do
517 Story.should_receive(:collect_t).with(any_args).exactly(1)
518 Story.stub(:collect_t).with(any_args).and_return([])
519 Story.stub(:serial?).with(any_args).and_return(true)
520 r = Story.validate_t @story
522 it '収集したtをシリアライズチェック依頼している' do
523 Story.stub(:collect_t).with(any_args).and_return([])
524 Story.should_receive(:serial?).with(any_args).exactly(1)
525 Story.stub(:serial?).with(any_args).and_return(true)
526 r = Story.validate_t @story
530 #依頼チェックだけでは不安なので最低限のチェックを
532 it '一件だけで正常通過している' do
533 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
534 r = Story.validate_t @story
539 it '2件目を作っても正常通過している' do
540 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
541 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
542 r = Story.validate_t @story2
547 describe '挿入シフトに於いて' do
549 @comic = FactoryGirl.create :comic, :author_id => @author.id
550 @panel = FactoryGirl.create :panel, :author_id => @author.id
554 it 'Updateを依頼している' do
555 Story.stub(:update_all).with(any_args)
556 Story.should_receive(:update_all).with(any_args).exactly(1)
557 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
561 context 'テーブルに1件(t:0)で0に挿入したとき' do
563 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
564 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
566 it '既存の行を1にシフトしている' do
569 l.first.t.should eq 1
571 it 'これから挿入するt(0)が欠番になっている' do
573 l = Story.find(:all).map {|s| s.t }
574 l.include?(0).should_not be_true
577 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
579 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
580 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
581 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
583 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
585 l = Story.find(:all).map {|s| s.t }
586 l.sort.should eq [0, 2]
589 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
591 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
592 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
593 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
594 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
595 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
596 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
598 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
600 l = Story.find(:all).map {|s| s.t }
601 l.sort.should eq [0, 1, 3, 4, 5]
604 context '先ほどのケース+他のコミック1件で挿入したとき' do
606 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
607 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
608 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
609 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
610 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
611 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
612 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
613 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
615 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
617 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
618 l.sort.should eq [0, 1, 3, 4, 5]
624 @storyc2.t.should eq ot
628 describe '少ない方に移動に於いて' do
630 @comic = FactoryGirl.create :comic, :author_id => @author.id
631 @panel = FactoryGirl.create :panel, :author_id => @author.id
634 it 'Updateを依頼している' do
635 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
636 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
637 Story.stub(:update_all).with(any_args)
638 Story.should_receive(:update_all).with(any_args).exactly(1)
641 @story2.lesser_shift ot
644 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
646 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
647 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
651 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
653 @story2.lesser_shift @ot
654 l = Story.find(:all).map {|s| s.t }
655 l.sort.should eq [1, 1]
657 it '既存のt0を1にシフトしている' do
658 @story2.lesser_shift @ot
663 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
665 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
666 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
667 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
671 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
673 @story3.lesser_shift @ot
674 l = Story.find(:all).map {|s| s.t }
675 l.sort.should eq [0, 2, 2]
677 it '既存のt1を2にシフトしている' do
678 @story3.lesser_shift @ot
680 @story2.t.should eq 2
683 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
685 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
686 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
687 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
688 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
689 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
693 it 'これから挿入するt(1)が欠番になっている' do
695 @story4.lesser_shift @ot
696 l = Story.find(:all).map {|s| s.t }
697 l.sort.should eq [0, 2, 3, 3, 4]
700 @story4.lesser_shift @ot
705 @story4.lesser_shift @ot
707 @story5.t.should eq 4
709 it '既存のt1を2にシフトしている' do
710 @story4.lesser_shift @ot
712 @story2.t.should eq 2
714 it '既存のt2を3にシフトしている' do
715 @story4.lesser_shift @ot
717 @story3.t.should eq 3
720 context '先ほどのケース+他のコミック1件で挿入したとき' do
722 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
723 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
724 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
725 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
726 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
727 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
728 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
732 it 'これから挿入するt(1)が欠番になっている' do
733 @story4.lesser_shift @ot
734 l = Story.find(:all).map {|s| s.t }
735 l.sort.should eq [0, 0, 2, 3, 3, 4]
738 @story4.lesser_shift @ot
743 @story4.lesser_shift @ot
745 @story5.t.should eq 4
747 it '既存のt1を2にシフトしている' do
748 @story4.lesser_shift @ot
750 @story2.t.should eq 2
752 it '既存のt2を3にシフトしている' do
753 @story4.lesser_shift @ot
755 @story3.t.should eq 3
758 @story4.lesser_shift @ot
760 @storyc2.t.should eq 0
765 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
767 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
768 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
772 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
774 @story2.lesser_shift @ot
775 l = Story.find(:all).map {|s| s.t }
776 l.sort.should eq [1, 1]
778 it '既存のt0を1にシフトしている' do
779 @story2.lesser_shift @ot
783 it '既存のt1は0に補正されている' do
784 @story2.lesser_shift @ot
785 @story2.t.should eq 0
789 describe '大きい方に移動に於いて' do
791 @comic = FactoryGirl.create :comic, :author_id => @author.id
792 @panel = FactoryGirl.create :panel, :author_id => @author.id
795 it 'Updateを依頼している' do
796 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
797 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
798 Story.stub(:update_all).with(any_args)
799 Story.should_receive(:update_all).with(any_args).exactly(1)
802 @story.higher_shift ot
805 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
807 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
808 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
812 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
814 @story.higher_shift @ot
815 l = Story.find(:all).map {|s| s.t }
816 l.sort.should eq [0, 0]
818 it '既存のt1を0にシフトしている' do
819 @story.higher_shift @ot
821 @story2.t.should eq 0
824 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
826 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
827 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
828 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
832 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
834 @story.higher_shift @ot
835 l = Story.find(:all).map {|s| s.t }
836 l.sort.should eq [0, 0, 2]
838 it '既存のt1を0にシフトしている' do
839 @story.higher_shift @ot
841 @story2.t.should eq 0
844 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
846 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
847 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
848 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
849 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
850 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
854 it 'これから挿入するt(3)が欠番になっている' do
856 @story2.higher_shift @ot
857 l = Story.find(:all).map {|s| s.t }
858 l.sort.should eq [0, 1, 1, 2, 4]
861 @story2.higher_shift @ot
866 @story2.higher_shift @ot
868 @story5.t.should eq 4
870 it '既存のt2を1にシフトしている' do
871 @story2.higher_shift @ot
873 @story3.t.should eq 1
875 it '既存のt3を2にシフトしている' do
876 @story2.higher_shift @ot
878 @story4.t.should eq 2
881 context '先ほどのケース+他のコミック1件で挿入したとき' do
883 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
884 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
885 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
886 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
887 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
888 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
889 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
893 it 'これから挿入するt(3)が欠番になっている' do
895 @story2.higher_shift @ot
896 l = Story.find(:all).map {|s| s.t }
897 l.sort.should eq [0, 0, 1, 1, 2, 4]
900 @story2.higher_shift @ot
905 @story2.higher_shift @ot
907 @story5.t.should eq 4
909 it '既存のt2を1にシフトしている' do
910 @story2.higher_shift @ot
912 @story3.t.should eq 1
914 it '既存のt3を2にシフトしている' do
915 @story2.higher_shift @ot
917 @story4.t.should eq 2
920 @story2.higher_shift @ot
922 @storyc2.t.should eq 0
927 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
929 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
930 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
934 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
936 @story.higher_shift @ot
937 l = Story.find(:all).map {|s| s.t }
938 l.sort.should eq [0, 0]
940 it '既存のt1を0にシフトしている' do
941 @story.higher_shift @ot
943 @story2.t.should eq 0
945 it '既存のt0は1に補正されている' do
946 @story.higher_shift @ot
951 describe '入れ替えに於いて' do
953 @comic = FactoryGirl.create :comic, :author_id => @author.id
954 @panel = FactoryGirl.create :panel, :author_id => @author.id
955 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
956 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
958 context '新tが旧tより小さいとき' do
959 it '少ない方に移動を依頼している' do
960 Story.any_instance.stub(:lesser_shift).with(any_args)
961 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
964 @story2.update_shift ot
967 context '新tが旧tより大きいとき' do
968 it '大きい方に移動を依頼している' do
969 Story.any_instance.stub(:higher_shift).with(any_args)
970 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
973 @story.update_shift ot
977 describe '順序入れ替えに於いて' do
979 @comic = FactoryGirl.create :comic, :author_id => @author.id
980 @panel = FactoryGirl.create :panel, :author_id => @author.id
982 context 'オブジェクトが新規でtが空のとき' do
983 it '末尾追加としてtを補充依頼している' do
984 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
985 Story.stub(:new_t).with(any_args).and_return(0)
986 Story.should_receive(:new_t).with(any_args).exactly(1)
991 context 'オブジェクトが新規でtが設定されているとき' do
992 it '挿入追加として挿入シフトを依頼している' do
993 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
994 Story.any_instance.stub(:insert_shift).with(any_args)
995 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1000 context 'オブジェクトが新規でなくtが設定されているとき' do
1001 it 'コマ移動として入れ替えを依頼している' do
1002 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1003 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1004 Story.any_instance.stub(:update_shift).with(any_args)
1005 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1010 context 'オブジェクトが新規でなくtが空のとき' do
1011 it '入れ替えもシフトもせず、tを空のままにしている' do
1012 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1016 describe '編集許可に於いて' do
1018 @comic = FactoryGirl.create :comic, :author_id => @author.id
1019 @panel = FactoryGirl.create :panel, :author_id => @author.id
1020 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1022 context 'つつがなく終わるとき' do
1028 context 'コミックで引っかかるとき' do
1030 @story.comic_id = nil
1035 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1040 context 'コマで引っかかるとき' do
1042 @story.panel_id = nil
1047 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1053 describe '保存に於いて' do
1055 @comic = FactoryGirl.create :comic, :author_id => @author.id
1056 @panel = FactoryGirl.create :panel, :author_id => @author.id
1057 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1059 context 'つつがなく終わるとき' do
1060 it '編集許可チェックを依頼している' do
1061 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1062 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1065 it '順序入れ替えを依頼している' do
1066 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1067 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1068 Story.any_instance.stub(:save).with(any_args).and_return(true)
1069 Story.stub(:validate_t).with(any_args).and_return(true)
1073 Story.stub(:new_t).with(any_args).and_return(0)
1074 Story.any_instance.stub(:save).with(any_args).and_return(true)
1075 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1076 Story.stub(:validate_t).with(any_args).and_return(true)
1079 it 'tのシリアライズチェックを依頼している' do
1080 Story.stub(:new_t).with(any_args).and_return(0)
1081 Story.any_instance.stub(:save).with(any_args).and_return(true)
1082 Story.stub(:validate_t).with(any_args).and_return(true)
1083 Story.should_receive(:validate_t).with(any_args).exactly(1)
1087 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1088 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1090 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1091 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1092 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1093 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1094 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1095 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1096 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1097 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1099 it '既存のt0には変化がない' do
1102 @story.t.should eq 0
1104 it '既存のt1には変化がない' do
1107 @story2.t.should eq 1
1109 it '既存のt2を3にシフトしている' do
1112 @story3.t.should eq 3
1114 it '既存のt3を4にシフトしている' do
1117 @story4.t.should eq 4
1119 it '既存のt5を5にシフトしている' do
1122 @story5.t.should eq 5
1124 it '新規のt2が作成されている' do
1127 @story6.t.should eq 2
1129 it '他のコミックに影響がない' do
1133 @storyc2.t.should eq @ot
1136 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1138 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1139 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1140 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1141 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1142 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1143 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1144 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1148 it '既存のt0には変化がない' do
1151 @story.t.should eq 0
1153 it '既存のt4には変化がない' do
1156 @story5.t.should eq 4
1158 it '既存のt1を2にシフトしている' do
1161 @story2.t.should eq 2
1163 it '既存のt2を3にシフトしている' do
1166 @story3.t.should eq 3
1168 it '既存のt3を1にシフトしている' do
1171 @story4.t.should eq 1
1173 it '他のコミックに影響がない' do
1176 @storyc2.t.should eq 0
1179 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1181 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1182 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1183 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1184 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1185 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1186 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1187 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1191 it '既存のt0には変化がない' do
1194 @story.t.should eq 0
1196 it '既存のt4には変化がない' do
1199 @story5.t.should eq 4
1201 it '既存のt1を3にシフトしている' do
1204 @story2.t.should eq 3
1206 it '既存のt2を1にシフトしている' do
1209 @story3.t.should eq 1
1211 it '既存のt3を2にシフトしている' do
1214 @story4.t.should eq 2
1216 it '他のコミックに影響がない' do
1219 @storyc2.t.should eq 0
1222 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1223 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1225 Story.any_instance.stub(:save).with(any_args).and_return(false)
1226 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1227 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1228 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1229 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1230 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1231 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1232 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1233 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1238 @story.t.should eq 0
1240 @story2.t.should eq 1
1242 @story3.t.should eq 2
1244 @story4.t.should eq 3
1246 @story5.t.should eq 4
1248 @storyc2.t.should eq 0
1255 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1257 Story.stub(:validate_t).with(any_args).and_return(false)
1258 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1259 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1260 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1261 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1262 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1263 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1264 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1271 @story.t.should eq 0
1273 @story2.t.should eq 1
1275 @story3.t.should eq 2
1277 @story4.t.should eq 3
1279 @story5.t.should eq 4
1281 @storyc2.t.should eq 0
1284 r = @story4.store @ot
1287 it 'tにエラーメッセージが入っている' do
1289 @story4.errors[:t].should_not be_empty
1290 @story4.valid?.should be_true
1293 context '編集不可だったとき' do
1295 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1296 Story.any_instance.stub(:allow?).and_return(false)
1298 it '403Forbidden例外を返す' do
1301 }.should raise_error(ActiveRecord::Forbidden)
1305 describe '切り詰め処理つき削除に於いて' do
1307 @comic = FactoryGirl.create :comic, :author_id => @author.id
1308 @panel = FactoryGirl.create :panel, :author_id => @author.id
1309 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1311 context 'つつがなく終わるとき' do
1314 @story.destroy_and_shorten
1315 }.should change(Story, :count ).by(-1)
1318 #連携テスト。切り詰めが直接DBをいじる
1319 context '2件で先頭を削除したとき' do
1321 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1325 @story.destroy_and_shorten
1326 }.should change(Story, :count ).by(-1)
1329 @story.destroy_and_shorten
1331 Story.find @story.id
1332 }.should raise_error(ActiveRecord::RecordNotFound)
1335 @story.destroy_and_shorten
1337 @story2.t.should eq 0
1340 context '3件で先頭を削除したとき' do
1342 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1343 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1347 @story.destroy_and_shorten
1348 }.should change(Story, :count ).by(-1)
1351 @story.destroy_and_shorten
1353 Story.find @story.id
1354 }.should raise_error(ActiveRecord::RecordNotFound)
1357 @story.destroy_and_shorten
1359 @story2.t.should eq 0
1362 @story.destroy_and_shorten
1364 @story3.t.should eq 1
1367 context '5件で3件目を削除したとき' do
1369 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1370 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1371 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1372 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1376 @story3.destroy_and_shorten
1377 }.should change(Story, :count ).by(-1)
1380 @story3.destroy_and_shorten
1382 @story.t.should eq 0
1385 @story3.destroy_and_shorten
1387 @story2.t.should eq 1
1390 @story3.destroy_and_shorten
1392 Story.find @story3.id
1393 }.should raise_error(ActiveRecord::RecordNotFound)
1396 @story3.destroy_and_shorten
1398 @story4.t.should eq 2
1401 @story3.destroy_and_shorten
1403 @story5.t.should eq 3
1406 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する