OSDN Git Service

t#31281:add comic.description
[pettanr/pettanr.git] / spec / models / resource_picture_spec.rb
index fc0a3bf..4988095 100644 (file)
@@ -211,6 +211,50 @@ describe ResourcePicture do
     end\r
   end\r
   \r
+  describe '文字コード検証に於いて' do\r
+    before do\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
+    \r
+    context 'artist_nameを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.artist_name = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+    context 'classnameを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.classname = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+    context 'creditを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.credit = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+    context 'settingsを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.settings = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+  end\r
+  \r
   describe 'デフォルト値補充に於いて' do\r
     it 'defined' do\r
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
@@ -242,8 +286,33 @@ describe ResourcePicture do
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end\r
-    it '素材を更新することはないので、Falseを返す' do\r
-      @rp.own?(@author).should == false\r
+    context '事前チェックする' do\r
+      it '自身にロールリストからの絵師取得を依頼している' do\r
+        ResourcePicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)\r
+        r = @rp.own?([@author])\r
+      end\r
+    end\r
+    context 'ロール内絵師が取得できるとき' do\r
+      before do\r
+      end\r
+      it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)\r
+        r = @rp.own?([@author])\r
+        r.should be_true\r
+      end\r
+      it 'ロール内絵師のidが自身の絵師idと一致しないならno' do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)\r
+        @rp.own?(@other_artist).should be_false\r
+      end\r
+    end\r
+    context 'ロール内絵師が取得できないとき' do\r
+      before do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.own?([@author])\r
+        r.should be_false\r
+      end\r
     end\r
   end\r
   \r
@@ -252,38 +321,46 @@ describe ResourcePicture do
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end\r
-    context '検査対象がnil(ゲスト)のとき' do\r
-      context 'クローズドモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 1\r
-        end\r
-        it '不許可を返す。' do\r
-          r = @rp.visible?(nil)\r
-          r.should be_false\r
-        end\r
-      end\r
-      context 'オープンモードのとき' do\r
-        before do\r
-          MagicNumber['run_mode'] = 0\r
-        end\r
-        it '許可する' do\r
-          r = @rp.visible?(nil)\r
-          r.should be_true\r
-        end\r
-      end\r
-    end\r
-    context '検査対象が作家のとき' do\r
-      it '許可する' do\r
-        r = @rp.visible?(@author)\r
-        r.should == true\r
+    context 'オープンモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 0\r
+      end\r
+      it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+        ResourcePicture.any_instance.stub(:guest_role_check).and_return(true)\r
+        ResourcePicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+        r = @rp.visible?([@author])\r
+      end\r
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+        ResourcePicture.any_instance.stub(:guest_role_check).and_return(false)\r
+        r = @rp.visible?([@author])\r
+        r.should be_false\r
       end\r
     end\r
-    context '検査対象がそれ以外のとき' do\r
-      it '不許可を返す。' do\r
-        r = @rp.visible?(@admin)\r
+    context 'クローズドモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+      end\r
+      it '自身に素材読者用ロールチェックを問い合わせしている' do\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+        ResourcePicture.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)\r
+        r = @rp.visible?([@author])\r
+      end\r
+      it '素材読者用ロールチェックが失敗したとき、falseを返す' do\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(false)\r
+        r = @rp.visible?([@author])\r
         r.should be_false\r
       end\r
     end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+      end\r
+      it '許可する' do\r
+        r = @rp.visible?([@author])\r
+        r.should be_true\r
+      end\r
+    end\r
   end\r
   \r
   describe 'ファイル名に於いて' do\r