OSDN Git Service

t#30137:fix authenticate
[pettanr/pettanr.git] / spec / models / picture_spec.rb
index 8684f43..d9aaf9d 100644 (file)
@@ -250,28 +250,36 @@ describe Picture do
     before do
       @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
     end
-    context 'パラメータが作家のとき' do
-      it '自作の実素材ならyes' do
-        @p.own?(@author).should == true
-      end
-      it '他人のならno' do
-        @p.own?(@other_author).should == false
+    context '事前チェックする' do
+      it '自身にロールリストからの絵師取得を依頼している' do
+        Picture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)
+        r = @p.own?([@artist])
       end
     end
-    context 'パラメータが絵師のとき' do
-      it '自作の実素材ならyes' do
-        @p.own?(@artist).should == true
+    context 'ロール内絵師が取得できるとき' do
+      before do
       end
-      it '他人のならno' do
-        @p.own?(@other_artist).should == false
+      it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do
+        Picture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)
+        r = @p.own?([@artist])
+        r.should be_true
+      end
+      it 'ロール内絵師のidが自身の絵師idと一致しないならno' do
+        Picture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)
+        @p.own?(@other_artist).should be_false
       end
     end
-    context 'それ以外のとき' do
-      it 'no' do
-        @p.own?(nil).should == false
+    context 'ロール内絵師が取得できないとき' do
+      before do
+        Picture.stub(:get_artist_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @p.own?([@artist])
+        r.should be_false
       end
     end
   end
+  
   describe '閲覧許可に於いて' do
     before do
       @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id