OSDN Git Service

fix test
[pettanr/pettanr.git] / spec / controllers / panels_controller_spec.rb
index 64a6abf..019ca87 100644 (file)
@@ -3,118 +3,128 @@ require 'spec_helper'
 #コマ\r
 describe PanelsController do\r
   before do\r
-    Factory :admin\r
-    @license = Factory :license\r
-    @user = Factory :user_yas\r
-    @author = @user.author    #ユーザ作成時に連動して作成される\r
+    @admin =FactoryGirl.create :admin\r
+    @user_yas = FactoryGirl.create :user_yas_with_owner\r
+    @user_rom = FactoryGirl.create :user_rom\r
+    @author_yas =  @user_yas.author\r
+    \r
+    @my_model_class =  Panel   #操作モデル\r
   end\r
   \r
+if Manifest.manifest.magic_numbers['run_mode'] == 1\r
   describe '一覧表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @author.id\r
-      Panel.stub(:list).and_return([@panel, @panel, @panel])\r
-      sign_in @user\r
-    end\r
-    context '事前チェックする' do\r
-      it '与えられたpageがセットされている' do\r
-        get :index, :page => 5\r
-        assigns(:page).should eq 5\r
-      end\r
-      it '省略されると@pageに1値が入る' do\r
-        get :index\r
-        assigns(:page).should eq 1\r
-      end\r
-      it '与えられたpage_sizeがセットされている' do\r
-        get :index, :page_size => 15\r
-        assigns(:page_size).should eq 15\r
-      end\r
-      it '省略されると@page_sizeにデフォルト値が入る' do\r
-        get :index\r
-        assigns(:page_size).should eq Panel.default_page_size\r
-      end\r
-      it '最大を超えると@page_sizeにデフォルト最大値が入る' do\r
-        get :index, :page_size => 1500\r
-        assigns(:page_size).should eq Panel.max_page_size\r
-      end\r
-      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do\r
-        get :index, :page_size => 0\r
-        assigns(:page_size).should eq Panel.default_page_size\r
-      end\r
+      factory_contents :panel_hello, @author_yas\r
+      @query_play = { }\r
+      @query = {:mode => 'filer'}\r
+      @query_format_json = @query_play.merge(:format => :json)\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
+    \r
+    context '正常系' do\r
+      before do\r
+        sign_in @user_yas\r
       end\r
-      it '@panelsにリストを取得している' do\r
-        get :index\r
-        assigns(:panels).should have_at_least(3).items\r
+      context '共通処理' do\r
+        before do\r
+          get :index, @query\r
+        end\r
+        it 'コントローラのマニフェストから操作モデルを導出している' do\r
+          set_model? @my_model_class\r
+        end\r
+        it 'コントローラのマニフェストからリスト操作モデルを導出している' do\r
+          set_list_model? @my_model_class\r
+        end\r
+        it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do\r
+          set_list? 'panel', 'public'\r
+        end\r
+        it '@itemsにリストを取得している' do\r
+          expect(assigns(:items).size).to be >= 3\r
+        end\r
       end\r
       context 'html形式' do\r
-        it 'indexテンプレートを描画する' do\r
-          get :index\r
-          response.should render_template("index")\r
+        before do\r
+          get :index, @query\r
+        end\r
+        it 'ステータス OKを返して、ファイラーを描画している' do\r
+          return_ok?\r
+          render_filer?\r
+        end\r
+        it '@filerにファイラーを取得している' do\r
+          let_filer?\r
         end\r
       end\r
       context 'json形式' do\r
-        it 'jsonデータを返す' do\r
-          get :index, :format => :json\r
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        before do\r
+          get :index, @query_format_json\r
         end\r
-        it 'データがリスト構造になっている' do\r
-          get :index, :format => :json\r
-          json = JSON.parse response.body\r
-          json.should have_at_least(3).items\r
+        it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do\r
+          set_list? 'panel', 'public'\r
         end\r
-        it 'リストの先頭くらいはコマっぽいものであって欲しい' do\r
-          get :index, :format => :json\r
-          json = JSON.parse response.body\r
-          json.first.has_key?("border").should be_true\r
+        it 'ステータス OKを返して、jsonデータを返している' do\r
+          return_ok?\r
+          render_json?\r
+        end\r
+        it '@filerにファイラーをセットしていない' do\r
+          expect(assigns(:filer)).to be nil\r
         end\r
       end\r
     end\r
-    context '作家権限がないとき' do\r
-      before do\r
-        sign_out @user\r
-      end\r
+    context '件数取得' do\r
       context 'html形式' do\r
-        it 'ステータスコード302 Foundを返す' do\r
-          get :index\r
-          response.status.should eq 302\r
-        end\r
-        it 'サインインページへ遷移する' do\r
-          get :index\r
-          response.should redirect_to '/users/sign_in'\r
+        it '必要ないので実装していない' do\r
+          sign_in @user_yas\r
+          get :count, @query\r
+          expect(response.status).to eq(406)\r
         end\r
       end\r
       context 'json形式' do\r
-        it 'ステータスコード401 Unauthorizedを返す' do\r
-          get :index, :format => :json\r
-          response.status.should eq 401\r
+        it 'ステータス OKを返して、jsonデータを返している' do\r
+          sign_in @user_yas\r
+          get :count, @query_format_json\r
+          return_ok?\r
+          render_json?\r
         end\r
-        it '応答メッセージにUnauthorizedを返す' do\r
-          get :index, :format => :json\r
-          response.message.should match(/Unauthorized/)\r
+      end\r
+      context 'ゲスト(サインインしていない)' do\r
+        it '通常通り応答する' do\r
+          get :count, @query_format_json\r
+          return_ok?\r
+          render_json?\r
         end\r
       end\r
     end\r
+    context 'サインインの状態が例外的なとき' do\r
+      it 'ユーザではなく管理者でも通常通り応答している' do\r
+        sign_in @admin\r
+        get :index, @query\r
+        return_ok?\r
+        get :index, @query_format_json\r
+        render_json?\r
+      end\r
+      it '創作活動してないROM専の読者にも通常通り応答している' do\r
+        sign_in @user_rom\r
+        get :index, @query\r
+        return_ok?\r
+        get :index, @query_format_json\r
+        render_json?\r
+      end\r
+      it 'ゲスト(サインインしていない)はサインインページに遷移している' do\r
+        get :index, @query\r
+        redirect? sign_in_url\r
+        get :index, @query_format_json\r
+        render_unauthorized?\r
+      end\r
+    end\r
   end\r
   \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, [@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
@@ -124,16 +134,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
@@ -141,7 +163,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
@@ -166,6 +188,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
@@ -187,7 +228,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
@@ -196,7 +237,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
@@ -235,10 +276,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
@@ -248,6 +285,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
@@ -259,8 +300,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
@@ -285,17 +336,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 = 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
@@ -303,22 +384,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(: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
@@ -346,6 +431,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
@@ -353,7 +442,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
@@ -378,6 +467,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
@@ -411,17 +531,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
@@ -429,19 +545,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
@@ -466,12 +590,43 @@ 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
     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
@@ -484,22 +639,22 @@ 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
     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
+      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
@@ -529,9 +684,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
@@ -556,6 +716,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
@@ -587,5 +778,542 @@ describe PanelsController do
     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/panels')\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
+        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
+    context '他人のコマだったとき' do\r
+    end\r
+=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