OSDN Git Service

t#32046:add sheet
[pettanr/pettanr.git] / spec / models / panel_spec.rb
index 56e1821..416fb17 100644 (file)
@@ -3,6 +3,7 @@ require 'spec_helper'
 #コマ\r
 describe Panel do\r
   before do\r
+    SpeechBalloonTemplate.delete_all\r
     @admin = FactoryGirl.create :admin\r
     @sp = FactoryGirl.create :system_picture\r
     @lg = FactoryGirl.create :license_group\r
@@ -17,7 +18,7 @@ describe Panel do
     @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
     @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
     @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
-    @sbt = FactoryGirl.create :speech_balloon_template\r
+    @sbt = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc",  "system_picture_id" => @sp.id, "settings" => '{}'\r
   end\r
   \r
   describe '検証に於いて' do\r
@@ -253,9 +254,9 @@ describe Panel do
   \r
   describe '閲覧許可に於いて' do\r
     before do\r
-      @comic = FactoryGirl.create :comic, :author_id => @author.id\r
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id\r
       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id\r
     end\r
     context 'オープンモードのとき' do\r
       before do\r
@@ -762,9 +763,17 @@ describe Panel do
       #コマを作成しておく。\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
-      @sb = @panel.speech_balloons.create(\r
+      @sb = @panel.speech_balloons.build(\r
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
+      @sb.build_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+      )\r
+      @sb.build_speech(\r
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+      )\r
+      @sb.boost\r
+      @sb.save!\r
       @gc = @panel.ground_colors.create(\r
         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
@@ -791,9 +800,17 @@ describe Panel do
       #コマを作成しておく。\r
       @panel = FactoryGirl.create :panel, :author_id => @author.id\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
+      @sb = @panel.speech_balloons.build(\r
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1)\r
       )\r
+      @sb.build_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+      )\r
+      @sb.build_speech(\r
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+      )\r
+      @sb.boost\r
+      @sb.save!\r
       @gc = @panel.ground_colors.create(\r
         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3)\r
       )\r
@@ -823,9 +840,17 @@ describe Panel do
     end\r
     context 'さらに末尾にフキダシを追加したとき' do\r
       before do\r
-        @sb2 = @panel.speech_balloons.create(\r
+        @sb2 = @panel.speech_balloons.build(\r
           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5)\r
         )\r
+        @sb2.build_balloon(\r
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+        )\r
+        @sb2.build_speech(\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+        )\r
+        @sb2.boost\r
+        @sb2.save!\r
         @panel.reload\r
       end\r
       it 'zでソートしている' do\r
@@ -843,9 +868,17 @@ describe Panel do
       #コマを作成しておく。\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
-      @sb = @panel.speech_balloons.create(\r
+      @sb = @panel.speech_balloons.build(\r
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
+      @sb.build_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+      )\r
+      @sb.build_speech(\r
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+      )\r
+      @sb.boost\r
+      @sb.save!\r
       @gc = @panel.ground_colors.create(\r
         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
@@ -874,9 +907,17 @@ describe Panel do
     end\r
     context 'さらに末尾にフキダシを追加したとき' do\r
       before do\r
-        @sb2 = @panel.speech_balloons.create(\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
         )\r
+        @sb2.build_balloon(\r
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+        )\r
+        @sb2.build_speech(\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+        )\r
+        @sb2.boost\r
+        @sb2.save!\r
         @panel.reload\r
       end\r
       it 'tでソートしている' do\r
@@ -894,9 +935,17 @@ describe Panel do
       #コマを作成しておく。\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
-      @sb = @panel.speech_balloons.create(\r
+      @sb = @panel.speech_balloons.build(\r
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
+      @sb.build_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+      )\r
+      @sb.build_speech(\r
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+      )\r
+      @sb.boost\r
+      @sb.save!\r
       @gc = @panel.ground_colors.create(\r
         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
@@ -939,15 +988,17 @@ describe Panel do
       #コマを作成しておく。\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
-      @sb = @panel.speech_balloons.create(\r
+      @sb = @panel.speech_balloons.build(\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
+      @sb.build_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
       )\r
-      @sb.create_speech(\r
-        FactoryGirl.attributes_for(:speech, :speech_balloon_id => @sb.id, :writing_format_id => @writing_format.id)\r
+      @sb.build_speech(\r
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
       )\r
+      @sb.boost\r
+      @sb.save!\r
       @gc = @panel.ground_colors.create(\r
         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
@@ -1012,9 +1063,17 @@ describe Panel do
       @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id\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, :picture_id => @p.id\r
-      @sb = @panel.speech_balloons.create(\r
+      @sb = @panel.speech_balloons.build(\r
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
+      @sb.build_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+      )\r
+      @sb.build_speech(\r
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+      )\r
+      @sb.boost\r
+      @sb.save!\r
       @gc = @panel.ground_colors.create(\r
         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
       )\r
@@ -1121,23 +1180,27 @@ describe Panel do
           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, :z => 2+1)\r
+          FactoryGirl.attributes_for(:speech_balloon, :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
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
         )\r
         sb1.build_speech(\r
-          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
         )\r
+        sb1.boost\r
+        sb1.save!\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
+          FactoryGirl.attributes_for(:speech_balloon, :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
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
         )\r
         sb2.build_speech(\r
-          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
         )\r
+        sb2.boost\r
+        sb2.save!\r
         @gc = @panel.ground_colors.build(\r
           FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
         )\r
@@ -1158,23 +1221,27 @@ describe Panel do
           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, :z => 2+1)\r
+          FactoryGirl.attributes_for(:speech_balloon, :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
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
         )\r
         sb1.build_speech(\r
-          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
         )\r
+        sb1.boost\r
+        sb1.save!\r
         sb2 = @panel.speech_balloons.build(\r
-          FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)\r
+          FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)\r
         )\r
         sb2.build_balloon(\r
-          FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
         )\r
         sb2.build_speech(\r
-          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
         )\r
+        sb2.boost\r
+        sb2.save!\r
         @gc = @panel.ground_colors.build(\r
           FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
         )\r
@@ -1195,23 +1262,27 @@ describe Panel do
           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
+          FactoryGirl.attributes_for(:speech_balloon, :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
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
         )\r
         sb1.build_speech(\r
-          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
         )\r
+        sb1.boost\r
+        sb1.save!\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
+          FactoryGirl.attributes_for(:speech_balloon, :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
+          FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
         )\r
         sb2.build_speech(\r
-          FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
+          FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
         )\r
+        sb2.boost\r
+        sb2.save!\r
         @gc = @panel.ground_colors.build(\r
           FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
         )\r
@@ -1292,14 +1363,76 @@ describe Panel do
     end\r
   end\r
   \r
+  describe '要素の検証に於いて' do\r
+    before do\r
+      @panel = Panel.new\r
+      @panel.supply_default\r
+      @attr = FactoryGirl.attributes_for :panel\r
+@sbattr = {\r
+  "speech_balloons_attributes" => {\r
+    "0" => {\r
+      "caption" => "大きな文字で","z" => "1","t" => "0",\r
+      "classname" => "CircleSpeechBalloon","speech_balloon_template_id" => @sbt.id,\r
+      "speech_attributes" => {\r
+        "content" => "カギッコ","x" => "20","y" => "20","width" => "-60","height" => "60",\r
+        "settings" => "","writing_format_id" => @writing_format.id\r
+      },\r
+      "balloon_attributes" => {\r
+        "r" => "247","x" => "293","y" => "-2","width" => "200","height" => "200",\r
+        "system_picture_id" => @sp.id,"settings" => ""\r
+      }\r
+    }\r
+  },\r
+  "publish" => "0"\r
+}\r
+@ppattr = {\r
+  "panel_pictures_attributes" => {\r
+    "4" => {\r
+      "caption" => "司会","x" => "a","y" => "99","z" => "1","t" => "0",\r
+      "width" => "156","height" => "245","link" => "","picture_id" => @p.id\r
+    }\r
+  },\r
+  "publish" => "0"\r
+}\r
+    end\r
+    context 'フキダシの幅がマイナスで検証に失敗したとき' do\r
+      before do\r
+        @attr.merge!(@sbattr)\r
+      end\r
+      it 'エラーメッセージがセットされている' do\r
+        r = @panel.store @attr, @author\r
+        r.should be_false\r
+        @panel.errors.should_not be_empty\r
+      end\r
+    end\r
+    context 'コマ絵の横軸はアルファベットのため検証に失敗したとき' do\r
+      before do\r
+        @attr.merge!(@ppattr)\r
+      end\r
+      it 'エラーメッセージがセットされている' do\r
+        r = @panel.store @attr, @author\r
+        r.should be_false\r
+        @panel.errors.should_not be_empty\r
+      end\r
+    end\r
+  end\r
+  \r
   describe '削除に於いて' do\r
     before do\r
-      @comic = FactoryGirl.create :comic, :author_id => @author.id\r
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id\r
       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
-      @sb = @panel.speech_balloons.create(\r
+      @sb = @panel.speech_balloons.build(\r
         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
       )\r
+      @sb.build_balloon(\r
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)\r
+      )\r
+      @sb.build_speech(\r
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)\r
+      )\r
+      @sb.boost\r
+      @sb.save!\r
       @gc = @panel.ground_colors.create(\r
         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
       )\r