OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / spec / controllers / panels_controller_spec.rb
index fbc8e26..a75ad3f 100644 (file)
@@ -1,18 +1,19 @@
 # -*- encoding: utf-8 -*-\r
 require 'spec_helper'\r
-\r
+#コマ\r
 describe PanelsController do\r
   before do\r
-    Factory :admin\r
-    @license = Factory :license
-    @user = Factory :user_yas\r
-    @author = @user.author    #ユーザ作成時に連動して作成される\r
-    @comic = Factory :comic, :author_id => @author.id\r
+    @admin = FactoryGirl.create :admin\r
+    @sp = FactoryGirl.create :system_picture\r
+    @lg = FactoryGirl.create :license_group\r
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
+    @user = FactoryGirl.create :user_yas\r
+    @author = FactoryGirl.create :author, :user_id => @user.id\r
   end\r
   \r
   describe '一覧表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
+      @panel = FactoryGirl.create :panel, :author_id => @author.id\r
       Panel.stub(:list).and_return([@panel, @panel, @panel])\r
       sign_in @user\r
     end\r
@@ -43,10 +44,6 @@ describe PanelsController do
       end\r
     end\r
     context 'つつがなく終わるとき' do\r
-      it 'ステータスコード200 OKを返す' do\r
-        get :index\r
-        response.should be_success \r
-      end\r
       it 'コマモデルに一覧を問い合わせている' do\r
         Panel.should_receive(:list).exactly(1)\r
         get :index\r
@@ -56,16 +53,28 @@ describe PanelsController do
         assigns(:panels).should have_at_least(3).items\r
       end\r
       context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :index\r
+          response.should be_success \r
+        end\r
         it 'indexテンプレートを描画する' do\r
           get :index\r
           response.should render_template("index")\r
         end\r
       end\r
       context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :index, :format => :json\r
+          response.should be_success \r
+        end\r
         it 'jsonデータを返す' do\r
           get :index, :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
+        it 'コマモデルにコマリストのjson出力を問い合わせている' do\r
+          Panel.should_receive(:list_as_json_text).exactly(1)\r
+          get :index, :format => :json\r
+        end\r
         it 'データがリスト構造になっている' do\r
           get :index, :format => :json\r
           json = JSON.parse response.body\r
@@ -74,7 +83,7 @@ describe PanelsController do
         it 'リストの先頭くらいはコマっぽいものであって欲しい' do\r
           get :index, :format => :json\r
           json = JSON.parse response.body\r
-          json.first.has_key?("comic_id").should be_true\r
+          json.first.has_key?("border").should be_true\r
         end\r
       end\r
     end\r
@@ -107,15 +116,11 @@ describe PanelsController do
   \r
   describe '単体表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @user.author.id, :comic_id => @comic.id\r
-      Panel.stub(:show).and_return(@panel)\r
+      @panel = FactoryGirl.create :panel, :author_id => @user.author.id\r
+      Panel.stub(:show).with(@panel.id.to_s, @author).and_return(@panel)\r
       sign_in @user\r
     end\r
     context 'つつがなく終わるとき' do\r
-      it 'ステータスコード200 OKを返す' do\r
-        get :show, :id => @panel.id\r
-        response.should be_success\r
-      end\r
       it 'コマモデルに単体取得を問い合わせている' do\r
         Panel.should_receive(:show).exactly(1)\r
         get :show\r
@@ -125,20 +130,32 @@ describe PanelsController do
         assigns(:panel).id.should eq(@panel.id)\r
       end\r
       context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :show, :id => @panel.id\r
+          response.should be_success\r
+        end\r
         it 'showテンプレートを描画する' do\r
           get :show, :id => @panel.id\r
           response.should render_template("show")\r
         end\r
       end\r
       context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :show, :id => @panel.id, :format => :json\r
+          response.should be_success\r
+        end\r
         it 'jsonデータを返す' do\r
           get :show, :id => @panel.id, :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
+        it 'コマモデルにコマのjson出力を問い合わせている' do\r
+          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1)\r
+          get :show, :id => @panel.id, :format => :json\r
+        end\r
         it 'データがアレになっている' do\r
           get :show, :id => @panel.id, :format => :json\r
           json = JSON.parse response.body\r
-          json["width"].should match(/438/)\r
+          json["width"].should eq 100\r
         end\r
       end\r
     end\r
@@ -188,7 +205,7 @@ describe PanelsController do
       context 'html形式' do\r
         it '例外403 forbiddenを返す' do\r
           Panel.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
-          hidden = Factory :hidden_panel, :author_id => @author.id\r
+          hidden = FactoryGirl.create :hidden_panel, :author_id => @author.id\r
           lambda{\r
             get :show, :id => hidden\r
           }.should raise_error(ActiveRecord::Forbidden)\r
@@ -197,7 +214,7 @@ describe PanelsController do
       context 'json形式' do\r
         it '例外403 forbiddenを返す' do\r
           Panel.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
-          hidden = Factory :hidden_panel, :author_id => @author.id\r
+          hidden = FactoryGirl.create :hidden_panel, :author_id => @author.id\r
           lambda{\r
             get :show, :id => hidden, :format => :json\r
           }.should raise_error(ActiveRecord::Forbidden)\r
@@ -236,10 +253,6 @@ describe PanelsController do
       sign_in @user\r
     end\r
     context 'つつがなく終わるとき' do\r
-      it 'ステータスコード200 OKを返す' do\r
-        get :new\r
-        response.should be_success \r
-      end\r
       it '@panelに新規データを用意している' do\r
         get :new\r
         assigns(:panel).should be_a_new(Panel)\r
@@ -249,6 +262,10 @@ describe PanelsController do
         get :new\r
       end\r
       context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :new\r
+          response.should be_success \r
+        end\r
         it 'newテンプレートを描画する' do\r
           get :new\r
           response.should render_template("new")\r
@@ -260,6 +277,16 @@ describe PanelsController do
           response.should render_template("new")\r
         end\r
       end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :new, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'コマモデルにコマのjson出力を問い合わせている' do\r
+          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1)\r
+          get :new, :format => :json\r
+        end\r
+      end\r
     end\r
     context '作家権限がないとき' do\r
       before do\r
@@ -290,66 +317,74 @@ describe PanelsController do
   \r
   describe '新規作成に於いて' do\r
     before do\r
-      @panel = Factory :normal_panel, :author_id => @user.author.id, :comic_id => @comic.id\r
+      @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+      @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id)\r
       sign_in @user\r
     end\r
     context '事前チェックする' do\r
       before do\r
-        controller\r
         Panel.stub(:count).and_return(10)\r
       end\r
       it 'panelがパラメータにあれば、展開する' do\r
-        post :create, :panel => Factory.attributes_for(:panel, :panel_id => @panel.id)\r
-        assigns(:prm)['border'].to_i.should eq 1\r
+        post :create, :panel => @attr\r
+        assigns(:prm)['border'].to_i.should eq @panel.border\r
       end\r
       it 'jsonがパラメータにあれば、展開する' do\r
-        post :create, :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+        post :create, :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json\r
         assigns(:prm)['border'].to_i.should eq 4\r
       end\r
       it 'panel・json両パラメータがあれば、panelを優先して展開する' do\r
         post :create, {\r
-          :panel => Factory.attributes_for(:panel, :panel_id => @panel.id), \r
-          :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+          :panel => FactoryGirl.attributes_for(:panel), \r
+          :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json\r
         }\r
-        assigns(:prm)['border'].to_i.should eq 1\r
+        assigns(:prm)['border'].to_i.should eq @panel.border\r
+      end\r
+      it 'コマモデルにデフォルト値補充を依頼している' do\r
+        Panel.any_instance.should_receive(:supply_default).exactly(1)\r
+        post :create, :panel => @attr\r
       end\r
-    end\r
-    context 'つつがなく終わるとき' do\r
       it 'モデルに保存依頼する' do\r
-        Panel.any_instance.should_receive(:save).exactly(1)\r
-        post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+        Panel.any_instance.should_receive(:store).exactly(1)\r
+        post :create, :panel => @attr\r
       end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
       it "@panelに作成されたコマを保持していて、それがDBにある" do\r
-        post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+        post :create, :panel => @attr\r
         assigns(:panel).should be_a(Panel)\r
         assigns(:panel).should be_persisted\r
       end\r
       context 'html形式' do\r
         it 'ステータスコード302 Foundを返す' do\r
-          Panel.any_instance.stub(:save).and_return(true)\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          Panel.any_instance.stub(:store).and_return(true)\r
+          post :create, :panel => @attr\r
           response.status.should eq 302\r
         end\r
         it '作成されたコマの表示ページへ遷移する' do\r
-#          Panel.any_instance.stub(:save).and_return(true)\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+#          Panel.any_instance.stub(:store).and_return(true)\r
+          post :create, :panel => @attr\r
           response.should redirect_to(Panel.last)\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード200 OKを返す' do\r
-#          Panel.any_instance.stub(:save).and_return(true)\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+#          Panel.any_instance.stub(:store).and_return(true)\r
+          post :create, :panel => @attr, :format => :json\r
           response.should be_success \r
         end\r
         it '作成されたコマをjsonデータで返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => @attr, :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
+        it 'コマモデルにコマのjson出力を問い合わせている' do\r
+          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1)\r
+          post :create, :panel => @attr, :format => :json\r
+        end\r
         it 'データがアレになっている' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => @attr, :format => :json\r
           json = JSON.parse response.body\r
-          json["title"].should match(/normal/)\r
+          json["width"].should eq @panel.width\r
         end\r
       end\r
     end\r
@@ -359,50 +394,50 @@ describe PanelsController do
       end\r
       context 'html形式' do\r
         it 'ステータスコード302 Foundを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => @attr\r
           response.status.should eq 302\r
         end\r
         it 'サインインページへ遷移する' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => @attr\r
           response.body.should redirect_to '/users/sign_in'\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード401 Unauthorizedを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => @attr, :format => :json\r
           response.status.should eq 401\r
         end\r
         it '応答メッセージにUnauthorizedを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => @attr, :format => :json\r
           response.message.should match(/Unauthorized/)\r
         end\r
       end\r
     end\r
     context '検証、保存に失敗した' do\r
       before do\r
-        Panel.any_instance.stub(:save).and_return(false)\r
+        Panel.any_instance.stub(:store).and_return(false)\r
       end\r
       it "未保存のコマを保持している" do\r
-        post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+        post :create, :panel => @attr\r
         assigns(:panel).should be_a_new(Panel)\r
       end\r
       context 'html形式' do\r
         it 'ステータスコード200 OKを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => @attr\r
           response.status.should eq 200\r
         end\r
         it '新規ページを描画する' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          post :create, :panel => @attr\r
           response.should render_template("new")\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード422 unprocessable_entity を返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => @attr, :format => :json\r
           response.status.should eq 422\r
         end\r
         it '応答メッセージUnprocessable Entityを返す' do\r
-          post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          post :create, :panel => @attr, :format => :json\r
           response.message.should match(/Unprocessable/)\r
         end\r
       end\r
@@ -411,17 +446,13 @@ describe PanelsController do
 \r
   describe '編集フォーム表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
+      @panel = FactoryGirl.create :panel, :author_id => @author.id\r
       sign_in @user\r
       Panel.stub(:show).and_return(@panel)\r
     end\r
     context 'つつがなく終わるとき' do\r
-      it 'ステータスコード200 OKを返す' do\r
-        get :edit, :id => @panel.id\r
-        response.should be_success \r
-      end\r
-      it 'コマモデルに単体取得を問い合わせている' do\r
-        Panel.should_receive(:show).exactly(1)\r
+      it 'コマモデルに編集取得を問い合わせている' do\r
+        Panel.should_receive(:edit).exactly(1)\r
         get :edit, :id => @panel.id\r
       end\r
       it '@panelにデータを用意している' do\r
@@ -429,12 +460,20 @@ describe PanelsController do
         assigns(:panel).should eq @panel\r
       end\r
       context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :edit, :id => @panel.id\r
+          response.should be_success \r
+        end\r
         it 'editテンプレートを描画する' do\r
           get :edit, :id => @panel.id\r
           response.should render_template("edit")\r
         end\r
       end\r
       context 'js形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :edit, :id => @panel.id, :format => :js\r
+          response.should be_success \r
+        end\r
         it 'edit.jsテンプレートを描画する' do\r
           get :edit, :id => @panel.id, :format => :js\r
           response.should render_template("edit")\r
@@ -470,49 +509,68 @@ describe PanelsController do
 \r
   describe '更新に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author => @author.id, :comic_id => @comic.id\r
+      @panel = FactoryGirl.create :panel, :author_id => @user.author.id\r
+      @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id)\r
       sign_in @user\r
     end\r
-    context '事前チェックしておく' do\r
-      it 'コマモデルに単体取得を問い合わせている' do\r
-        Panel.stub(:show).with(any_args()).and_return @panel\r
-        Panel.should_receive(:show).exactly(1)\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+    context '事前チェックする' do\r
+      before do\r
+        controller\r
+        Panel.stub(:count).and_return(10)\r
       end\r
-      it 'モデルに更新を依頼する' do\r
-        Panel.any_instance.should_receive(:update_attributes).with(any_args)\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+      it 'panelがパラメータにあれば、展開する' do\r
+        put :update, :id => @panel.id, :panel => @attr\r
+        assigns(:prm)['border'].to_i.should eq @panel.border\r
       end\r
-      it '@panelにアレを取得している' do\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-        assigns(:panel).id.should eq(@panel.id)\r
+      it 'jsonがパラメータにあれば、展開する' do\r
+        put :update, :id => @panel.id, :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json\r
+        assigns(:prm)['border'].to_i.should eq 4\r
+      end\r
+      it 'panel・json両パラメータがあれば、panelを優先して展開する' do\r
+        put :update, {\r
+          :id => @panel.id, \r
+          :panel => FactoryGirl.attributes_for(:panel), \r
+          :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json\r
+        }\r
+        assigns(:prm)['border'].to_i.should eq @panel.border\r
       end\r
     end\r
     context 'つつがなく終わるとき' do\r
-      it '更新される' do\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-        Panel.find(@panel.id).visible.should eq 0\r
+      it 'モデルに編集取得依頼する' do\r
+        Panel.stub(:edit).with(any_args).and_return(@panel)\r
+        Panel.should_receive(:edit).exactly(1)\r
+        put :update, :id => @panel.id, :panel => @attr\r
+      end\r
+      it 'モデルに保存依頼する' do\r
+        Panel.any_instance.should_receive(:store).exactly(1)\r
+        put :update, :id => @panel.id, :panel => @attr\r
+      end\r
+      it "@panelに作成されたコマを保持していて、それがDBにある" do\r
+        put :update, :id => @panel.id, :panel => @attr\r
+        assigns(:panel).should be_a(Panel)\r
+        assigns(:panel).should be_persisted\r
       end\r
       context 'html形式' do\r
         it 'ステータスコード302 Foundを返す' do\r
-          Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          Panel.any_instance.stub(:store).and_return(true)\r
+          put :update, :id => @panel.id, :panel => @attr\r
           response.status.should eq 302\r
         end\r
-        it '更新されたコマの表示ページへ遷移する' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-          response.should redirect_to(@panel)\r
+        it '作成されたコマの表示ページへ遷移する' do\r
+#          Panel.any_instance.stub(:store).and_return(true)\r
+          put :update, :id => @panel.id, :panel => @attr\r
+          response.should redirect_to(Panel.last)\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード200 OKを返す' do\r
-          Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+#          Panel.any_instance.stub(:store).and_return(true)\r
+          put :update, :id => @panel.id, :panel => @attr, :format => :json\r
           response.should be_success \r
         end\r
         it 'ページ本体は特に返さない' do\r
-          Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          Panel.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @panel.id, :panel => @attr, :format => :json\r
           response.body.should match /./\r
         end\r
       end\r
@@ -521,49 +579,152 @@ describe PanelsController do
       before do\r
         sign_out @user\r
       end\r
-      it 'ステータスコード302 Foundを返す' do\r
-        put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
-        response.status.should eq 302\r
-      end\r
       context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          put :update, :id => @panel.id, :panel => @attr\r
+          response.status.should eq 302\r
+        end\r
         it 'サインインページへ遷移する' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          put :update, :id => @panel.id, :panel => @attr\r
           response.body.should redirect_to '/users/sign_in'\r
         end\r
       end\r
       context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          put :update, :id => @panel.id, :panel => @attr, :format => :json\r
+          response.status.should eq 401\r
+        end\r
         it '応答メッセージにUnauthorizedを返す' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          put :update, :id => @panel.id, :panel => @attr, :format => :json\r
           response.message.should match(/Unauthorized/)\r
         end\r
       end\r
     end\r
-    context '検証、保存に失敗したとき' do\r
+    context '検証、保存に失敗した' do\r
       before do\r
-        Panel.any_instance.stub(:update_attributes).and_return(false)\r
+        Panel.any_instance.stub(:store).and_return(false)\r
+      end\r
+      it "指定のコマを保持している" do\r
+        put :update, :id => @panel.id, :panel => @attr\r
+        assigns(:panel).should eq @panel\r
       end\r
       context 'html形式' do\r
-        it 'ステータスコード200 Okを返す' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+        it 'ステータスコード200 OKを返す' do\r
+          put :update, :id => @panel.id, :panel => @attr\r
           response.status.should eq 200\r
         end\r
         it '編集ページを描画する' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+          put :update, :id => @panel.id, :panel => @attr\r
           response.should render_template("edit")\r
         end\r
       end\r
       context 'json形式' do\r
         it 'ステータスコード422 unprocessable_entity を返す' do\r
-          Panel.any_instance.stub(:update_attributes).and_return(false)\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          put :update, :id => @panel.id, :panel => @attr, :format => :json\r
           response.status.should eq 422\r
         end\r
         it '応答メッセージUnprocessable Entityを返す' do\r
-          put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+          put :update, :id => @panel.id, :panel => @attr, :format => :json\r
           response.message.should match(/Unprocessable/)\r
         end\r
       end\r
     end\r
   end\r
+\r
+  describe '削除に於いて' do\r
+    before do\r
+      @panel = FactoryGirl.create :panel, :author_id => @user.author.id\r
+      Panel.stub(:edit).and_return(@panel)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'コマモデルに編集取得を問い合わせている' do\r
+        Panel.should_receive(:edit).exactly(1)\r
+        delete :destroy, :id => @panel.id\r
+      end\r
+      it '@panelにアレを取得している' do\r
+        delete :destroy, :id => @panel.id\r
+        assigns(:panel).id.should eq(@panel.id)\r
+      end\r
+      it 'そのコマを削除する' do\r
+        lambda {\r
+          delete :destroy, :id => @panel.id\r
+        }.should change(Panel, :count)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @panel.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'マイコマ一覧ページへ遷移する' do\r
+          delete :destroy, :id => @panel.id\r
+          response.should redirect_to('/home/panel')\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          delete :destroy, :id => @panel.id, :format => :json\r
+          response.should be_success\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @panel.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          delete :destroy, :id => @panel.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          delete :destroy, :id => @panel.id, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          delete :destroy, :id => @panel.id, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context '削除に失敗したとき' do\r
+      before do\r
+        Panel.any_instance.stub(:destroy_with_elements).and_return(false)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @panel.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'そのコマの詳細ページへ遷移する' do\r
+          delete :destroy, :id => @panel.id\r
+          response.should redirect_to(panel_path(@panel))\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          delete :destroy, :id => @panel.id, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          delete :destroy, :id => @panel.id, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+=begin\r
+    context '対象コマがないとき' do\r
+    end\r
+    context '他人のコマだったとき' do\r
+    end\r
+=end\r
+  end\r
   \r
 end\r
+\r