OSDN Git Service

t#30137:fix authenticate
[pettanr/pettanr.git] / spec / models / ground_picture_spec.rb
index ab72eb2..02e6054 100644 (file)
@@ -150,58 +150,79 @@ describe GroundPicture do
     before do
       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @gp.visible?(nil)
-          r.should be_false
-        end
-      end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開されたコマの絵地なら許可する' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-          r = @gp.visible?(nil)
-          r.should be_true
-        end
-        it 'れ以外なら不許可を返す' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-          r = @gp.visible?(nil)
-          r.should be_false
-        end
-      end
-    end
-    context '検査対象が作家のとき' do
-      it '公開されたコマの絵地なら許可する' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-        r = @gp.visible?(@author)
-        r.should be_true
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        GroundPicture.any_instance.stub(:guest_role_check).and_return(true)
+        GroundPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
       end
-      it 'ã\82\8c以å¤\96ã\81ªã\82\89ä¸\8d許å\8f¯を返す' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @gp.visible?(@author)
+      it 'ã\82²ã\82¹ã\83\88ç\94¨ã\83­ã\83¼ã\83«ã\83\81ã\82§ã\83\83ã\82¯ã\81\8c失æ\95\97ã\81\97ã\81\9fã\81¨ã\81\8dã\80\81falseを返す' do
+        GroundPicture.any_instance.stub(:guest_role_check).and_return(false)
+        r = @gp.visible?([@author])
         r.should be_false
       end
     end
-    context '検査対象が管理者のとき' do
-      it '許可を返す。' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @gp.visible?(@admin)
-        r.should be_true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
+        GroundPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        GroundPicture.any_instance.stub(:reader_role_check).and_return(false)
+        r = @gp.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @gp.visible?(1)
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコマに所持判定を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
+      end
+      it '自身のコマに閲覧許可を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @gp.visible?([@author])
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Panel.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコマの絵地なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @gp.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コマの絵地なら許可しない' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @gp.visible?([@author])
         r.should be_false
       end
+      it '他人のコマの絵地でも公開なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        r = @gp.visible?([@author])
+        r.should be_true
+      end
     end
   end
+  
   describe '一覧取得に於いて' do
     before do
       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id