OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05client
[pettanr/pettanr.git] / spec / controllers / original_pictures_controller_spec.rb
index 32ae9d7..fd6c341 100644 (file)
@@ -89,7 +89,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 +114,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
@@ -239,7 +255,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
@@ -264,26 +280,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 '例外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
@@ -378,7 +391,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
@@ -403,26 +416,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 '例外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
@@ -471,7 +481,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
@@ -496,34 +506,40 @@ 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 '例外403 forbiddenを返す' do
           lambda{
-          get :new, :format => :json
+            get :new, :format => :json
           }.should raise_error(ActiveRecord::Forbidden)
         end
       end
@@ -603,7 +619,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
@@ -631,9 +647,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
@@ -650,6 +682,7 @@ if MagicNumber['run_mode'] == 1
           @attr.merge!({:format => :json})
         end
         it '例外403 forbiddenを返す' do
+          @attr.merge!({:format => :json})
           lambda{
             post :create, @attr
           }.should raise_error(ActiveRecord::Forbidden)
@@ -756,7 +789,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
@@ -781,9 +814,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
@@ -795,14 +844,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
@@ -868,7 +914,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
@@ -893,9 +939,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
@@ -1017,15 +1079,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'
@@ -1038,6 +1100,44 @@ if MagicNumber['run_mode'] == 1
         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)
@@ -1090,7 +1190,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
@@ -1141,7 +1241,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
@@ -1195,7 +1295,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
@@ -1254,7 +1354,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
@@ -1316,7 +1416,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
@@ -1370,7 +1470,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
@@ -1431,7 +1531,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
@@ -1456,28 +1556,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)
@@ -1554,7 +1632,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