OSDN Git Service

t#31470:create pager
[pettanr/pettanr.git] / spec / controllers / panels_controller_spec.rb
index 7f1770b..848cf05 100644 (file)
@@ -3,14 +3,15 @@ require 'spec_helper'
 #コマ\r
 describe PanelsController do\r
   before do\r
-    FactoryGirl.create :admin\r
-    @sp = FactoryGirl.create :system_picture
-    @lg = FactoryGirl.create :license_group
-    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @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
+if MagicNumber['run_mode'] == 1\r
   describe '一覧表示に於いて' do\r
     before do\r
       @panel = FactoryGirl.create :panel, :author_id => @author.id\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,32 @@ describe PanelsController do
         assigns(:panels).should have_at_least(3).items\r
       end\r
       context 'html形式' do\r
+        it '@paginateにページ制御を取得している' do\r
+          get :index\r
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true\r
+        end\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
@@ -79,7 +92,7 @@ describe PanelsController do
         end\r
       end\r
     end\r
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
       before do\r
         sign_out @user\r
       end\r
@@ -104,19 +117,35 @@ describe PanelsController do
         end\r
       end\r
     end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \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).and_return(@panel)\r
+      Panel.stub(:show).with(@panel.id.to_s, [@user, nil]).and_return(@panel)\r
+      Panel.stub(:show).with(@panel.id.to_s, [nil, @admin]).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 +155,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
@@ -143,7 +184,7 @@ describe PanelsController do
         end\r
       end\r
     end\r
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
       before do\r
         sign_out @user\r
       end\r
@@ -168,6 +209,25 @@ describe PanelsController do
         end\r
       end\r
     end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+          get :show, :id => @panel.id\r
+        response.should be_success \r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+          get :show, :id => @panel.id\r
+        response.should be_success \r
+      end\r
+    end\r
 =begin\r
     context '対象コマがないとき' do\r
       context 'html形式' do\r
@@ -237,10 +297,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 +306,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,8 +321,18 @@ 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 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
       before do\r
         sign_out @user\r
       end\r
@@ -287,17 +357,47 @@ describe PanelsController do
         end\r
       end\r
     end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\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
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\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 new_author_path\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 = 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
@@ -315,20 +415,16 @@ describe PanelsController do
         }\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 +452,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
@@ -363,7 +463,7 @@ describe PanelsController do
         end\r
       end\r
     end\r
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
       before do\r
         sign_out @user\r
       end\r
@@ -388,6 +488,37 @@ describe PanelsController do
         end\r
       end\r
     end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\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
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\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 new_author_path\r
+        end\r
+      end\r
+    end\r
     context '検証、保存に失敗した' do\r
       before do\r
         Panel.any_instance.stub(:store).and_return(false)\r
@@ -426,12 +557,8 @@ describe PanelsController do
       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,19 +566,27 @@ 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
         end\r
       end\r
     end\r
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
       before do\r
         sign_out @user\r
       end\r
@@ -476,6 +611,37 @@ describe PanelsController do
         end\r
       end\r
     end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\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
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\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 new_author_path\r
+        end\r
+      end\r
+    end\r
   end\r
 \r
   describe '更新に於いて' do\r
@@ -512,10 +678,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,9 +705,14 @@ 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 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
       before do\r
         sign_out @user\r
       end\r
@@ -570,6 +737,37 @@ describe PanelsController do
         end\r
       end\r
     end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\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
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\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 new_author_path\r
+        end\r
+      end\r
+    end\r
     context '検証、保存に失敗した' do\r
       before do\r
         Panel.any_instance.stub(:store).and_return(false)\r
@@ -616,7 +814,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 +824,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
@@ -638,7 +836,7 @@ describe PanelsController do
         end\r
       end\r
     end\r
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do\r
       before do\r
         sign_out @user\r
       end\r
@@ -663,6 +861,62 @@ describe PanelsController do
         end\r
       end\r
     end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\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
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\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 new_author_path\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
@@ -671,5 +925,416 @@ 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, [nil, nil]).and_return(@panel)\r
+      Panel.stub(:show).with(@panel.id.to_s, [@user, nil]).and_return(@panel)\r
+      Panel.stub(:show).with(@panel.id.to_s, [nil, @admin]).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