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 b28ba4d..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,7 +118,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -130,9 +134,9 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -145,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
@@ -254,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
@@ -279,7 +284,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -289,25 +294,13 @@ if MagicNumber['run_mode'] == 1
         response.should be_success 
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       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
-      end
-      context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          get :show, :id => @pic.id, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @pic.id
+        response.should be_success 
       end
     end
 =begin
@@ -402,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
@@ -427,7 +420,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -437,25 +430,13 @@ if MagicNumber['run_mode'] == 1
         response.should be_success 
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
-      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
+        @artist.destroy
       end
-      context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          get :history, :id => @op.id, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
+      it 'ステータスコード200 OKを返す' do
+        get :history, :id => @op.id
+        response.should be_success 
       end
     end
   end
@@ -504,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
@@ -529,7 +510,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -545,9 +526,9 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -559,20 +540,11 @@ if MagicNumber['run_mode'] == 1
           response.should redirect_to new_artist_path
         end
       end
-      context 'js形式' do
-        it 'ステータスコード200 Okを返す' do
-          get :new, :format => :js
-          response.status.should eq 200
-        end
-        it '絵師登録部分テンプレートartists/new.jsを描画する' do
-          get :new, :format => :js
-          response.should render_template("artists/new")
-        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
@@ -651,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
@@ -679,7 +651,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -695,9 +667,9 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -713,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
@@ -819,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
@@ -844,7 +818,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -860,9 +834,9 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -874,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
@@ -947,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
@@ -972,7 +943,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -988,9 +959,9 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -1003,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
@@ -1111,7 +1083,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
@@ -1132,7 +1104,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
       before do
         sign_out @user
         sign_in @admin
@@ -1148,9 +1120,9 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'ä½\9c家ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶ã\81\8c絵師ã\81§ã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -1163,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
@@ -1221,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
@@ -1272,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
@@ -1326,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
@@ -1385,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
@@ -1447,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
@@ -1501,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
@@ -1562,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
@@ -1587,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)
@@ -1685,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