@storyc2.t.should eq 0
end
end
+ #例外ケース。
+ #負のときは0として正常扱い
+ context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
+ before do
+ @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @ot = @story2.t
+ @story2.t = -1
+ end
+ it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
+ #移動させたい行はそのまま残る
+ @story2.lesser_shift @ot
+ l = Story.find(:all).map {|s| s.t }
+ l.sort.should eq [1, 1]
+ end
+ it '既存のt0を1にシフトしている' do
+ @story2.lesser_shift @ot
+ @story.reload
+ @story.t.should eq 1
+ end
+ it '既存のt1は0に補正されている' do
+ @story2.lesser_shift @ot
+ @story2.t.should eq 0
+ end
+ end
end
describe '大きい方に移動に於いて' do
before do
@storyc2.t.should eq 0
end
end
+ #例外ケース。
+ #max超えたときはmaxとして正常扱い
+ context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
+ before do
+ @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story2 = Factory :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @ot = @story.t
+ @story.t = 2
+ end
+ it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
+ #移動させたい行はそのまま残る
+ @story.higher_shift @ot
+ l = Story.find(:all).map {|s| s.t }
+ l.sort.should eq [0, 0]
+ end
+ it '既存のt1を0にシフトしている' do
+ @story.higher_shift @ot
+ @story2.reload
+ @story2.t.should eq 0
+ end
+ it '既存のt0は1に補正されている' do
+ @story.higher_shift @ot
+ @story.t.should eq 1
+ end
+ end
end
describe '入れ替えに於いて' do
before do