OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / spec / controllers / original_pictures_controller_spec.rb
index 3bcfe70..8a06063 100644 (file)
@@ -60,6 +60,10 @@ if MagicNumber['run_mode'] == 1
         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")
@@ -89,7 +93,7 @@ if MagicNumber['run_mode'] == 1
         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
@@ -114,9 +118,25 @@ if MagicNumber['run_mode'] == 1
         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 :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
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -129,9 +149,10 @@ if MagicNumber['run_mode'] == 1
         end
       end
       context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          get :index, :format => :json
-          response.message.should match(/Unauthorized/)
+        it '例外403 forbiddenを返す' do
+          lambda{
+            get :index, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
@@ -238,7 +259,7 @@ if MagicNumber['run_mode'] == 1
         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,25 +284,23 @@ if MagicNumber['run_mode'] == 1
         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 '応答メッセージにUnauthorizedを返す' do
-          get :show, :id => @pic.id, :format => :json
-          response.message.should match(/Unauthorized/)
-        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
@@ -376,7 +395,7 @@ if MagicNumber['run_mode'] == 1
         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
@@ -401,25 +420,23 @@ if MagicNumber['run_mode'] == 1
         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 '応答メッセージにUnauthorizedを返す' do
-          get :history, :id => @op.id, :format => :json
-          response.message.should match(/Unauthorized/)
-        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
@@ -468,7 +485,7 @@ if MagicNumber['run_mode'] == 1
         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
@@ -493,34 +510,41 @@ if MagicNumber['run_mode'] == 1
         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 '応答メッセージにUnauthorizedを返す' do
-          get :new, :format => :json
-          response.message.should match(/Unauthorized/)
+        it '例外403 forbiddenを返す' do
+          lambda{
+            get :new, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
@@ -599,7 +623,7 @@ if MagicNumber['run_mode'] == 1
         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
@@ -627,9 +651,25 @@ if MagicNumber['run_mode'] == 1
         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
@@ -645,9 +685,11 @@ if MagicNumber['run_mode'] == 1
         before do
           @attr.merge!({:format => :json})
         end
-        it '応答メッセージにUnauthorizedを返す' do
-          post :create, @attr
-          response.message.should match(/Unauthorized/)
+        it '例外403 forbiddenを返す' do
+          @attr.merge!({:format => :json})
+          lambda{
+            post :create, @attr
+          }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
@@ -751,7 +793,7 @@ if MagicNumber['run_mode'] == 1
         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
@@ -776,9 +818,25 @@ if MagicNumber['run_mode'] == 1
         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 :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
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -790,14 +848,11 @@ if MagicNumber['run_mode'] == 1
           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
@@ -863,7 +918,7 @@ if MagicNumber['run_mode'] == 1
         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
@@ -888,9 +943,25 @@ if MagicNumber['run_mode'] == 1
         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
@@ -903,9 +974,10 @@ if MagicNumber['run_mode'] == 1
         end
       end
       context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          put :update, :id => @op.id, :original_picture => @attr, :format => :json
-          response.message.should match(/Unauthorized/)
+        it '例外403 forbiddenを返す' do
+          lambda{
+            put :update, :id => @op.id, :original_picture => @attr, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
@@ -1011,15 +1083,15 @@ if MagicNumber['run_mode'] == 1
         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
-      it 'ステータスコード302 Foundを返す' do
-        delete :destroy, :id => @op.id
-        response.status.should eq 302
-      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'
@@ -1032,9 +1104,25 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context '作家が絵師でないとき' do
+    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
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -1047,9 +1135,10 @@ if MagicNumber['run_mode'] == 1
         end
       end
       context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          delete :destroy, :id => @op.id, :format => :json
-          response.message.should match(/Unauthorized/)
+        it '例外403 forbiddenを返す' do
+          lambda{
+            delete :destroy, :id => @op.id, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
@@ -1105,7 +1194,7 @@ else
         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
@@ -1156,7 +1245,7 @@ else
         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
@@ -1210,7 +1299,7 @@ else
         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
@@ -1269,7 +1358,7 @@ else
         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
@@ -1331,7 +1420,7 @@ else
         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
@@ -1385,7 +1474,7 @@ else
         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
@@ -1446,7 +1535,7 @@ else
         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
@@ -1471,28 +1560,6 @@ else
         end
       end
     end
-    context '作家が絵師でないとき' do
-      before do
-        Author.any_instance.stub(:artist?).and_return(false)
-      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 new_artist_path
-        end
-      end
-      context 'json形式' do
-        it '例外403 forbiddenを返す' do
-          lambda{
-            put :update, :id => @op.id, :original_picture => @attr, :format => :json
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
-      end
-    end
     context '検証、保存に失敗した' do
       before do
         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
@@ -1569,7 +1636,7 @@ else
         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