OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / spec / controllers / panels_controller_spec.rb
index 31e8bfc..a75ad3f 100644 (file)
@@ -3,12 +3,12 @@ require 'spec_helper'
 #コマ\r
 describe PanelsController do\r
   before do\r
-    FactoryGirl.create :admin\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 = @user.author    #ユーザ作成時に連動して作成される\r
+    @author = FactoryGirl.create :author, :user_id => @user.id\r
   end\r
   \r
   describe '一覧表示に於いて' do\r
@@ -71,10 +71,10 @@ describe PanelsController do
           get :index, :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
-        it 'ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81«ã\82³ã\83\9eã\81®jsonå\87ºå\8a\9bã\82\92å\95\8fã\81\84å\90\88ã\82\8fã\81\9bã\81¦ã\81\84ã\82\8b' do
-          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(3)
-          get :index, :format => :json
-        end
+        it 'ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81«ã\82³ã\83\9eã\83ªã\82¹ã\83\88ã\81®jsonå\87ºå\8a\9bã\82\92å\95\8fã\81\84å\90\88ã\82\8fã\81\9bã\81¦ã\81\84ã\82\8b' 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
@@ -148,10 +148,10 @@ describe PanelsController do
           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
-          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1)
-          get :show, :id => @panel.id, :format => :json
-        end
+        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
@@ -277,16 +277,16 @@ describe PanelsController do
           response.should render_template("new")\r
         end\r
       end\r
-      context 'json形式' do
-        it 'jsonデータを返す' do
-          get :new, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'コマモデルにコマのjson出力を問い合わせている' do
-          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1)
-          get :new, :format => :json
-        end
-      end
+      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
@@ -377,10 +377,10 @@ describe PanelsController do
           post :create, :panel => @attr, :format => :json\r
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
         end\r
-        it 'コマモデルにコマのjson出力を問い合わせている' do
-          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1)
+        it 'コマモデルにコマのjson出力を問い合わせている' do\r
+          Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1)\r
           post :create, :panel => @attr, :format => :json\r
-        end
+        end\r
         it 'データがアレになっている' do\r
           post :create, :panel => @attr, :format => :json\r
           json = JSON.parse response.body\r
@@ -646,7 +646,7 @@ describe PanelsController do
         delete :destroy, :id => @panel.id\r
         assigns(:panel).id.should eq(@panel.id)\r
       end\r
-      it 'そのコマを一つのトランザクションで削除する' do\r
+      it 'そのコマを削除する' do\r
         lambda {\r
           delete :destroy, :id => @panel.id\r
         }.should change(Panel, :count)\r
@@ -656,9 +656,9 @@ describe PanelsController do
           delete :destroy, :id => @panel.id\r
           response.status.should eq 302\r
         end\r
-        it 'コマ一覧ページへ遷移する' do\r
+        it 'ã\83\9eã\82¤ã\82³ã\83\9eä¸\80覧ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99ã\82\8b' do\r
           delete :destroy, :id => @panel.id\r
-          response.should redirect_to(panels_url)\r
+          response.should redirect_to('/home/panel')\r
         end\r
       end\r
       context 'json形式' do\r
@@ -693,6 +693,31 @@ describe PanelsController do
         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