OSDN Git Service

t#30137:fix authenticate
[pettanr/pettanr.git] / spec / models / panel_picture_spec.rb
index 29a214c..5b415ed 100644 (file)
@@ -289,63 +289,86 @@ describe PanelPicture do
       end
     end
   end
+  
   describe '閲覧許可に於いて' do
     before do
       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
         :width => @p.width, :height => @p.height
     end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do
-          r = @pp.visible?(nil)
-          r.should be_false
-        end
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
       end
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '公開されたコマのコマ絵なら許可する' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-          r = @pp.visible?(nil)
-          r.should be_true
-        end
-        it 'れ以外なら不許可を返す' do
-          Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-          r = @pp.visible?(nil)
-          r.should be_false
-        end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        PanelPicture.any_instance.stub(:guest_role_check).and_return(true)
+        PanelPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @pp.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        PanelPicture.any_instance.stub(:guest_role_check).and_return(false)
+        r = @pp.visible?([@author])
+        r.should be_false
       end
     end
-    context '検査対象が作家のとき' do
-      it '公開されたコマのコマ絵なら許可する' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
-        r = @pp.visible?(@author)
-        r.should be_true
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        PanelPicture.any_instance.stub(:reader_role_check).and_return(true)
+        PanelPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @pp.visible?([@author])
       end
-      it 'れ以外なら不許可を返す' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @pp.visible?(@author)
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        PanelPicture.any_instance.stub(:reader_role_check).and_return(false)
+        r = @pp.visible?([@author])
         r.should be_false
       end
     end
-    context '検査対象が管理者のとき' do
-      it '許可を返す。' do
-        Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
-        r = @pp.visible?(@admin)
-        r.should be_true
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        PanelPicture.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 = @pp.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 = @pp.visible?([@author])
       end
     end
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do
-        r = @pp.visible?(1)
+    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 = @pp.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 = @pp.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 = @pp.visible?([@author])
+        r.should be_true
+      end
     end
   end
+  
+  
   describe '一覧取得に於いて' do
     before do
       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,