OSDN Git Service

t#30443:add test for open mode
[pettanr/pettanr.git] / spec / controllers / panels_controller_spec.rb
index 283feb1..3ccd6c6 100644 (file)
@@ -3,17 +3,18 @@ require 'spec_helper'
 #コマ\r
 describe PanelsController do\r
   before do\r
-    Factory :admin\r
-    @sp = Factory :system_picture
-    @lg = Factory :license_group
-    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
-    @user = Factory :user_yas\r
-    @author = @user.author    #ユーザ作成時に連動して作成される\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
+if MagicNumber['run_mode'] == 1\r
   describe '一覧表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @author.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
@@ -44,10 +45,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
@@ -57,16 +54,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
@@ -108,15 +117,11 @@ describe PanelsController do
   \r
   describe '単体表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @user.author.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
@@ -126,16 +131,28 @@ 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
@@ -189,7 +206,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
@@ -198,7 +215,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
@@ -237,10 +254,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
@@ -250,6 +263,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
@@ -261,6 +278,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
@@ -291,13 +318,12 @@ describe PanelsController do
   \r
   describe '新規作成に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @user.author.id\r
-      @attr = Factory.attributes_for(:panel, :author_id => @author.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
@@ -305,30 +331,26 @@ describe PanelsController do
         assigns(:prm)['border'].to_i.should eq @panel.border\r
       end\r
       it 'jsonがパラメータにあれば、展開する' do\r
-        post :create, :json => Factory.attributes_for(:panel, :border => 4).to_json\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), \r
-          :json => Factory.attributes_for(:panel, :border => 4).to_json\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
         Panel.any_instance.should_receive(:supply_default).exactly(1)\r
         post :create, :panel => @attr\r
       end\r
-      it 'コマモデルに上書き補充を依頼している' do\r
-        Panel.any_instance.should_receive(:overwrite).exactly(1)\r
-        post :create, :panel => @attr\r
-      end\r
       it 'モデルに保存依頼する' do\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 => @attr\r
         assigns(:panel).should be_a(Panel)\r
@@ -356,6 +378,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\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 => @attr, :format => :json\r
           json = JSON.parse response.body\r
@@ -421,17 +447,13 @@ describe PanelsController do
 \r
   describe '編集フォーム表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @author.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
@@ -439,12 +461,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
@@ -480,8 +510,8 @@ describe PanelsController do
 \r
   describe '更新に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @user.author.id\r
-      @attr = Factory.attributes_for(:panel, :author_id => @author.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
@@ -494,14 +524,14 @@ describe PanelsController do
         assigns(:prm)['border'].to_i.should eq @panel.border\r
       end\r
       it 'jsonがパラメータにあれば、展開する' do\r
-        put :update, :id => @panel.id, :json => Factory.attributes_for(:panel, :border => 4).to_json\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 => Factory.attributes_for(:panel), \r
-          :json => Factory.attributes_for(:panel, :border => 4).to_json\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
@@ -512,10 +542,6 @@ describe PanelsController do
         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(:overwrite).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
@@ -543,6 +569,11 @@ describe PanelsController do
           put :update, :id => @panel.id, :panel => @attr, :format => :json\r
           response.should be_success \r
         end\r
+        it 'ページ本体は特に返さない' do\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
     end\r
     context '作家権限がないとき' do\r
@@ -603,7 +634,7 @@ describe PanelsController do
 \r
   describe '削除に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @user.author.id\r
+      @panel = FactoryGirl.create :panel, :author_id => @user.author.id\r
       Panel.stub(:edit).and_return(@panel)\r
       sign_in @user\r
     end\r
@@ -616,7 +647,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
@@ -626,9 +657,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
@@ -663,6 +694,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
@@ -671,5 +727,415 @@ describe PanelsController do
 =end\r
   end\r
   \r
+else\r
+  describe '一覧表示に於いて' do\r
+    before do\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
+    context 'つつがなく終わるとき' do\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
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\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
+      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(:show).with(@panel.id.to_s, @author).and_return(@panel)\r
+      Panel.stub(:show).with(@panel.id.to_s, nil).and_return(@panel)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\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
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\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
+      end\r
+    end\r
+  end\r
+  \r
+  describe 'コマ数取得に於いて' do\r
+    before do\r
+      Panel.should_receive(:visible_count).and_return(3)\r
+#      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :count, :format => :json\r
+        response.should be_success \r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :count, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '新規作成フォーム表示に於いて' do\r
+    before do\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\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
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'new.jsテンプレートを描画する' do\r
+          get :new, :format => :js\r
+          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
+      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
+          get :new\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :new\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '新規作成に於いて' do\r
+    before do\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
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\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(: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(: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 => @attr, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\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
+          post :create, :panel => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\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 => @attr, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          post :create, :panel => @attr, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '編集フォーム表示に於いて' do\r
+    before do\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
+      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
+        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
+          get :edit, :id => @panel.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @panel.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :edit, :id => @panel.id, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :edit, :id => @panel.id, :format => :js\r
+          response.message.should match(/Unauthorized/)\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
+      @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\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
+#          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(: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(: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
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\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 => @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 => @attr, :format => :json\r
+          response.message.should match(/Unauthorized/)\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
+      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
+  end\r
+  \r
+end\r
 end\r
 \r