OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / pictures_controller_spec.rb
index c3ddfe1..b7cd668 100644 (file)
@@ -5,6 +5,7 @@ require 'spec_helper'
 describe PicturesController 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
@@ -19,7 +20,9 @@ if MagicNumber['run_mode'] == 1
     before do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       sign_in @user
-      Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
     end
     context 'つつがなく終わるとき as json' do
       it 'ステータスコード200 OKを返す' do
@@ -89,7 +92,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,6 +117,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 => @p.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 => @p.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @p.id
+        response.should be_success 
+      end
+    end
 =begin
     context '対象素材がないとき' do
       before do
@@ -161,7 +193,9 @@ if MagicNumber['run_mode'] == 1
     before do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       sign_in @user
-      Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
     end
     context 'つつがなく終わるとき' do
       it 'ステータスコード200 OKを返す' do
@@ -195,7 +229,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
@@ -220,6 +254,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 => @p.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 => @p.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :credit, :id => @p.id
+        response.should be_success 
+      end
+    end
 =begin
     context '対象素材がないとき' do
       before do
@@ -292,7 +355,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
@@ -317,6 +380,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 :search, :md5 => 'a'*32
+        response.should be_success 
+      end
+    end
+    context 'ユーザ権限はないが借手権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @demand_user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :search, :md5 => 'a'*32
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :search, :md5 => 'a'*32
+        response.should be_success 
+      end
+    end
   end
   
 else
@@ -324,8 +416,10 @@ else
     before do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       sign_in @user
-      Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
-      Picture.stub(:show).with(@p.id.to_s, nil).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
     end
     context 'つつがなく終わるとき as json' do
       it 'ステータスコード200 OKを返す' do
@@ -345,7 +439,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
@@ -372,8 +466,10 @@ else
     before do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
       sign_in @user
-      Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
-      Picture.stub(:show).with(@p.id.to_s, nil).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+      Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
     end
     context 'つつがなく終わるとき' do
       it 'ステータスコード200 OKを返す' do
@@ -393,7 +489,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
@@ -444,7 +540,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