OSDN Git Service

add: social button
[pettanr/pettanr.git] / spec / controllers / comics_controller_spec.rb
index 7a11c89..449cbcb 100644 (file)
-require 'spec_helper'
-
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator.  If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails.  There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec.  Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
-describe ComicsController do
-
-  # This should return the minimal set of attributes required to create a valid
-  # Comic. As you add validations to Comic, be sure to
-  # update the return value of this method accordingly.
-  def valid_attributes
-    {}
-  end
-
-  describe "GET index" do
-    it "assigns all comics as @comics" do
-      comic = Comic.create! valid_attributes
-      get :index
-      assigns(:comics).should eq([comic])
-    end
-  end
-
-  describe "GET show" do
-    it "assigns the requested comic as @comic" do
-      comic = Comic.create! valid_attributes
-      get :show, :id => comic.id
-      assigns(:comic).should eq(comic)
-    end
-  end
-
-  describe "GET new" do
-    it "assigns a new comic as @comic" do
-      get :new
-      assigns(:comic).should be_a_new(Comic)
-    end
-  end
-
-  describe "GET edit" do
-    it "assigns the requested comic as @comic" do
-      comic = Comic.create! valid_attributes
-      get :edit, :id => comic.id
-      assigns(:comic).should eq(comic)
-    end
-  end
-
-  describe "POST create" do
-    describe "with valid params" do
-      it "creates a new Comic" do
-        expect {
-          post :create, :comic => valid_attributes
-        }.to change(Comic, :count).by(1)
-      end
-
-      it "assigns a newly created comic as @comic" do
-        post :create, :comic => valid_attributes
-        assigns(:comic).should be_a(Comic)
-        assigns(:comic).should be_persisted
-      end
-
-      it "redirects to the created comic" do
-        post :create, :comic => valid_attributes
-        response.should redirect_to(Comic.last)
-      end
-    end
-
-    describe "with invalid params" do
-      it "assigns a newly created but unsaved comic as @comic" do
-        # Trigger the behavior that occurs when invalid params are submitted
-        Comic.any_instance.stub(:save).and_return(false)
-        post :create, :comic => {}
-        assigns(:comic).should be_a_new(Comic)
-      end
-
-      it "re-renders the 'new' template" do
-        # Trigger the behavior that occurs when invalid params are submitted
-        Comic.any_instance.stub(:save).and_return(false)
-        post :create, :comic => {}
-        response.should render_template("new")
-      end
-    end
-  end
-
-  describe "PUT update" do
-    describe "with valid params" do
-      it "updates the requested comic" do
-        comic = Comic.create! valid_attributes
-        # Assuming there are no other comics in the database, this
-        # specifies that the Comic created on the previous line
-        # receives the :update_attributes message with whatever params are
-        # submitted in the request.
-        Comic.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
-        put :update, :id => comic.id, :comic => {'these' => 'params'}
-      end
-
-      it "assigns the requested comic as @comic" do
-        comic = Comic.create! valid_attributes
-        put :update, :id => comic.id, :comic => valid_attributes
-        assigns(:comic).should eq(comic)
-      end
-
-      it "redirects to the comic" do
-        comic = Comic.create! valid_attributes
-        put :update, :id => comic.id, :comic => valid_attributes
-        response.should redirect_to(comic)
-      end
-    end
-
-    describe "with invalid params" do
-      it "assigns the comic as @comic" do
-        comic = Comic.create! valid_attributes
-        # Trigger the behavior that occurs when invalid params are submitted
-        Comic.any_instance.stub(:save).and_return(false)
-        put :update, :id => comic.id, :comic => {}
-        assigns(:comic).should eq(comic)
-      end
-
-      it "re-renders the 'edit' template" do
-        comic = Comic.create! valid_attributes
-        # Trigger the behavior that occurs when invalid params are submitted
-        Comic.any_instance.stub(:save).and_return(false)
-        put :update, :id => comic.id, :comic => {}
-        response.should render_template("edit")
-      end
-    end
-  end
-
-  describe "DELETE destroy" do
-    it "destroys the requested comic" do
-      comic = Comic.create! valid_attributes
-      expect {
-        delete :destroy, :id => comic.id
-      }.to change(Comic, :count).by(-1)
-    end
-
-    it "redirects to the comics list" do
-      comic = Comic.create! valid_attributes
-      delete :destroy, :id => comic.id
-      response.should redirect_to(comics_url)
-    end
-  end
-
-end
+# -*- encoding: utf-8 -*-\r
+require 'spec_helper'\r
+#コミック\r
+describe ComicsController do\r
+  before do\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
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      Comic.stub(:list).and_return([@comic, @comic, @comic])\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 Comic.default_page_size\r
+      end\r
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do\r
+        get :index, :page_size => 1500\r
+        assigns(:page_size).should eq Comic.max_page_size\r
+      end\r
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do\r
+        get :index, :page_size => 0\r
+        assigns(:page_size).should eq Comic.default_page_size\r
+      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
+        Comic.should_receive(:list).exactly(1)\r
+        get :index\r
+      end\r
+      it '@comicsにリストを取得している' do\r
+        get :index\r
+        assigns(:comics).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 'indexテンプレートを描画する' do\r
+          get :index\r
+          response.should render_template("index")\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
+        end\r
+        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do\r
+          Comic.should_receive(:list_json_opt).exactly(1)\r
+          get :index, :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
+        end\r
+        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do\r
+          get :index, :format => :json\r
+          json = JSON.parse response.body\r
+          json.first.has_key?("title").should be_true\r
+          json.first.has_key?("visible").should be_true\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 :index\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :index\r
+          response.should redirect_to '/users/sign_in'\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
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :index, :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
+      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
+      context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :index\r
+          response.should be_success \r
+        end\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '単体表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id, :title => 'normal'\r
+      Comic.stub(:show).and_return(@comic)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success\r
+      end\r
+      it 'コミックモデルに単体取得を問い合わせている' do\r
+        Comic.should_receive(:show).exactly(1)\r
+        get :show\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        get :show, :id => @comic.id\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+      context 'html形式' do\r
+        it 'showテンプレートを描画する' do\r
+          get :show, :id => @comic.id\r
+          response.should render_template("show")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'コミックモデルにjson単体出力オプションを問い合わせている' do\r
+          Comic.should_receive(:show_json_opt).exactly(1)\r
+          get :show, :id => @comic.id, :format => :json\r
+        end\r
+        it 'データがアレになっている' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          json = JSON.parse response.body\r
+          json["title"].should match(/normal/)\r
+          json["visible"].should_not be_nil\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 :show, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :show, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :show, :id => @comic.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
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success \r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :show, :id => @comic.id\r
+          response.should be_success\r
+        end\r
+      end\r
+    end\r
+=begin\r
+    context '対象コミックがないとき' do\r
+      context 'html形式' do\r
+        it '例外404 not_foundを返す' do\r
+          lambda{\r
+            get :show, :id => 0\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '例外404 not_foundを返す' do\r
+          lambda{ \r
+            get :show, :id => 0, :format => :json\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+    end\r
+    context '非公開コミックを見ようとしたとき' do\r
+      context 'html形式' do\r
+        it '例外403 forbiddenを返す' do\r
+          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+          hidden = FactoryGirl.create :hidden_comic, :author_id => @author.id\r
+          lambda{\r
+            get :show, :id => hidden\r
+          }.should raise_error(ActiveRecord::Forbidden)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '例外403 forbiddenを返す' do\r
+          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+          hidden = FactoryGirl.create :hidden_comic, :author_id => @author.id\r
+          lambda{\r
+            get :show, :id => hidden, :format => :json\r
+          }.should raise_error(ActiveRecord::Forbidden)\r
+        end\r
+      end\r
+    end\r
+=end\r
+  end\r
+  describe 'コミック数取得に於いて' do\r
+    before do\r
+      Comic.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
+        it 'データがHash構造になっていてコミック数が1である' do\r
+          get :count, :format => :json\r
+          json = JSON.parse response.body\r
+          json["count"].should == 3\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
+      it 'ステータスコード200 OKを返す' do\r
+        get :new\r
+        response.should be_success \r
+      end\r
+      it '@comicに新規データを用意している' do\r
+        get :new\r
+        assigns(:comic).should be_a_new(Comic)\r
+      end\r
+      it 'コミックモデルにデフォルト値補充を依頼している' do\r
+        Comic.any_instance.should_receive(:supply_default).exactly(1)\r
+        get :new\r
+      end\r
+      context 'html形式' do\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
+        it 'コミックモデルにjson単体出力オプションを問い合わせている' do\r
+          Comic.should_receive(:show_json_opt).exactly(1)\r
+          get :new, :format => :json\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
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :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
+          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, @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          get :new, @attr\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
+      sign_in @user\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'normal')\r
+    end\r
+    context '事前チェックしておく' do\r
+      it 'コミックモデルにデフォルト値補充を依頼している' do\r
+        Comic.any_instance.should_receive(:supply_default).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+      it 'コミックモデルにカラム値復元を依頼している' do\r
+        Comic.any_instance.should_receive(:attributes=).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+      it 'コミックモデルに上書き補充を依頼している' do\r
+        Comic.any_instance.should_receive(:overwrite).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+      it 'モデルに保存依頼する' do\r
+        Comic.any_instance.should_receive(:save).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it "@comicに作成されたコミックを保持していて、それがDBにある" do\r
+        post :create, :comic => @attr\r
+        assigns(:comic).should be_a(Comic)\r
+        assigns(:comic).should be_persisted\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作成されたコミックの表示ページへ遷移する' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.should redirect_to(Comic.last)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it '作成されたコミックをjsonデータで返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがアレになっている' do\r
+          post :create, :comic => @attr, :format => :json\r
+          json = JSON.parse response.body\r
+          json["title"].should match(/normal/)\r
+          json["visible"].should_not be_nil\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, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          post :create, :comic => @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, :comic => @attr, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          post :create, :comic => @attr, :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
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          post :create, :comic => @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, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          post :create, :comic => @attr\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+    context '検証、保存に失敗した' do\r
+      before do\r
+        Comic.any_instance.stub(:save).and_return(false)\r
+      end\r
+      it "未保存のコミックを保持している" do\r
+        post :create, :comic => @attr\r
+        assigns(:comic).should be_a_new(Comic)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          post :create, :comic => @attr\r
+          response.status.should eq 200\r
+        end\r
+        it '新規ページを描画する' do\r
+          post :create, :comic => @attr\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '編集フォーム表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      sign_in @user\r
+      Comic.stub(:edit).and_return(@comic)\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :edit, :id => @comic.id\r
+        response.should be_success \r
+      end\r
+      it 'コミックモデルに編集取得を問い合わせている' do\r
+        Comic.should_receive(:edit).exactly(1)\r
+        get :edit, :id => @comic.id\r
+      end\r
+      it '@comicにデータを用意している' do\r
+        get :edit, :id => @comic.id\r
+        assigns(:comic).should eq @comic\r
+      end\r
+      context 'html形式' do\r
+        it 'editテンプレートを描画する' do\r
+          get :edit, :id => @comic.id\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'edit.jsテンプレートを描画する' do\r
+          get :edit, :id => @comic.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 => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @comic.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 => @comic.id, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :edit, :id => @comic.id, :format => :js\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
+          get :edit, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @comic.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 => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          get :edit, :id => @comic.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
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'updated title', :visible => 0)\r
+      sign_in @user\r
+    end\r
+    context '事前チェックしておく' do\r
+      it 'コミックモデルに編集取得を問い合わせている' do\r
+        Comic.stub(:edit).with(any_args()).and_return @comic\r
+        Comic.should_receive(:edit).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it 'コミックモデルにカラム値復元を依頼している' do\r
+        Comic.any_instance.should_receive(:attributes=).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it 'コミックモデルに上書き補充を依頼している' do\r
+        Comic.any_instance.should_receive(:overwrite).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it 'モデルに更新を依頼する' do\r
+        Comic.any_instance.stub(:save).with(any_args).and_return true\r
+        Comic.any_instance.should_receive(:save).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '更新される' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        Comic.find(@comic.id).visible.should eq 0\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '更新されたコミックの表示ページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should redirect_to(@comic)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @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 => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr, :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
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @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 => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+    context '検証、保存に失敗したとき' do\r
+      before do\r
+        Comic.any_instance.stub(:save).and_return(false)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 Okを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 200\r
+        end\r
+        it '編集ページを描画する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          Comic.any_instance.stub(:save).and_return(false)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '削除に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      sign_in @user\r
+    end\r
+    context '事前チェックしておく' do\r
+      before do\r
+        Comic.stub(:edit).with(any_args()).and_return @comic\r
+        Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+      end\r
+      it 'コミックモデルに編集取得を問い合わせている' do\r
+        Comic.should_receive(:edit).exactly(1)\r
+        delete :destroy, :id => @comic.id\r
+      end\r
+      it 'モデルに削除を依頼する' do\r
+        Comic.any_instance.should_receive(:destroy_with_story).exactly(1)\r
+        delete :destroy, :id => @comic.id\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        delete :destroy, :id => @comic.id\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '削除される' do\r
+        lambda {\r
+          delete :destroy, :id => @comic.id\r
+        }.should change Comic, :count\r
+      end\r
+      context 'html形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'マイコミックの一覧ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.should redirect_to('/home/comics')\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード200 OKを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          delete :destroy, :id => @comic.id, :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
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          delete :destroy, :id => @comic.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 => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          delete :destroy, :id => @comic.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 => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+    context '削除に失敗したとき' do\r
+      before do\r
+        Comic.any_instance.stub(:destroy_with_story).and_return(false)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'そのコミックの詳細ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.should redirect_to(comic_path(@comic))\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+else\r
+  describe '一覧表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      Comic.stub(:list).and_return([@comic, @comic, @comic])\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\r
+        it 'indexテンプレートを描画する' do\r
+          get :index\r
+          response.should render_template("index")\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
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\r
+        it 'indexテンプレートを描画する' do\r
+          get :index\r
+          response.should render_template("index")\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
+        end\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '単体表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id, :title => 'normal'\r
+      Comic.stub(:show).and_return(@comic)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success\r
+      end\r
+      context 'html形式' do\r
+        it 'showテンプレートを描画する' do\r
+          get :show, :id => @comic.id\r
+          response.should render_template("show")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :show, :id => @comic.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
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success\r
+      end\r
+      context 'html形式' do\r
+        it 'showテンプレートを描画する' do\r
+          get :show, :id => @comic.id\r
+          response.should render_template("show")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+  end\r
+  describe 'コミック数取得に於いて' do\r
+    before do\r
+      Comic.should_receive(:visible_count).and_return(3)\r
+      sign_out @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
+      it 'ステータスコード200 OKを返す' do\r
+        get :new\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\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
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '新規作成に於いて' do\r
+    before do\r
+      sign_in @user\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'normal')\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作成されたコミックの表示ページへ遷移する' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.should redirect_to(Comic.last)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it '作成されたコミックをjsonデータで返す' do\r
+          post :create, :comic => @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, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          post :create, :comic => @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, :comic => @attr, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          post :create, :comic => @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
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      sign_in @user\r
+      Comic.stub(:edit).and_return(@comic)\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :edit, :id => @comic.id\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\r
+        it 'editテンプレートを描画する' do\r
+          get :edit, :id => @comic.id\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'edit.jsテンプレートを描画する' do\r
+          get :edit, :id => @comic.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 => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @comic.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 => @comic.id, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :edit, :id => @comic.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
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'updated title', :visible => 0)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '更新されたコミックの表示ページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should redirect_to(@comic)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @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
+      it 'ステータスコード302 Foundを返す' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        response.status.should eq 302\r
+      end\r
+      context 'html形式' do\r
+        it 'サインインページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '削除に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      context 'html形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'マイコミックの一覧ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.should redirect_to('/home/comic')\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード200 OKを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          delete :destroy, :id => @comic.id, :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
+      it 'ステータスコード302 Foundを返す' do\r
+        delete :destroy, :id => @comic.id\r
+        response.status.should eq 302\r
+      end\r
+      context 'html形式' do\r
+        it 'サインインページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+end\r
+\r
+end\r