OSDN Git Service

t#30443:add test for open mode
[pettanr/pettanr.git] / spec / controllers / artists_controller_spec.rb
index a2e1a32..7b929a7 100644 (file)
@@ -4,15 +4,16 @@ require 'spec_helper'
 
 describe ArtistsController do
   before do
-    FactoryGirl.create :admin
+    @admin = FactoryGirl.create :admin
     @sp = FactoryGirl.create :system_picture
     @lg = FactoryGirl.create :license_group
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     @user = FactoryGirl.create( :user_yas)
-    @author = @user.author
+    @author = FactoryGirl.create :author, :user_id => @user.id
     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
   end
   
+if MagicNumber['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
       Artist.stub(:list).and_return([@artist, @artist, @artist])
@@ -125,9 +126,9 @@ describe ArtistsController do
         Artist.should_receive(:show).exactly(1)
         get :show
       end
-      it '@artistにアレを取得している' do
+      it '@arにアレを取得している' do
         get :show, :id => @artist.id
-        assigns(:artist).should eq(@artist)
+        assigns(:ar).should eq(@artist)
       end
       context 'html形式' do
         it 'showテンプレートを描画する' do
@@ -220,35 +221,35 @@ describe ArtistsController do
     end
   end
 
-  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 '@artistに新規データを用意している' do\r
-        get :new\r
-        assigns(:artist).should be_a_new(Artist)\r
-      end\r
-      it '絵師モデルにデフォルト値補充を依頼している' do\r
-        Artist.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
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :new
+        response.should be_success 
+      end
+      it '@artistに新規データを用意している' do
+        get :new
+        assigns(:ar).should be_a_new(Artist)
+      end
+      it '絵師モデルにデフォルト値補充を依頼している' do
+        Artist.any_instance.should_receive(:supply_default).exactly(1)
+        get :new
+      end
+      context 'html形式' do
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
       context 'json形式' do
         it 'jsonデータを返す' do
           get :new, :format => :json
@@ -259,31 +260,31 @@ describe ArtistsController do
           get :new, :format => :json
         end
       end
-    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
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
       context 'json形式' do
         it 'ステータスコード401 Unauthorizedを返す' do
           get :new, :format => :json
@@ -294,290 +295,628 @@ describe ArtistsController do
           response.message.should match(/Unauthorized/)
         end
       end
-    end\r
-  end\r
-\r
-  describe '新規作成に於いて' do\r
-    before do\r
-      sign_in @user\r
-      @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')\r
-    end\r
-    context '事前チェックしておく' do\r
-      it '絵師モデルにデフォルト値補充を依頼している' do\r
-        Artist.any_instance.should_receive(:supply_default).exactly(1)\r
-        post :create, :artist => @attr\r
-      end
-      it '絵師モデルにカラム値復元を依頼している' do\r
-        Artist.any_instance.should_receive(:attributes=).exactly(1)\r
-        post :create, :artist => @attr\r
-      end\r
-      it '絵師モデルに上書き補充を依頼している' do\r
-        Artist.any_instance.should_receive(:overwrite).exactly(1)\r
-        post :create, :artist => @attr\r
-      end\r
-      it 'モデルに保存依頼する' do\r
-        Artist.any_instance.should_receive(:save).exactly(1)\r
-        post :create, :artist => @attr\r
-      end\r
-    end\r
-    context 'つつがなく終わるとき' do\r
-      it "@artistに作成された絵師を保持していて、それがDBにある" do\r
-        post :create, :artist => @attr\r
-        assigns(:artist).should be_a(Artist)\r
-        assigns(:artist).should be_persisted\r
-      end\r
-      context 'html形式' do\r
-        it 'ステータスコード302 Foundを返す' do\r
-          Artist.any_instance.stub(:save).and_return(true)\r
-          post :create, :artist => @attr\r
-          response.status.should eq 302\r
-        end\r
-        it '作成された絵師の表示ページへ遷移する' do\r
-#          Artist.any_instance.stub(:save).and_return(true)\r
-          post :create, :artist => @attr\r
-          response.should redirect_to(Artist.last)\r
-        end\r
-      end\r
-      context 'json形式' do\r
-        it 'ステータスコード200 OKを返す' do\r
-#          Artist.any_instance.stub(:save).and_return(true)\r
-          post :create, :artist => @attr, :format => :json\r
-          response.should be_success \r
-        end\r
-        it '作成された絵師をjsonデータで返す' do\r
-          post :create, :artist => @attr, :format => :json\r
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
-        end\r
+    end
+  end
+
+  describe '新規作成に於いて' do
+    before do
+      sign_in @user
+      @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
+    end
+    context '事前チェックしておく' do
+      it '絵師モデルにデフォルト値補充を依頼している' do
+        Artist.any_instance.should_receive(:supply_default).exactly(1)
+        post :create, :artist => @attr
+      end
+      it '絵師モデルにカラム値復元を依頼している' do
+        Artist.any_instance.should_receive(:attributes=).exactly(1)
+        post :create, :artist => @attr
+      end
+      it '絵師モデルに上書き補充を依頼している' do
+        Artist.any_instance.should_receive(:overwrite).exactly(1)
+        post :create, :artist => @attr
+      end
+      it 'モデルに保存依頼する' do
+        Artist.any_instance.should_receive(:save).exactly(1)
+        post :create, :artist => @attr
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it "@arに作成された絵師を保持していて、それがDBにある" do
+        post :create, :artist => @attr
+        assigns(:ar).should be_a(Artist)
+        assigns(:ar).should be_persisted
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Artist.any_instance.stub(:save).and_return(true)
+          post :create, :artist => @attr
+          response.status.should eq 302
+        end
+        it 'トップページへ遷移する' do
+#          Artist.any_instance.stub(:save).and_return(true)
+          post :create, :artist => @attr
+          response.should redirect_to(root_path)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Artist.any_instance.stub(:save).and_return(true)
+          post :create, :artist => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成された絵師をjsonデータで返す' do
+          post :create, :artist => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
         it '絵師モデルにjson単体出力オプションを問い合わせている' do
           Artist.should_receive(:show_json_opt).exactly(1)
-          post :create, :artist => @attr, :format => :json\r
-        end
-        it 'データがアレになっている' do\r
-          post :create, :artist => @attr, :format => :json\r
-          json = JSON.parse response.body\r
-          json["name"].should match(/ken/)\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, :artist => @attr\r
-          response.status.should eq 302\r
-        end\r
-        it 'サインインページへ遷移する' do\r
-          post :create, :artist => @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, :artist => @attr, :format => :json\r
-          response.status.should eq 401\r
-        end\r
-        it '応答メッセージにUnauthorizedを返す' do\r
-          post :create, :artist => @attr, :format => :json\r
-          response.message.should match(/Unauthorized/)\r
-        end\r
-      end\r
-    end\r
-    context '検証、保存に失敗した' do\r
-      before do\r
-        Artist.any_instance.stub(:save).and_return(false)\r
-      end\r
-      it "未保存の絵師を保持している" do\r
-        post :create, :artist => @attr\r
-        assigns(:artist).should be_a_new(Artist)\r
-      end\r
-      context 'html形式' do\r
-        it 'ステータスコード200 OKを返す' do\r
-          post :create, :artist => @attr\r
-          response.status.should eq 200\r
-        end\r
-        it '新規ページを描画する' do\r
-          post :create, :artist => @attr\r
-          response.should render_template("new")\r
-        end\r
-      end\r
-      context 'json形式' do\r
-        it 'ステータスコード422 unprocessable_entity を返す' do\r
-          post :create, :artist => @attr, :format => :json\r
-          response.status.should eq 422\r
-        end\r
-        it '応答メッセージUnprocessable Entityを返す' do\r
-          post :create, :artist => @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
-      sign_in @user\r
-      Artist.stub(:edit).and_return(@artist)\r
-    end\r
-    context 'つつがなく終わるとき' do\r
-      it 'ステータスコード200 OKを返す' do\r
-        get :edit, :id => @artist.id\r
-        response.should be_success \r
-      end\r
-      it '絵師モデルに編集取得を問い合わせている' do\r
-        Artist.should_receive(:edit).exactly(1)\r
-        get :edit, :id => @artist.id\r
-      end\r
-      it '@artistにデータを用意している' do\r
-        get :edit, :id => @artist.id\r
-        assigns(:artist).should eq @artist\r
-      end\r
-      context 'html形式' do\r
-        it 'editテンプレートを描画する' do\r
-          get :edit, :id => @artist.id\r
-          response.should render_template("edit")\r
-        end\r
-      end\r
-      context 'js形式' do\r
-        it 'edit.jsテンプレートを描画する' do\r
-          get :edit, :id => @artist.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 => @artist.id\r
-          response.status.should eq 302\r
-        end\r
-        it 'サインインページへ遷移する' do\r
-          get :edit, :id => @artist.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 => @artist.id, :format => :js\r
-          response.status.should eq 401\r
-        end\r
-        it '応答メッセージにUnauthorizedを返す' do\r
-          get :edit, :id => @artist.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
-      @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')\r
-      sign_in @user\r
-    end\r
-    context '事前チェックしておく' do\r
-      it '絵師モデルに編集取得を問い合わせている' do\r
-        Artist.stub(:edit).with(any_args()).and_return @artist\r
-        Artist.should_receive(:edit).exactly(1)\r
-        put :update, :id => @artist.id, :artist => @attr\r
-      end\r
-      it '絵師モデルにカラム値復元を依頼している' do\r
-        Artist.any_instance.should_receive(:attributes=).exactly(1)\r
-        put :update, :id => @artist.id, :artist => @attr\r
-      end\r
-      it '絵師モデルに上書き補充を依頼している' do\r
-        Artist.any_instance.should_receive(:overwrite).exactly(1)\r
-        put :update, :id => @artist.id, :artist => @attr\r
-      end\r
-      it 'モデルに更新を依頼する' do\r
-        Artist.any_instance.stub(:save).with(any_args).and_return true\r
-        Artist.any_instance.should_receive(:save).exactly(1)\r
-        put :update, :id => @artist.id, :artist => @attr\r
-      end\r
-      it '@artistにアレを取得している' do\r
-        put :update, :id => @artist.id, :artist => @attr\r
-        assigns(:artist).should eq @artist\r
-      end\r
-    end\r
-    context 'つつがなく終わるとき' do\r
-      it '更新される' do\r
-        put :update, :id => @artist.id, :artist => @attr\r
-        Artist.find(@artist.id).name.should eq 'ryu'\r
-      end\r
-      context 'html形式' do\r
-        it 'ステータスコード302 Foundを返す' do\r
-          Artist.any_instance.stub(:save).with(any_args()).and_return(true)\r
-          put :update, :id => @artist.id, :artist => @attr\r
-          response.status.should eq 302\r
-        end\r
-        it '更新された絵師の表示ページへ遷移する' do\r
-          put :update, :id => @artist.id, :artist => @attr\r
-          response.should redirect_to(@artist)\r
-        end\r
-      end\r
-      context 'json形式' do\r
-        it 'ステータスコード200 OKを返す' do\r
-          Artist.any_instance.stub(:save).with(any_args()).and_return(true)\r
-          put :update, :id => @artist.id, :artist => @attr, :format => :json\r
-          response.should be_success \r
-        end\r
-        it 'ページ本体は特に返さない' do\r
-          Artist.any_instance.stub(:save).with(any_args()).and_return(true)\r
-          put :update, :id => @artist.id, :artist => @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 => @artist.id, :artist => @attr\r
-        response.status.should eq 302\r
-      end\r
-      context 'html形式' do\r
-        it 'サインインページへ遷移する' do\r
-          put :update, :id => @artist.id, :artist => @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 => @artist.id, :artist => @attr, :format => :json\r
-          response.message.should match(/Unauthorized/)\r
-        end\r
-      end\r
-    end\r
-    context '検証、保存に失敗したとき' do\r
-      before do\r
-        Artist.any_instance.stub(:save).and_return(false)\r
-      end\r
-      context 'html形式' do\r
-        it 'ステータスコード200 Okを返す' do\r
-          put :update, :id => @artist.id, :artist => @attr\r
-          response.status.should eq 200\r
-        end\r
-        it '編集ページを描画する' do\r
-          put :update, :id => @artist.id, :artist => @attr\r
-          response.should render_template("edit")\r
-        end\r
-      end\r
-      context 'json形式' do\r
-        it 'ステータスコード422 unprocessable_entity を返す' do\r
-          Artist.any_instance.stub(:save).and_return(false)\r
-          put :update, :id => @artist.id, :artist => @attr, :format => :json\r
-          response.status.should eq 422\r
-        end\r
-        it '応答メッセージUnprocessable Entityを返す' do\r
-          put :update, :id => @artist.id, :artist => @attr, :format => :json\r
-          response.message.should match(/Unprocessable/)\r
-        end\r
-      end\r
-    end\r
-  end\r
-\r
+          post :create, :artist => @attr, :format => :json
+        end
+        it 'データがアレになっている' do
+          post :create, :artist => @attr, :format => :json
+          json = JSON.parse response.body
+          json["name"].should match(/ken/)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :artist => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :artist => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :artist => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :artist => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        Artist.any_instance.stub(:save).and_return(false)
+      end
+      it "未保存の絵師を保持している" do
+        post :create, :artist => @attr
+        assigns(:ar).should be_a_new(Artist)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          post :create, :artist => @attr
+          response.status.should eq 200
+        end
+        it '新規ページを描画する' do
+          post :create, :artist => @attr
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          post :create, :artist => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          post :create, :artist => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      sign_in @user
+      Artist.stub(:edit).and_return(@artist)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :edit, :id => @artist.id
+        response.should be_success 
+      end
+      it '絵師モデルに編集取得を問い合わせている' do
+        Artist.should_receive(:edit).exactly(1)
+        get :edit, :id => @artist.id
+      end
+      it '@artistにデータを用意している' do
+        get :edit, :id => @artist.id
+        assigns(:artist).should eq @artist
+      end
+      context 'html形式' do
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @artist.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @artist.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @artist.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @artist.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @artist.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @artist.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
+      sign_in @user
+    end
+    context '事前チェックしておく' do
+      it '絵師モデルに編集取得を問い合わせている' do
+        Artist.stub(:edit).with(any_args()).and_return @artist
+        Artist.should_receive(:edit).exactly(1)
+        put :update, :id => @artist.id, :artist => @attr
+      end
+      it '絵師モデルにカラム値復元を依頼している' do
+        Artist.any_instance.should_receive(:attributes=).exactly(1)
+        put :update, :id => @artist.id, :artist => @attr
+      end
+      it '絵師モデルに上書き補充を依頼している' do
+        Artist.any_instance.should_receive(:overwrite).exactly(1)
+        put :update, :id => @artist.id, :artist => @attr
+      end
+      it 'モデルに更新を依頼する' do
+        Artist.any_instance.stub(:save).with(any_args).and_return true
+        Artist.any_instance.should_receive(:save).exactly(1)
+        put :update, :id => @artist.id, :artist => @attr
+      end
+      it '@arにアレを取得している' do
+        put :update, :id => @artist.id, :artist => @attr
+        assigns(:ar).should eq @artist
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '更新される' do
+        put :update, :id => @artist.id, :artist => @attr
+        Artist.find(@artist.id).name.should eq 'ryu'
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Artist.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @artist.id, :artist => @attr
+          response.status.should eq 302
+        end
+        it '設定ページへ遷移する' do
+          put :update, :id => @artist.id, :artist => @attr
+          response.should redirect_to('/home/configure')
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          Artist.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          Artist.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード302 Foundを返す' do
+        put :update, :id => @artist.id, :artist => @attr
+        response.status.should eq 302
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          put :update, :id => @artist.id, :artist => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context '検証、保存に失敗したとき' do
+      before do
+        Artist.any_instance.stub(:save).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 Okを返す' do
+          put :update, :id => @artist.id, :artist => @attr
+          response.status.should eq 200
+        end
+        it '編集ページを描画する' do
+          put :update, :id => @artist.id, :artist => @attr
+          response.should render_template("edit")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          Artist.any_instance.stub(:save).and_return(false)
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+else
+  describe '一覧表示に於いて' do
+    before do
+      Artist.stub(:list).and_return([@artist, @artist, @artist])
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '閲覧に於いて' do
+    before do
+      Artist.stub(:show).and_return(@artist)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @artist.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @artist.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @artist.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @artist.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @artist.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @artist.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '絵師数取得に於いて' do
+    before do
+      Artist.should_receive(:visible_count).and_return(3)
+#      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :count, :format => :json
+        response.should be_success 
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :count, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :new
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '新規作成に於いて' do
+    before do
+      sign_in @user
+      @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Artist.any_instance.stub(:save).and_return(true)
+          post :create, :artist => @attr
+          response.status.should eq 302
+        end
+        it 'トップページへ遷移する' do
+#          Artist.any_instance.stub(:save).and_return(true)
+          post :create, :artist => @attr
+          response.should redirect_to(root_path)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Artist.any_instance.stub(:save).and_return(true)
+          post :create, :artist => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成された絵師をjsonデータで返す' do
+          post :create, :artist => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :artist => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :artist => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :artist => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :artist => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      sign_in @user
+      Artist.stub(:edit).and_return(@artist)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :edit, :id => @artist.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @artist.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @artist.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @artist.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @artist.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @artist.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @artist.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Artist.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @artist.id, :artist => @attr
+          response.status.should eq 302
+        end
+        it '設定ページへ遷移する' do
+          put :update, :id => @artist.id, :artist => @attr
+          response.should redirect_to('/home/configure')
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          Artist.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          Artist.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード302 Foundを返す' do
+        put :update, :id => @artist.id, :artist => @attr
+        response.status.should eq 302
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          put :update, :id => @artist.id, :artist => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @artist.id, :artist => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+end
 end