OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / spec / peta / leaf_spec.rb
index ebaee0f..86b3796 100644 (file)
@@ -20,49 +20,49 @@ describe ScrollPanel do
     before do
     end
     
-    it 'ぶら下がるそれぞれのリーフを取得できる' do
+    it '親モデルであるバインダーを取得している' do
       expect(@model.parent_model).to eq Scroll
     end
-    it 'すべてのリーフを取得できる' do
+    it '差し込むコンテンツのモデルを取得している' do
       expect(@model.destination_model).to eq Panel
     end
     
-    it 'ã\81¶ã\82\89ä¸\8bã\81\8cã\82\8bã\81\9dã\82\8cã\81\9eã\82\8cã\81®ã\83ªã\83¼ã\83\95ã\82\92å\8f\96å¾\97ã\81§ã\81\8dる' do
+    it 'ã\83\90ã\82¤ã\83³ã\83\80ã\83¼ã\82\92å\8f\96å¾\97ã\81\99ã\82\8bã\81\9fã\82\81ã\81®IDã\81®ã\82«ã\83©ã\83 ã\82\92è¿\94ã\81\97ã\81¦ã\81\84る' do
       expect(@model.binder_key).to eq 'scroll_id'
     end
     
-    it 'ぶら下がるそれぞれのリーフを取得できる' do
+    it '差し込むコンテンツを取得するためのIDのカラムを返している' do
       expect(@model.destination_key).to eq 'panel_id'
     end
     
   end
   
-  describe 'myに於いて' do
+  describe '便利機能に於いて' do
     before do
     end
     
-    it '名前の活用に於いて' do
+    it 'バインダーのIDを返している' do
       expect(@item.binder_id).to eq @scroll.id
     end
     
-    it 'å\90\8då\89\8dã\81®æ´»ç\94¨ã\81«æ\96¼ã\81\84ã\81¦' do
+    it 'å·®ã\81\97è¾¼ã\82\80ã\82³ã\83³ã\83\86ã\83³ã\83\84ã\81®IDã\82\92è¿\94ã\81\97ã\81¦ã\81\84ã\82\8b' do
       expect(@item.destination_id).to eq @panel.id
     end
   end
   
-  describe 'cutに於いて' do
-    it 'cut' do
+  describe 'クラスメソッドへのショートカットに於いて' do
+    it 'binder_keyメソッドを呼び出せる' do
       expect(@item.binder_key).to eq @model.binder_key
     end
     
-    it 'cut' do
+    it 'destination_keyメソッドを呼び出せる' do
       expect(@item.destination_key).to eq @model.destination_key
     end
     
   end
   
   describe 'playに於いて' do
-    it 'cut' do
+    it '時系列でソートできるようなSQLを返している' do
       expect(@model.play_list_order).to eq 'scroll_panels.t'
     end
     
@@ -318,40 +318,42 @@ describe StorySheet do
     # insert_shift, lesser_shift, higher_shift, update_shift, rotate
 end
 
-# 
+# I/O処理については、マニフェストで動作が変わることがないのでスクロールとスクコマでのみテストしておく
 describe ScrollPanel do
   include LeafMacros
   before do
-    @admin =FactoryGirl.create :admin
+    @admin = FactoryGirl.create :admin
     @user_yas = FactoryGirl.create :user_yas_with_owner
     @user_rom = FactoryGirl.create :user_rom
-    @author_yas =  @user_yas.author
+    @author_yas = @user_yas.author
     
     @model = ScrollPanel
   end
   
-  describe 'new_tに於いて' do
+  describe 't補充値new_tに於いて' do
     before do
-      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @dummy =  FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
+      @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
     
-    context 'ã\82ªã\83¼ã\82½ã\83\89ã\83\83ã\82¯ã\82¹ã\81ªã\83\87ã\83¼ã\82¿ã\81®ã\81¨ã\81\8d' do
-      it 'cut' do
+    context 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«å\88\9dã\81®ã\82³ã\83\9eã\81ªã\82\89' do
+      it '0を補充値とする' do
         expect(@model.new_t(@scroll.id)).to eq 0
       end
       
     end
     
-    context 'ã\82ªã\83¼ã\82½ã\83\89ã\83\83ã\82¯ã\82¹ã\81ªã\83\87ã\83¼ã\82¿ã\81®とき' do
-      it 'cut' do
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
+    context 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«ã\81«ã\82³ã\83\9eã\81\8cã\81\82ã\82\8bとき' do
+      it '一個なら1を補充値とする' do
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
         expect(@model.new_t(@scroll.id)).to eq 1
       end
       
-      it 'cut' do
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 2, t: 1, scroll: @scroll, panel: @panel
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 3, t: 2, scroll: @scroll, panel: @panel
+      it '3個なら3を補充値とする' do
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
         expect(@model.new_t(@scroll.id)).to eq 3
       end
       
@@ -359,29 +361,30 @@ describe ScrollPanel do
     
   end
   
-  describe 'collect_tに於いて' do
+  describe 't収集collect_tに於いて' do
     before do
       @dummy =  FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
       @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
     
-    context 'オーソドックスなデータのとき' do
-      it 'cut' do
+    context '空っぽのスクロールのとき' do
+      it '当然リストは空っぽになっている' do
         expect(@model.collect_t(@scroll.id)).to be_empty
       end
       
     end
     
     context 'オーソドックスなデータのとき' do
-      it 'cut' do
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
+      it 'スクコマから同一スクロールのtだけを収集している' do
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
         expect(@model.collect_t(@scroll.id)).to eq [0]
       end
       
-      it 'cut' do
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 2, t: 1, scroll: @scroll, panel: @panel
-        @item =  FactoryGirl.create :scroll_panel_plain, z: 3, t: 2, scroll: @scroll, panel: @panel
+      it 'スクコマから同一スクロールのtだけを収集している' do
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
         expect(@model.collect_t(@scroll.id)).to eq [0, 1, 2]
       end
       
@@ -391,192 +394,151 @@ describe ScrollPanel do
   
   describe 'tチェックに於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-      @item = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-    end
-    context 'つつがなく終わるとき' do
-      it 't収集を依頼している' do
-        SheetPanel.should_receive(:collect_t).with(any_args).exactly(1)
-        SheetPanel.stub(:collect_t).with(any_args).and_return([])
-        SheetPanel.stub(:serial?).with(any_args).and_return(true)
-        r = SheetPanel.validate_t @item
-      end
-      it '収集したtをシリアライズチェック依頼している' do
-        SheetPanel.stub(:collect_t).with(any_args).and_return([])
-        SheetPanel.should_receive(:serial?).with(any_args).exactly(1)
-        SheetPanel.stub(:serial?).with(any_args).and_return(true)
-        r = SheetPanel.validate_t @item
-      end
+      @dummy =  FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
-    #実データでチェック
-    #依頼チェックだけでは不安なので最低限のチェックを
+    #実データで最低限のチェックを
     context '新規のとき' do
       it '一件だけで正常通過している' do
-        @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
-        r = SheetPanel.validate_t @item
-        r.should be_true 
+        @item =  FactoryGirl.build :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        r = ScrollPanel.validate_t @item
+        expect(r).to be_true 
       end
     end
     context '既存のとき' do
       it '2件目を作っても正常通過している' do
-        @item = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
-        @item2 = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
-        r = SheetPanel.validate_t @item2
-        r.should be_true 
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.build :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        r = ScrollPanel.validate_t @item2
+        expect(r).to be_true 
       end
     end
   end
   describe '挿入シフトに於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-    end
-    context '依頼チェック' do
-      #テーブルが空で0に挿入
-      it 'Updateを依頼している' do
-        SheetPanel.stub(:update_all).with(any_args)
-        SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
-        @item = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item.insert_shift
-      end
+      @dummy_scroll =  FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
     context 'テーブルに1件(t:0)で0に挿入したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.build :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
       end
       it '既存の行を1にシフトしている' do
         @item2.insert_shift
-        l = SheetPanel.find :all
-        l.first.t.should eq 1
+        @item.reload
+        expect(@item.t).to eq 1
       end
       it 'これから挿入するt(0)が欠番になっている' do
         @item2.insert_shift
-        l = SheetPanel.find(:all).map {|s| s.t }
-        l.include?(0).should_not be_true
+        @item.reload
+        expect(@item2.t).to eq 0
       end
     end
     context 'テーブルに2件(t:0,1)で1に挿入したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.build :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
       end
       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
         @item3.insert_shift
-        l = SheetPanel.find(:all).map {|s| s.t }
-        l.sort.should eq [0, 2]
+        @item.reload
+        @item2.reload
+        expect(@item.t).to eq 0
+        expect(@item2.t).to eq 2
       end
     end
     context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-      end
-      it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
-        @item6.insert_shift
-        l = SheetPanel.find(:all).map {|s| s.t }
-        l.sort.should eq [0, 1, 3, 4, 5]
-      end
-    end
-    context '先ほどのケース+他の用紙1件で挿入したとき' do
-      before do
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
+        @item6 =  FactoryGirl.build :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
       end
       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
         @item6.insert_shift
-        l = SheetPanel.find(:all, :conditions => ['sheet_id = ?', @sheet.id]).map {|s| s.t }
-        l.sort.should eq [0, 1, 3, 4, 5]
-      end
-      it '他の用紙に影響がない' do
-        ot = @itemc2.t
-        @item6.insert_shift
-        @itemc2.reload
-        @itemc2.t.should eq ot
+        @item.reload
+        @item2.reload
+        @item3.reload
+        @item4.reload
+        @item5.reload
+        expect(@item.t).to eq 0
+        expect(@item2.t).to eq 1
+        expect(@item3.t).to eq 3
+        expect(@item4.t).to eq 4
+        expect(@item5.t).to eq 5
       end
     end
   end
   describe '少ない方に移動に於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-    end
-    context '依頼チェック' do
-      it 'Updateを依頼している' do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        SheetPanel.stub(:update_all).with(any_args)
-        SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
-        ot = @item2.t
-        @item2.t = 0
-        @item2.lesser_shift ot
-      end
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
     context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
         @ot = @item2.t
         @item2.t = 0
       end
       it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item2.lesser_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
-        l.sort.should eq [1, 1]
+        @item.reload
+        @item2.reload
+        expect(@item.t).to eq 1
+        expect(@item2.t).to eq 1
       end
       it '既存のt0を1にシフトしている' do
         @item2.lesser_shift @ot
         @item.reload
-        @item.t.should eq 1
+        expect(@item.t).to eq 1
       end
     end
     context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
         @ot = @item3.t
         @item3.t = 1
       end
       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item3.lesser_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
-        l.sort.should eq [0, 2, 2]
+        @item.reload
+        @item2.reload
+        @item3.reload
+        expect(@item.t).to eq 0
+        expect(@item2.t).to eq 2
+        expect(@item3.t).to eq 2
       end
       it '既存のt1を2にシフトしている' do
         @item3.lesser_shift @ot
         @item2.reload
-        @item2.t.should eq 2
+        expect(@item2.t).to eq 2
       end
     end
     context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
         @ot = @item4.t
         @item4.t = 1
       end
       it 'これから挿入するt(1)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item4.lesser_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [0, 2, 3, 3, 4]
       end
       it '既存のt0には変化がない' do
@@ -600,21 +562,19 @@ describe ScrollPanel do
         @item3.t.should eq 3
       end
     end
-    context '先ほどのケース+他の用紙1件で挿入したとき' do
+    context '先ほどのケース+他のスクロール1件で挿入したとき' do
       before do
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
         @ot = @item4.t
         @item4.t = 1
       end
       it 'これから挿入するt(1)が欠番になっている' do
         @item4.lesser_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [0, 0, 2, 3, 3, 4]
       end
       it '既存のt0には変化がない' do
@@ -637,7 +597,7 @@ describe ScrollPanel do
         @item3.reload
         @item3.t.should eq 3
       end
-      it '他の用紙に影響がない' do
+      it '他のスクロールに影響がない' do
         @item4.lesser_shift @ot
         @itemc2.reload
         @itemc2.t.should eq 0
@@ -647,15 +607,16 @@ describe ScrollPanel do
     #負のときは0として正常扱い
     context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
         @ot = @item2.t
         @item2.t = -1
       end
       it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item2.lesser_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [1, 1]
       end
       it '既存のt0を1にシフトしている' do
@@ -671,15 +632,16 @@ describe ScrollPanel do
   end
   describe '大きい方に移動に於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
     context '依頼チェック' do
       it 'Updateを依頼している' do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        SheetPanel.stub(:update_all).with(any_args)
-        SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        ScrollPanel.stub(:update_all).with(any_args)
+        ScrollPanel.should_receive(:update_all).with(any_args).exactly(1)
         ot = @item.t
         @item.t = 1
         @item.higher_shift ot
@@ -687,15 +649,16 @@ describe ScrollPanel do
     end
     context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
         @ot = @item.t
         @item.t = 1
       end
       it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item.higher_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [0, 0]
       end
       it '既存のt1を0にシフトしている' do
@@ -706,16 +669,16 @@ describe ScrollPanel do
     end
     context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
         @ot = @item.t
         @item.t = 1
       end
       it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item.higher_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [0, 0, 2]
       end
       it '既存のt1を0にシフトしている' do
@@ -726,18 +689,18 @@ describe ScrollPanel do
     end
     context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
         @ot = @item2.t
         @item2.t = 3
       end
       it 'これから挿入するt(3)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item2.higher_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [0, 1, 1, 2, 4]
       end
       it '既存のt0には変化がない' do
@@ -761,22 +724,22 @@ describe ScrollPanel do
         @item4.t.should eq 2
       end
     end
-    context '先ほどのケース+他の用紙1件で挿入したとき' do
+    context '先ほどのケース+他のスクロール1件で挿入したとき' do
       before do
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
+        @itemc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
         @ot = @item2.t
         @item2.t = 3
       end
       it 'これから挿入するt(3)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item2.higher_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [0, 0, 1, 1, 2, 4]
       end
       it '既存のt0には変化がない' do
@@ -799,7 +762,7 @@ describe ScrollPanel do
         @item4.reload
         @item4.t.should eq 2
       end
-      it '他の用紙に影響がない' do
+      it '他のスクロールに影響がない' do
         @item2.higher_shift @ot
         @itemc2.reload
         @itemc2.t.should eq 0
@@ -809,15 +772,16 @@ describe ScrollPanel do
     #max超えたときはmaxとして正常扱い
     context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
       before do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
         @ot = @item.t
         @item.t = 2
       end
       it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
         #移動させたい行はそのまま残る
         @item.higher_shift @ot
-        l = SheetPanel.find(:all).map {|s| s.t }
+        l = ScrollPanel.find(:all).map {|s| s.t }
         l.sort.should eq [0, 0]
       end
       it '既存のt1を0にシフトしている' do
@@ -833,15 +797,16 @@ describe ScrollPanel do
   end
   describe '入れ替えに於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-      @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-      @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+      @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+      @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
     end
     context '新tが旧tより小さいとき' do
       it '少ない方に移動を依頼している' do
-        SheetPanel.any_instance.stub(:lesser_shift).with(any_args)
-        SheetPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
+        ScrollPanel.any_instance.stub(:lesser_shift).with(any_args)
+        ScrollPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
         ot = @item2.t
         @item2.t = 0
         @item2.update_shift ot
@@ -849,8 +814,8 @@ describe ScrollPanel do
     end
     context '新tが旧tより大きいとき' do
       it '大きい方に移動を依頼している' do
-        SheetPanel.any_instance.stub(:higher_shift).with(any_args)
-        SheetPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
+        ScrollPanel.any_instance.stub(:higher_shift).with(any_args)
+        ScrollPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
         ot = @item.t
         @item.t = 1
         @item.update_shift ot
@@ -859,33 +824,36 @@ describe ScrollPanel do
   end
   describe '順序入れ替えに於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
     context 'オブジェクトが新規でtが空のとき' do
       it '末尾追加としてtを補充依頼している' do
-        @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        SheetPanel.stub(:new_t).with(any_args).and_return(0)
-        SheetPanel.should_receive(:new_t).with(any_args).exactly(1)
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        ScrollPanel.stub(:new_t).with(any_args).and_return(0)
+        ScrollPanel.should_receive(:new_t).with(any_args).exactly(1)
         @item.t = nil
         r = @item.rotate
       end
     end
     context 'オブジェクトが新規でtが設定されているとき' do
       it '挿入追加として挿入シフトを依頼している' do
-        @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        SheetPanel.any_instance.stub(:insert_shift).with(any_args)
-        SheetPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        ScrollPanel.any_instance.stub(:insert_shift).with(any_args)
+        ScrollPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
         @item.t = 0
         r = @item.rotate
       end
     end
     context 'オブジェクトが新規でなくtが設定されているとき' do
       it 'コマ移動として入れ替えを依頼している' do
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        SheetPanel.any_instance.stub(:update_shift).with(any_args)
-        SheetPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+        ScrollPanel.any_instance.stub(:update_shift).with(any_args)
+        ScrollPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
         @item2.t = 0
         r = @item.rotate 1
       end
@@ -898,216 +866,182 @@ describe ScrollPanel do
   end
   describe '保存に於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-      @item = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-    end
-    context 'つつがなく終わるとき' do
-      it '編集許可チェックを依頼している' do
-        SheetPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
-        SheetPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
-        r = @item.store
-      end
-      it '順序入れ替えを依頼している' do
-        SheetPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
-        SheetPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
-        SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
-        SheetPanel.stub(:validate_t).with(any_args).and_return(true)
-        r = @item.store 
-      end
-      it '保存を依頼している' do
-        SheetPanel.stub(:new_t).with(any_args).and_return(0)
-        SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
-        SheetPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
-        SheetPanel.stub(:validate_t).with(any_args).and_return(true)
-        r = @item.store
-      end
-      it 'tのシリアライズチェックを依頼している' do
-        SheetPanel.stub(:new_t).with(any_args).and_return(0)
-        SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
-        SheetPanel.stub(:validate_t).with(any_args).and_return(true)
-        SheetPanel.should_receive(:validate_t).with(any_args).exactly(1)
-        r = @item.store
-      end
+      @dummy_scroll =  FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
+      @dummy_scroll_panels = @dummy_scroll.scroll_panels
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
     end
     #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
-    context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したとき' do
+    context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したとき' do
       before do
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
+        @item6 =  FactoryGirl.build :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
       end
       it '既存のt0には変化がない' do
         @item6.store
         @item.reload
-        @item.t.should eq 0
+        expect(@item.t).to eq 0
       end
       it '既存のt1には変化がない' do
         @item6.store
         @item2.reload
-        @item2.t.should eq 1
+        expect(@item2.t).to eq 1
       end
       it '既存のt2を3にシフトしている' do
         @item6.store
         @item3.reload
-        @item3.t.should eq 3
+        expect(@item3.t).to eq 3
       end
       it '既存のt3を4にシフトしている' do
         @item6.store
         @item4.reload
-        @item4.t.should eq 4
+        expect(@item4.t).to eq 4
       end
       it '既存のt5を5にシフトしている' do
         @item6.store
         @item5.reload
-        @item5.t.should eq 5
+        expect(@item5.t).to eq 5
       end
       it '新規のt2が作成されている' do
         @item6.store
         @item6.reload
-        @item6.t.should eq 2
+        expect(@item6.t).to eq 2
       end
-      it '他の用紙に影響がない' do
-        @ot = @itemc2.t
+      it '他のスクロールに影響がない' do
+        @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
         @item6.store
-        @itemc2.reload
-        @itemc2.t.should eq @ot
+        @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
+        expect(@after_status).to eq @ot
       end
     end
-    context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したとき' do
+    context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したとき' do
       before do
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
         @ot = @item4.t
         @item4.t = 1
       end
       it '既存のt0には変化がない' do
         @item4.store @ot
         @item.reload
-        @item.t.should eq 0
+        expect(@item.t).to eq 0
       end
       it '既存のt4には変化がない' do
         @item4.store @ot
         @item5.reload
-        @item5.t.should eq 4
+        expect(@item5.t).to eq 4
       end
       it '既存のt1を2にシフトしている' do
         @item4.store @ot
         @item2.reload
-        @item2.t.should eq 2
+        expect(@item2.t).to eq 2
       end
       it '既存のt2を3にシフトしている' do
         @item4.store @ot
         @item3.reload
-        @item3.t.should eq 3
+        expect(@item3.t).to eq 3
       end
       it '既存のt3を1にシフトしている' do
         @item4.store @ot
         @item4.reload
-        @item4.t.should eq 1
+        expect(@item4.t).to eq 1
       end
-      it '他の用紙に影響がない' do
+      it '他のスクロールに影響がない' do
+        @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
         @item4.store @ot
-        @itemc2.reload
-        @itemc2.t.should eq 0
+        @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
+        expect(@after_status).to eq @ot
       end
     end
-    context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で1を3に移動したとき' do
+    context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で1を3に移動したとき' do
       before do
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
         @ot = @item2.t
         @item2.t = 3
       end
       it '既存のt0には変化がない' do
         @item2.store @ot
         @item.reload
-        @item.t.should eq 0
+        expect(@item.t).to eq 0
       end
       it '既存のt4には変化がない' do
         @item2.store @ot
         @item5.reload
-        @item5.t.should eq 4
+        expect(@item5.t).to eq 4
       end
       it '既存のt1を3にシフトしている' do
         @item2.store @ot
         @item2.reload
-        @item2.t.should eq 3
+        expect(@item2.t).to eq 3
       end
       it '既存のt2を1にシフトしている' do
         @item2.store @ot
         @item3.reload
-        @item3.t.should eq 1
+        expect(@item3.t).to eq 1
       end
       it '既存のt3を2にシフトしている' do
         @item2.store @ot
         @item4.reload
-        @item4.t.should eq 2
+        expect(@item4.t).to eq 2
       end
-      it '他の用紙に影響がない' do
+      it '他のスクロールに影響がない' do
+        @before_status = @dummy_scroll_panels.map {|sp| [sp.id, sp.t]}
         @item2.store @ot
-        @itemc2.reload
-        @itemc2.t.should eq 0
+        @after_status = @dummy_scroll_panels.map {|sp| sp.reload ; [sp.id, sp.t]}
+        expect(@after_status).to eq @ot
       end
     end
     #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
-    context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したが保存に失敗したとき' do
+    context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したが保存に失敗したとき' do
       before do
-        SheetPanel.any_instance.stub(:save).with(any_args).and_return(false)
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        ScrollPanel.any_instance.stub(:save).with(any_args).and_return(false)
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
+        @item6 = FactoryGirl.build :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
       end
       it '既存のtに変化がない' do
         @item6.store
         @item.reload
-        @item.t.should eq 0
         @item2.reload
-        @item2.t.should eq 1
         @item3.reload
-        @item3.t.should eq 2
         @item4.reload
-        @item4.t.should eq 3
         @item5.reload
-        @item5.t.should eq 4
+        expect(@item.t).to eq 0
+        expect(@item2.t).to eq 1
+        expect(@item3.t).to eq 2
+        expect(@item4.t).to eq 3
+        expect(@item5.t).to eq 4
+        expect(@item.t).to eq 5
         @itemc2.reload
         @itemc2.t.should eq 0
       end
       it 'falseを返す' do
         r = @item6.store
-        r.should be_false
+        expect(r).to be_false
       end
     end
-    context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したがシリアルチェックに失敗したとき' do
+    context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したがシリアルチェックに失敗したとき' do
       before do
-        SheetPanel.stub(:validate_t).with(any_args).and_return(false)
-        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
-        @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
-        @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        ScrollPanel.stub(:validate_t).with(any_args).and_return(false)
+        @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
         @ot = @item4.t
         @item4.t = 1
       end
@@ -1125,149 +1059,144 @@ describe ScrollPanel do
         @item5.t.should eq 4
         @itemc2.reload
         @itemc2.t.should eq 0
+        expect(@item.t).to eq 0
+        expect(@item.t).to eq 0
+        expect(@item.t).to eq 0
+        expect(@item.t).to eq 0
+        expect(@item.t).to eq 0
+        expect(@item.t).to eq 0
       end
       it 'falseを返す' do
         r = @item4.store @ot
-        r.should be_false
+        expect(r).to be_false
       end
       it 'tにエラーメッセージが入っている' do
         @item4.store @ot
-        @item4.errors[:t].should_not be_empty
-        @item4.valid?.should be_true
-      end
-    end
-    context '編集不可だったとき' do
-      before do
-        @item = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        SheetPanel.any_instance.stub(:allow?).and_return(false)
-      end
-      it '403Forbidden例外を返す' do
-        lambda{
-          @item.store
-        }.should raise_error(ActiveRecord::Forbidden)
+        expect(@item4.errors[:t]).to be_empty
+        expect(@item4.valid?).to be_true
       end
     end
   end
   describe '切り詰め処理つき削除に於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-      @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      @dummy =  FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
+      @scroll =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @panel = FactoryGirl.create :panel_hello, author: @author_yas
+      @item =  FactoryGirl.create :scroll_panel_plain, t: 0, scroll: @scroll, panel: @panel
     end
     context 'つつがなく終わるとき' do
       it '削除される' do
-        lambda{
+        expect {
           @item.destroy_and_shorten
-        }.should change(SheetPanel, :count ).by(-1)
+        }.to change(ScrollPanel, :count ).by(-1)
       end
       it 'Trueを返す' do
         r = @item.destroy_and_shorten
-        r.should be_true 
+        expect(r).to be_true 
       end
     end
     context '削除に失敗したとき' do
       before do
-        SheetPanel.any_instance.stub(:destroy).and_return(false)
+        ScrollPanel.any_instance.stub(:destroy).and_return(false)
       end
       it 'ロールバックされる' do
-        lambda{
+        expect {
           @item.destroy_and_shorten
-        }.should_not change(SheetPanel, :count )
+        }.to change(ScrollPanel, :count )
       end
       it 'Falseを返す' do
         r = @item.destroy_and_shorten
-        r.should be_false
+        expect(r).to be_false
       end
     end
     #連携テスト。切り詰めが直接DBをいじる
     context '2件で先頭を削除したとき' do
       before do
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
       end
       it '行が削除される' do
-        lambda{
+        expect {
           @item.destroy_and_shorten
-        }.should change(SheetPanel, :count ).by(-1)
+        }.to change(ScrollPanel, :count ).by(-1)
       end
       it '先頭は削除される' do
         @item.destroy_and_shorten
-        lambda{
-          SheetPanel.find @item.id
-        }.should raise_error(ActiveRecord::RecordNotFound)
+        expect {
+          ScrollPanel.find @item.id
+        }.to raise_error(ActiveRecord::RecordNotFound)
       end
       it '2件目は前に詰められる' do
         @item.destroy_and_shorten
         @item2.reload
-        @item2.t.should eq 0
+        expect(@item2.t).to eq 0
       end
     end
     context '3件で先頭を削除したとき' do
       before do
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
       end
       it '行が削除される' do
-        lambda{
+        expect {
           @item.destroy_and_shorten
-        }.should change(SheetPanel, :count ).by(-1)
+        }.to change(ScrollPanel, :count ).by(-1)
       end
       it '先頭は削除される' do
         @item.destroy_and_shorten
-        lambda{
-          SheetPanel.find @item.id
-        }.should raise_error(ActiveRecord::RecordNotFound)
+        expect {
+          ScrollPanel.find @item.id
+        }.to raise_error(ActiveRecord::RecordNotFound)
       end
       it '2件目は前に詰められる' do
         @item.destroy_and_shorten
         @item2.reload
-        @item2.t.should eq 0
+        expect(@item2.t).to eq 0
       end
       it '3件目は前に詰められる' do
         @item.destroy_and_shorten
         @item3.reload
-        @item3.t.should eq 1
+        expect(@item3.t).to eq 1
       end
     end
     context '5件で3件目を削除したとき' do
       before do
-        @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
-        @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+        @item2 =  FactoryGirl.create :scroll_panel_plain, t: 1, scroll: @scroll, panel: @panel
+        @item3 =  FactoryGirl.create :scroll_panel_plain, t: 2, scroll: @scroll, panel: @panel
+        @item4 =  FactoryGirl.create :scroll_panel_plain, t: 3, scroll: @scroll, panel: @panel
+        @item5 =  FactoryGirl.create :scroll_panel_plain, t: 4, scroll: @scroll, panel: @panel
       end
       it '行が削除される' do
-        lambda{
+        expect {
           @item3.destroy_and_shorten
-        }.should change(SheetPanel, :count ).by(-1)
+        }.to change(ScrollPanel, :count ).by(-1)
       end
       it '1件目は変化がない' do
         @item3.destroy_and_shorten
         @item.reload
-        @item.t.should eq 0
+        expect(@item.t).to eq 0
       end
       it '2件目は変化がない' do
         @item3.destroy_and_shorten
         @item2.reload
-        @item2.t.should eq 1
+        expect(@item2.t).to eq 1
       end
       it '3件目は削除される' do
         @item3.destroy_and_shorten
-        lambda{
-          SheetPanel.find @item3.id
-        }.should raise_error(ActiveRecord::RecordNotFound)
+        expect {
+          ScrollPanel.find @item3.id
+        }.to raise_error(ActiveRecord::RecordNotFound)
       end
       it '4件目は前に詰められる' do
         @item3.destroy_and_shorten
         @item4.reload
-        @item4.t.should eq 2
+        expect(@item4.t).to eq 2
       end
       it '5件目は前に詰められる' do
         @item3.destroy_and_shorten
         @item5.reload
-        @item5.t.should eq 3
+        expect(@item5.t).to eq 3
       end
     end
     #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
   end
 end
-