OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / original_pictures_controller_spec.rb
index 4a325ef..8a06063 100644 (file)
@@ -13,6 +13,7 @@ describe OriginalPicturesController do
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
   end
 
+if MagicNumber['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
@@ -59,6 +60,10 @@ describe OriginalPicturesController do
         assigns(:original_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
@@ -88,7 +93,7 @@ describe OriginalPicturesController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -113,9 +118,25 @@ describe OriginalPicturesController do
         end
       end
     end
-    context '作家が絵師でないとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザが絵師でないとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -238,7 +259,7 @@ describe OriginalPicturesController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -263,26 +284,23 @@ describe OriginalPicturesController do
         end
       end
     end
-    context '作家が絵師でないとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        sign_out @user
+        sign_in @admin
       end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :show, :id => @pic.id
-          response.status.should eq 302
-        end
-        it '絵師登録ページへ遷移する' do
-          get :show, :id => @pic.id
-          response.should redirect_to new_artist_path
-        end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @pic.id
+        response.should be_success 
       end
-      context 'json形式' do
-        it '例外403 forbiddenを返す' do
-          lambda{
-            get :show, :id => @pic.id, :format => :json
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
+    end
+    context 'ユーザが絵師でないとき' do
+      before do
+        @artist.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @pic.id
+        response.should be_success 
       end
     end
 =begin
@@ -377,7 +395,7 @@ describe OriginalPicturesController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -402,26 +420,23 @@ describe OriginalPicturesController do
         end
       end
     end
-    context '作家が絵師でないとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        sign_out @user
+        sign_in @admin
       end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :history, :id => @op.id
-          response.status.should eq 302
-        end
-        it '絵師登録ページへ遷移する' do
-          get :history, :id => @op.id
-          response.should redirect_to new_artist_path
-        end
+      it 'ステータスコード200 OKを返す' do
+        get :history, :id => @op.id
+        response.should be_success 
       end
-      context 'json形式' do
-        it '例外403 forbiddenを返す' do
-          lambda{
-            get :history, :id => @op.id, :format => :json
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
+    end
+    context 'ユーザが絵師でないとき' do
+      before do
+        @artist.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :history, :id => @op.id
+        response.should be_success 
       end
     end
   end
@@ -470,7 +485,7 @@ describe OriginalPicturesController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -495,34 +510,40 @@ describe OriginalPicturesController do
         end
       end
     end
-    context '作家が絵師でないとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        sign_out @user
+        sign_in @admin
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
           get :new
           response.status.should eq 302
         end
-        it '絵師登録ページへ遷移する' do
+        it 'サインインページへ遷移する' do
           get :new
-          response.should redirect_to new_artist_path
+          response.body.should redirect_to '/users/sign_in'
         end
       end
-      context 'js形式' do
-        it 'ステータスコード200 Okを返す' do
-          get :new, :format => :js
-          response.status.should eq 200
+    end
+    context 'ユーザが絵師でないとき' do
+      before do
+        @artist.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
         end
-        it '絵師登録é\83¨å\88\86ã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88artists/new.jsã\82\92æ\8f\8fç\94»ã\81\99ã\82\8b' do
-          get :new, :format => :js
-          response.should render_template("artists/new")
+        it '絵師登録ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99ã\82\8b' do
+          get :new
+          response.should redirect_to new_artist_path
         end
       end
       context 'json形式' do
         it '例外403 forbiddenを返す' do
           lambda{
-          get :new, :format => :json
+            get :new, :format => :json
           }.should raise_error(ActiveRecord::Forbidden)
         end
       end
@@ -602,7 +623,7 @@ describe OriginalPicturesController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -630,9 +651,25 @@ describe OriginalPicturesController do
         end
       end
     end
-    context '作家が絵師でないとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザが絵師でないとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -649,6 +686,7 @@ describe OriginalPicturesController do
           @attr.merge!({:format => :json})
         end
         it '例外403 forbiddenを返す' do
+          @attr.merge!({:format => :json})
           lambda{
             post :create, @attr
           }.should raise_error(ActiveRecord::Forbidden)
@@ -688,6 +726,39 @@ describe OriginalPicturesController do
         end
       end
     end
+    context 'ファイルが指定されていないとき' do
+      before do
+        @attr = {}
+        PettanImager.stub(:load).and_return(nil)
+      end
+      it "未保存の原画を保持している" do
+        post :create, @attr
+        assigns(:original_picture).should be_a_new(OriginalPicture)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          post :create, @attr
+          response.status.should eq 200
+        end
+        it '新規ページを描画する' do
+          post :create, @attr
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        before do
+          @attr.merge!({:format => :json})
+        end
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          post :create, @attr
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          post :create, @attr
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
   end
 
   describe '編集フォーム表示に於いて' do
@@ -722,7 +793,7 @@ describe OriginalPicturesController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -747,9 +818,25 @@ describe OriginalPicturesController do
         end
       end
     end
-    context '作家が絵師でないとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @pic.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @pic.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザが絵師でないとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -761,14 +848,11 @@ describe OriginalPicturesController do
           response.should redirect_to new_artist_path
         end
       end
-      context 'js形式' do
-        it 'ステータスコード200 Okを返す' do
-          get :edit, :id => @pic.id, :format => :js
-          response.status.should eq 200
-        end
-        it '絵師登録部分テンプレートartists/new.jsを描画する' do
-          get :edit, :id => @pic.id, :format => :js
-          response.should render_template("artists/new")
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          lambda{
+            get :edit, :id => @pic.id, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
@@ -834,7 +918,7 @@ describe OriginalPicturesController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -859,9 +943,25 @@ describe OriginalPicturesController do
         end
       end
     end
-    context '作家が絵師でないとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザが絵師でないとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -907,6 +1007,682 @@ describe OriginalPicturesController do
         end
       end
     end
+    context 'ファイルが指定されていないとき' do
+      before do
+        @attr = {}
+        PettanImager.stub(:load).and_return(nil)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 Okを返す' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.status.should eq 200
+        end
+        it '編集ページを描画する' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.should render_template("edit")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
   end
 
+  describe '削除に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      sign_in @user
+    end
+    context '事前チェックしておく' do
+      before do
+        OriginalPicture.stub(:edit).with(any_args()).and_return @op
+        OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+      end
+      it '原画モデルに編集取得を問い合わせている' do
+        OriginalPicture.should_receive(:edit).exactly(1)
+        delete :destroy, :id => @op.id
+      end
+      it 'モデルに削除を依頼する' do
+        OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
+        delete :destroy, :id => @op.id
+      end
+      it '@original_pictureにアレを取得している' do
+        delete :destroy, :id => @op.id
+        assigns(:original_picture).id.should eq(@op.id)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @op.id
+          response.status.should eq 302
+        end
+        it '原画の一覧ページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.should redirect_to(original_pictures_path)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @op.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @op.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザが絵師でないとき' do
+      before do
+        @artist.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @op.id
+          response.status.should eq 302
+        end
+        it '絵師登録ページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.should redirect_to new_artist_path
+        end
+      end
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          lambda{
+            delete :destroy, :id => @op.id, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
+        end
+      end
+    end
+    context '削除に失敗したとき' do
+      before do
+        OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @op.id
+          response.status.should eq 302
+        end
+        it 'その原画の詳細ページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.should redirect_to(original_picture_path(@op))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+else
+  describe '一覧表示に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      sign_in @user
+      OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
+    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
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      sign_in @user
+      OriginalPicture.stub(:show).and_return(@pic)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @pic.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @pic.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @pic.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
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :show, :id => @pic.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @pic.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @pic.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @pic.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '履歴一覧表示に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
+        :original_picture_id => @op.id
+      sign_in @user
+      OriginalPicture.stub(:show).and_return(@op)
+      OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :history, :id => @op.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'historyテンプレートを描画する' do
+          get :history, :id => @op.id
+          response.should render_template("history")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :history, :id => @op.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
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :history, :id => @op.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :history, :id => @op.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :history, :id => @op.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :history, :id => @op.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new
+          response.should be_success 
+        end
+        it 'ページテンプレートnewを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :js
+          response.should be_success 
+        end
+        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
+    end
+  end
+
+  describe '新規作成に於いて' do
+    before do
+      sign_in @user
+      @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
+      @imager = ImagerTest.load("abc\ndef\nghi")
+      OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, @attr
+          response.status.should eq 302
+        end
+        it '作成された原画の表示ページへ遷移する' do
+          post :create, @attr
+          response.should redirect_to(OriginalPicture.last)
+        end
+      end
+      context 'json形式' do
+        before do
+          @attr.merge!({:format => :json})
+        end
+        it 'ステータスコード200 OKを返す' do
+          post :create, @attr
+          response.should be_success 
+        end
+        it '作成された原画をjsonデータで返す' do
+          post :create, @attr
+          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, @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        before do
+          @attr.merge!({:format => :json})
+        end
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, @attr
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, @attr
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      sign_in @user
+      OriginalPicture.stub(:show).and_return(@pic)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :edit, :id => @pic.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'ページテンプレートeditを描画する' do
+          get :edit, :id => @pic.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it '部分テンプレートedit.jsを描画する' do
+          get :edit, :id => @pic.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 => @pic.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @pic.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @pic.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @pic.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+      OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+      sign_in @user
+      @attr = {:file => "abc\ndef\nghi"}
+      @imager = ImagerTest.load("abc\ndef\nghi")
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.status.should eq 302
+        end
+        it '更新された原画の表示ページへ遷移する' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.should redirect_to(@pic)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+        OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 Okを返す' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.status.should eq 200
+        end
+        it '編集ページを描画する' do
+          put :update, :id => @op.id, :original_picture => @attr
+          response.should render_template("edit")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      sign_in @user
+    end
+    context '事前チェックしておく' do
+      before do
+        OriginalPicture.stub(:edit).with(any_args()).and_return @op
+        OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+      end
+      it '原画モデルに編集取得を問い合わせている' do
+        OriginalPicture.should_receive(:edit).exactly(1)
+        delete :destroy, :id => @op.id
+      end
+      it 'モデルに削除を依頼する' do
+        OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
+        delete :destroy, :id => @op.id
+      end
+      it '@original_pictureにアレを取得している' do
+        delete :destroy, :id => @op.id
+        assigns(:original_picture).id.should eq(@op.id)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @op.id
+          response.status.should eq 302
+        end
+        it '原画の一覧ページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.should redirect_to(original_pictures_path)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード302 Foundを返す' do
+        delete :destroy, :id => @op.id
+        response.status.should eq 302
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context '削除に失敗したとき' do
+      before do
+        OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @op.id
+          response.status.should eq 302
+        end
+        it 'その原画の詳細ページへ遷移する' do
+          delete :destroy, :id => @op.id
+          response.should redirect_to(original_picture_path(@op))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          delete :destroy, :id => @op.id, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+end
+
 end