OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05client
[pettanr/pettanr.git] / spec / controllers / resource_pictures_controller_spec.rb
index d998878..0115ac8 100644 (file)
@@ -5,6 +5,7 @@ require 'spec_helper'
 describe ResourcePicturesController do
   before do
     @admin = FactoryGirl.create :admin
+    @demand_user = FactoryGirl.create :demand_user
     @sp = FactoryGirl.create :system_picture
     @lg = FactoryGirl.create :license_group
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@@ -94,7 +95,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
@@ -119,6 +120,35 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
+    context 'ユーザ権限はないが借手権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @demand_user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
   end
   
   describe '単体表示に於いて' do
@@ -126,7 +156,9 @@ if MagicNumber['run_mode'] == 1
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       sign_in @user
-      ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
     end
     context 'つつがなく終わるとき' do
       it '素材モデルに単体取得を問い合わせている' do
@@ -226,7 +258,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
@@ -251,6 +283,35 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @rp.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザ権限はないが借手権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @demand_user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @rp.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @rp.id
+        response.should be_success 
+      end
+    end
 =begin
     context '対象素材がないとき' do
       before do
@@ -323,7 +384,9 @@ if MagicNumber['run_mode'] == 1
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       sign_in @user
-      ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
     end
     context 'つつがなく終わるとき' do
       it '素材モデルに単体取得を問い合わせている' do
@@ -366,7 +429,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
@@ -391,6 +454,35 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :credit, :id => @rp.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザ権限はないが借手権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @demand_user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :credit, :id => @rp.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :credit, :id => @rp.id
+        response.should be_success 
+      end
+    end
 =begin
     context '対象素材がないとき' do
       before do
@@ -533,7 +625,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
@@ -561,9 +653,41 @@ 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
+          get :new, @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new, @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザ権限はないが借手権限があるとき' do
       before do
-        Author.any_instance.stub(:artist?).and_return(false)
+        sign_out @user
+        sign_in @demand_user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new, @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new, @attr
+          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
@@ -593,6 +717,9 @@ if MagicNumber['run_mode'] == 1
       before do
         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => 0}, 
           :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
+        OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+        OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
+        OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
       end
       context 'html形式' do
         it '例外404 not_foundを返す' do
@@ -786,7 +913,7 @@ if MagicNumber['run_mode'] == 1
         }.should_not change(ResourcePicture, :count)
       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
@@ -814,9 +941,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
+          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
+        sign_out @user
+        sign_in @demand_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
+    end
+    context 'ユーザが絵師でないとき' do
+      before do
+        @artist.destroy
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
@@ -829,10 +988,8 @@ if MagicNumber['run_mode'] == 1
         end
       end
       context 'json形式' do
-        before do
-          @attr.merge!({:format => :json})
-        end
         it '例外403 forbiddenを返す' do
+          @attr.merge!({:format => :json})
           lambda{
             post :create, @attr
           }.should raise_error(ActiveRecord::Forbidden)
@@ -924,15 +1081,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 => @rp.id
-        response.status.should eq 302
-      end
       context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @rp.id
+          response.status.should eq 302
+        end
         it 'サインインページへ遷移する' do
           delete :destroy, :id => @rp.id
           response.body.should redirect_to '/users/sign_in'
@@ -945,6 +1102,60 @@ 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 => @rp.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @rp.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザ権限はないが借手権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @demand_user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @rp.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @rp.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 => @rp.id
+          response.status.should eq 302
+        end
+        it '絵師登録ページへ遷移する' do
+          delete :destroy, :id => @rp.id
+          response.should redirect_to new_artist_path
+        end
+      end
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          lambda{
+            delete :destroy, :id => @rp.id, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
+        end
+      end
+    end
     context '削除に失敗したとき' do
       before do
         ResourcePicture.any_instance.stub(:unpublish).and_return(false)
@@ -1002,7 +1213,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
@@ -1034,8 +1245,10 @@ else
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       sign_in @user
-      ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
-      ResourcePicture.stub(:show).with(@rp.id.to_s, nil).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
     end
     context 'つつがなく終わるとき' do
       context 'html形式' do
@@ -1059,7 +1272,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
@@ -1110,8 +1323,10 @@ else
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       sign_in @user
-      ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
-      ResourcePicture.stub(:show).with(@rp.id.to_s, nil).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp)
+      ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp)
     end
     context 'つつがなく終わるとき' do
       context 'html形式' do
@@ -1135,7 +1350,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
@@ -1209,7 +1424,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
@@ -1289,6 +1504,21 @@ else
         end
       end
     end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, @newattr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, @newattr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
   end
   
   describe '削除に於いて' do
@@ -1322,7 +1552,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