OSDN Git Service

#31540:try sort
[pettanr/pettanr.git] / spec / models / panel_spec.rb
index 011adc6..7542b20 100644 (file)
@@ -399,19 +399,6 @@ describe Panel do
         pl.should eq [@panel]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
-      before do\r
-        @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
-        @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
-        @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
-        @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
-        Panel.stub(:default_page_size).and_return(2)\r
-      end\r
-      it '件数0は全件(5件)を返す' do\r
-        r = Panel.list 5, 0\r
-        r.should have(5).items \r
-      end\r
-    end\r
   end\r
   \r
   describe '自分のコマ一覧取得に於いて' do\r
@@ -462,19 +449,6 @@ describe Panel do
         pl.should eq [@panel]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
-      before do\r
-        @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
-        @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
-        @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
-        @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
-        Author.stub(:default_panel_page_size).and_return(2)\r
-      end\r
-      it '通常は全件(5件)を返す' do\r
-        r = Panel.mylist @author, 5, 0\r
-        r.should have(5).items \r
-      end\r
-    end\r
   end\r
   \r
   describe '他作家のコマ一覧取得に於いて' do\r
@@ -521,80 +495,123 @@ describe Panel do
         pl.should eq [@other_panel]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
-      before do\r
-        @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
-        @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200\r
-        @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300\r
-        @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400\r
-        Author.stub(:default_panel_page_size).and_return(2)\r
-      end\r
-      it '通常は全件(5件)を返す' do\r
-        r = Panel.himlist @other_author, 5, 0\r
-        r.should have(5).items \r
-      end\r
+  end\r
+  \r
+  describe 'コマ一覧ページ制御に於いて' do\r
+    before do\r
+      Panel.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = Panel.list_paginate \r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it 'コマ一覧の取得条件を利用している' do\r
+      Panel.stub(:list_where).with(any_args).and_return('')\r
+      Panel.should_receive(:list_where).with(any_args).exactly(1)\r
+      r = Panel.list_paginate \r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = Panel.list_paginate 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
     end\r
   end\r
   \r
-  describe '一覧取得オプションに於いて' do\r
-    it 'includeキーを含んでいる' do\r
-      r = Panel.list_opt\r
-      r.has_key?(:include).should be_true\r
+  describe '自分のコマ一覧ページ制御に於いて' do\r
+    before do\r
+      Panel.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = Panel.mylist_paginate @author\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '自分のコマ一覧の取得条件を利用している' do\r
+      Panel.stub(:mylist_where).with(any_args).and_return('')\r
+      Panel.should_receive(:mylist_where).with(any_args).exactly(1)\r
+      r = Panel.mylist_paginate @author\r
     end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = Panel.mylist_paginate @author, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '他作家のコマ一覧ページ制御に於いて' do\r
+    before do\r
+      Panel.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = Panel.himlist_paginate @other_author\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '他作家のコマ一覧の取得条件を利用している' do\r
+      Panel.stub(:himlist_where).with(any_args).and_return('')\r
+      Panel.should_receive(:himlist_where).with(any_args).exactly(1)\r
+      r = Panel.himlist_paginate @other_author\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = Panel.himlist_paginate @other_author, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '一覧取得オプションに於いて' do\r
     it '5つの項目を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.should have(5).items\r
     end\r
     it 'コマ絵を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:panel_pictures).should be_true\r
     end\r
       it 'コマ絵は実素材を含んでいる' do\r
-        r = Panel.list_opt[:include]\r
+        r = Panel.list_opt\r
         r[:panel_pictures].has_key?(:picture).should be_true\r
       end\r
         it '実素材は絵師を含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
         end\r
         it '実素材はライセンスを含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
         end\r
     it 'フキダシを含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:speech_balloons).should be_true\r
     end\r
       it 'フキダシはフキダシ枠を含んでいる' do\r
-        r = Panel.list_opt[:include]\r
-        r[:speech_balloons].has_key?(:balloons).should be_true\r
+        r = Panel.list_opt\r
+        r[:speech_balloons].has_key?(:balloon).should be_true\r
       end\r
       it 'フキダシはセリフを含んでいる' do\r
-        r = Panel.list_opt[:include]\r
-        r[:speech_balloons].has_key?(:speeches).should be_true\r
+        r = Panel.list_opt\r
+        r[:speech_balloons].has_key?(:speech).should be_true\r
       end\r
     it '絵地を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:ground_pictures).should be_true\r
     end\r
       it '絵地は実素材を含んでいる' do\r
-        r = Panel.list_opt[:include]\r
+        r = Panel.list_opt\r
         r[:ground_pictures].has_key?(:picture).should be_true\r
       end\r
         it '実素材は絵師を含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
         end\r
         it '実素材はライセンスを含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
         end\r
     it '色地を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:ground_colors).should be_true\r
     end\r
     it '作家を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:author).should be_true\r
     end\r
   end\r
@@ -706,11 +723,11 @@ describe Panel do
     end\r
       it 'フキダシはフキダシ枠を含んでいる' do\r
         r = Panel.show_opt[:include]\r
-        r[:speech_balloons].has_key?(:balloons).should be_true\r
+        r[:speech_balloons].has_key?(:balloon).should be_true\r
       end\r
       it 'フキダシはセリフを含んでいる' do\r
         r = Panel.show_opt[:include]\r
-        r[:speech_balloons].has_key?(:speeches).should be_true\r
+        r[:speech_balloons].has_key?(:speech).should be_true\r
       end\r
     it '絵地を含んでいる' do\r
       r = Panel.show_opt[:include]\r
@@ -748,10 +765,10 @@ describe Panel do
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
       @gc = @panel.ground_colors.create(\r
-        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
       @gp = @panel.ground_pictures.create(\r
-        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
       )\r
       @panel.reload\r
     end\r
@@ -759,15 +776,12 @@ describe Panel do
       r = @panel.parts_element\r
       r.is_a?(Array).should be_true\r
     end\r
-    it 'コマ絵とフキダシを合わせている' do\r
+    it 'ã\82³ã\83\9eçµµã\81¨ã\83\95ã\82­ã\83\80ã\82·ã\81¨çµµå\9c°ã\81¨è\89²å\9c°ã\82\92å\90\88ã\82\8fã\81\9bã\81¦ã\81\84ã\82\8b' do\r
       r = @panel.parts_element\r
       r.include?(@pp).should be_true\r
       r.include?(@sb).should be_true\r
-    end\r
-    it '絵地と色地を含んでいない' do\r
-      r = @panel.parts_element\r
-      r.include?(@gc).should_not be_true\r
-      r.include?(@gp).should_not be_true\r
+      r.include?(@gc).should be_true\r
+      r.include?(@gp).should be_true\r
     end\r
   end\r
   describe 'コマ部品に於いて' do\r
@@ -779,10 +793,10 @@ describe Panel do
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
       @gc = @panel.ground_colors.create(\r
-        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
       @gp = @panel.ground_pictures.create(\r
-        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
       )\r
       @panel.reload\r
     end\r
@@ -796,17 +810,19 @@ describe Panel do
     it 'リストを返している' do\r
       r = @panel.parts\r
       r.is_a?(Array).should be_true\r
-      r.size.should eq 2\r
+      r.size.should eq 4\r
     end\r
     it 'tでソートしている' do\r
       r = @panel.parts\r
       r[0].should eq @sb\r
       r[1].should eq @pp\r
+      r[2].should eq @gc\r
+      r[3].should eq @gp\r
     end\r
     context 'さらに末尾にフキダシを追加したとき' do\r
       before do\r
         @sb2 = @panel.speech_balloons.create(\r
-          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)\r
         )\r
         @panel.reload\r
       end\r
@@ -814,39 +830,63 @@ describe Panel do
         r = @panel.parts\r
         r[0].should eq @sb\r
         r[1].should eq @pp\r
-        r[2].should eq @sb2\r
+        r[2].should eq @gc\r
+        r[3].should eq @gp\r
+        r[4].should eq @sb2\r
       end\r
     end\r
   end\r
-  describe 'コマ地に於いて' do\r
+  \r
+  describe 'z順コマ部品に於いて' do\r
     before do\r
       #コマを作成しておく。\r
       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
-      @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+      @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :width => @p.width, :height => @p.height\r
       @sb = @panel.speech_balloons.create(\r
-        FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+        FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1)\r
       )\r
       @gc = @panel.ground_colors.create(\r
-        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3)\r
       )\r
       @gp = @panel.ground_pictures.create(\r
-        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4)\r
       )\r
       @panel.reload\r
     end\r
+    context 'つつがなく終わるとき' do\r
+      it 'コマ部品集合を利用している' do\r
+        Panel.any_instance.stub(:parts_element).with(any_args).and_return([])\r
+        Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)\r
+        r = @panel.zorderd_elements\r
+      end\r
+    end\r
     it 'リストを返している' do\r
-      r = @panel.grounds\r
+      r = @panel.zorderd_elements\r
       r.is_a?(Array).should be_true\r
+      r.size.should eq 4\r
     end\r
-    it '絵地と色地を合わせている' do\r
-      r = @panel.grounds\r
-      r.include?(@gc).should be_true\r
-      r.include?(@gp).should be_true\r
+    it 'zでオフセットを0でソートしている' do\r
+      r = @panel.zorderd_elements\r
+      r[0].should eq @sb\r
+      r[1].should eq @pp\r
+      r[2].should eq @gc\r
+      r[3].should eq @gp\r
     end\r
-    it 'コマ絵とフキダシを含んでいない' do\r
-      r = @panel.grounds\r
-      r.include?(@pp).should_not be_true\r
-      r.include?(@sb).should_not be_true\r
+    context 'さらに末尾にフキダシを追加したとき' do\r
+      before do\r
+        @sb2 = @panel.speech_balloons.create(\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5)\r
+        )\r
+        @panel.reload\r
+      end\r
+      it 'zでソートしている' do\r
+        r = @panel.zorderd_elements\r
+        r[0].should eq @sb\r
+        r[1].should eq @pp\r
+        r[2].should eq @gc\r
+        r[3].should eq @gp\r
+        r[4].should eq @sb2\r
+      end\r
     end\r
   end\r
   describe 'コマ要素に於いて' do\r
@@ -858,10 +898,10 @@ describe Panel do
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
       @gc = @panel.ground_colors.create(\r
-        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
       @gp = @panel.ground_pictures.create(\r
-        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
       )\r
       @panel.reload\r
     end\r
@@ -871,30 +911,17 @@ describe Panel do
         Panel.any_instance.should_receive(:parts).with(any_args).exactly(1)\r
         r = @panel.panel_elements\r
       end\r
-      it 'コマ地を利用している' do\r
-        Panel.any_instance.stub(:grounds).with(any_args).and_return([])\r
-        Panel.any_instance.should_receive(:grounds).with(any_args).exactly(1)\r
-        r = @panel.panel_elements\r
-      end\r
     end\r
     it 'リストを返している' do\r
       r = @panel.panel_elements\r
       r.is_a?(Array).should be_true\r
     end\r
-    it 'コマ絵とフキダシを合わせている' do\r
-      r = @panel.panel_elements\r
-      r.include?(@pp).should be_true\r
-      r.include?(@sb).should be_true\r
-    end\r
-    it '絵地と色地を合わせている' do\r
-      r = @panel.panel_elements\r
-      r.include?(@gc).should be_true\r
-      r.include?(@gp).should be_true\r
-    end\r
-    it 'tでソートしている[t順にソートできる部品の方が優先順位は高い。]' do\r
+    it 'tでソートしている' do\r
       r = @panel.panel_elements\r
       r[0].should eq @sb\r
       r[1].should eq @pp\r
+      r[2].should eq @gc\r
+      r[3].should eq @gp\r
     end\r
   end\r
   describe 'コマ要素のjson出力に於いて' do\r
@@ -906,10 +933,10 @@ describe Panel do
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
       @gc = @panel.ground_colors.create(\r
-        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
       @gp = @panel.ground_pictures.create(\r
-        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
       )\r
       @panel.reload\r
     end\r
@@ -950,11 +977,17 @@ describe Panel do
       @sb = @panel.speech_balloons.create(\r
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
+      @sb.create_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :speech_balloon_id => @sb.id)\r
+      )\r
+      @sb.create_speech(\r
+        FactoryGirl.attributes_for(:speech, :speech_balloon_id => @sb.id)\r
+      )\r
       @gc = @panel.ground_colors.create(\r
-        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
       @gp = @panel.ground_pictures.create(\r
-        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
       )\r
       @panel.reload\r
     end\r
@@ -978,8 +1011,8 @@ describe Panel do
       #t:0\r
       sb = r['elements'].first\r
       sb.has_key?('classname').should be_true\r
-      sb.has_key?('balloons').should be_true\r
-      sb.has_key?('speeches').should be_true\r
+      sb.has_key?('balloon').should be_true\r
+      sb.has_key?('speech').should be_true\r
       #t:1\r
     end\r
   end\r
@@ -1018,10 +1051,10 @@ describe Panel do
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
       @gc = @panel.ground_colors.create(\r
-        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
       @gp = @panel.ground_pictures.create(\r
-        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id)\r
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3)\r
       )\r
       @panel.reload\r
     end\r
@@ -1057,48 +1090,58 @@ describe Panel do
   describe 'シリアライズチェックに於いて' do\r
     context 'つつがなく終わるとき' do\r
       it '0からシリアライズされているならTrueを返す' do\r
-        r = Panel.validate_t [0, 1, 2]\r
+        r = Panel.validate_serial [0, 1, 2]\r
         r.should be_true\r
       end\r
       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
-        r = Panel.validate_t [0, 2, 1]\r
+        r = Panel.validate_serial [0, 2, 1]\r
         r.should be_true\r
       end\r
       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
-        r = Panel.validate_t [ 2, 1, 4, 3, 0]\r
+        r = Panel.validate_serial [ 2, 1, 4, 3, 0]\r
+        r.should be_true\r
+      end\r
+    end\r
+    context 'オフセットが1のとき' do\r
+      it '0からシリアライズされているならFalseを返す' do\r
+        r = Panel.validate_serial [0, 1, 2], 1\r
+        r.should be_false\r
+      end\r
+      it '1からシリアライズされているならTrueを返す' do\r
+        r = Panel.validate_serial [1, 2, 3], 1\r
         r.should be_true\r
       end\r
     end\r
     context '異常なとき' do\r
       it '0から始まらないならFalseを返す' do\r
-        r = Panel.validate_t [1, 2, 3]\r
+        r = Panel.validate_serial [1, 2, 3]\r
         r.should be_false\r
       end\r
       it '連続していないならFalseを返す' do\r
-        r = Panel.validate_t [0, 1, 2, 4]\r
+        r = Panel.validate_serial [0, 1, 2, 4]\r
         r.should be_false\r
       end\r
       it '連続していないならFalseを返す' do\r
-        r = Panel.validate_t [0, 1, 2, 4, 5]\r
+        r = Panel.validate_serial [0, 1, 2, 4, 5]\r
         r.should be_false\r
       end\r
     end\r
   end\r
-  describe 'tチェック単体に於いて' do\r
+  describe 'シリアライズチェック単体に於いて' do\r
     before do\r
     end\r
     context 'つつがなく終わるとき' do\r
       it '検証値収集を依頼している' do\r
         Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
-        Panel.stub(:validate_t).with(any_args).and_return(true)\r
-        r = Panel.validate_element_t [], :t\r
+        Panel.stub(:validate_serial).with(any_args).and_return(true)\r
+        r = Panel.validate_element_serial [], :t\r
       end\r
       it 'シリアライズチェック依頼している' do\r
         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
-        Panel.should_receive(:validate_t).with(any_args).exactly(1)\r
-        Panel.stub(:validate_t).with(any_args).and_return(true)\r
-        r = Panel.validate_element_t [], :t\r
+        Panel.should_receive(:validate_serial).with(any_args).exactly(1)\r
+        Panel.stub(:validate_serial).with(any_args).and_return(true)\r
+        r = Panel.validate_element_serial [], :t\r
       end\r
     end\r
   end\r
@@ -1107,60 +1150,109 @@ describe Panel do
       it 'trueを返している' do\r
         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
         @panel.panel_pictures.build(\r
-          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
+          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
         )\r
         @panel.panel_pictures.build(\r
-          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)\r
+          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)\r
         )\r
         sb1 = @panel.speech_balloons.build(\r
-          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
         )\r
-        sb1.balloons.build(\r
+        sb1.build_balloon(\r
           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
         )\r
-        sb1.speeches.build(\r
+        sb1.build_speech(\r
           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
         )\r
         sb2 = @panel.speech_balloons.build(\r
-          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)\r
         )\r
-        sb2.balloons.build(\r
+        sb2.build_balloon(\r
           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
         )\r
-        sb2.speeches.build(\r
+        sb2.build_speech(\r
           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
         )\r
+        @gc = @panel.ground_colors.build(\r
+          FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
+        )\r
+        @gp = @panel.ground_pictures.build(\r
+          FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
+        )\r
         r = @panel.validate_child\r
         r.should be_true\r
       end\r
     end\r
-    context 'シリアライズされていないとき' do\r
+    context 'tシリアライズされていないとき' do\r
       it 'falseを返している' do\r
         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
         @panel.panel_pictures.build(\r
-          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
+          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
         )\r
         @panel.panel_pictures.build(\r
-          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)\r
+          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)\r
         )\r
         sb1 = @panel.speech_balloons.build(\r
-          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
         )\r
-        sb1.balloons.build(\r
+        sb1.build_balloon(\r
           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
         )\r
-        sb1.speeches.build(\r
+        sb1.build_speech(\r
           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
         )\r
         sb2 = @panel.speech_balloons.build(\r
-          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)\r
         )\r
-        sb2.balloons.build(\r
+        sb2.build_balloon(\r
           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
         )\r
-        sb2.speeches.build(\r
+        sb2.build_speech(\r
           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
         )\r
+        @gc = @panel.ground_colors.build(\r
+          FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
+        )\r
+        @gp = @panel.ground_pictures.build(\r
+          FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
+        )\r
+        r = @panel.validate_child\r
+        r.should be_false\r
+      end\r
+    end\r
+    context 'zシリアライズされていないとき' do\r
+      it 'falseを返している' do\r
+        @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+        @panel.panel_pictures.build(\r
+          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
+        )\r
+        @panel.panel_pictures.build(\r
+          FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 0+1)\r
+        )\r
+        sb1 = @panel.speech_balloons.build(\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
+        )\r
+        sb1.build_balloon(\r
+          FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
+        )\r
+        sb1.build_speech(\r
+          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
+        )\r
+        sb2 = @panel.speech_balloons.build(\r
+          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)\r
+        )\r
+        sb2.build_balloon(\r
+          FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
+        )\r
+        sb2.build_speech(\r
+          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
+        )\r
+        @gc = @panel.ground_colors.build(\r
+          FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
+        )\r
+        @gp = @panel.ground_pictures.build(\r
+          FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
+        )\r
         r = @panel.validate_child\r
         r.should be_false\r
       end\r